Skip to content

Commit

Permalink
Merge pull request #769 from SSWConsulting/phone-string-location
Browse files Browse the repository at this point in the history
Improve phone highlighting for phone number rule
  • Loading branch information
tombui99 authored Nov 15, 2023
2 parents 24217cf + 4b080b8 commit 42121e1
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions docker/customHtmlRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,25 +525,29 @@ exports.addCustomHtmlRule = async (apiToken, url) => {
parser.addListener("text", (event) => {
// Replace "." and "/" characters to avoid false positives when parsing phone numbers
const text = event.raw?.replace(/\.|\//g, "_");
if (text && event.lastEvent && findPhoneNumbersInText(text, optionValue.length > 0 ? optionValue : 'AU').length) {
const pageContent = event.lastEvent.raw;
if (pageContent && event.lastEvent.tagName) {
const tagName = event.lastEvent.tagName.toLowerCase();
const mapAttrs = parser.getMapAttrs(event.lastEvent.attrs);
const href = mapAttrs["href"];
const isLink = tagName === "a";
const isTelLink = isLink && href && href.startsWith("tel:");

if (!(isTelLink || isInCodeBlock)) {
reporter.warn(
"Phone number must be in a hyperlink.",
event.line,
event.col,
self,
event.raw
);
if (text && event.lastEvent) {
const foundPhoneNumbers = findPhoneNumbersInText(text, optionValue.length > 0 ? optionValue : 'AU');

foundPhoneNumbers.forEach((phone) => {
const pageContent = event.lastEvent.raw;
if (pageContent && event.lastEvent.tagName) {
const tagName = event.lastEvent.tagName.toLowerCase();
const mapAttrs = parser.getMapAttrs(event.lastEvent.attrs);
const href = mapAttrs["href"];
const isLink = tagName === "a";
const isTelLink = isLink && href && href.startsWith("tel:");

if (!(isTelLink || isInCodeBlock)) {
reporter.warn(
"Phone number must be in a hyperlink.",
event.line,
event.col + phone.startsAt - 1,
self,
event.raw
);
}
}
}
});
}
});
},
Expand Down

0 comments on commit 42121e1

Please sign in to comment.