INNER CODE UNIT · TypeScript
HTML_TAG_PATTERN
vinta/pangu.js · src/shared/index.ts:324
const HTML_TAG_PATTERN = /<\/?[a-zA-Z][a-zA-Z0-9]*(?:\s+[^>]*)?>/g;
// Tag names whose closing tag appears anywhere in the text: their opening tags are paired markup
const closedTagNames = new Set<string>();
for (const closingTag of newText.matchAll(CLOSING_HTML_TAG)) {
closedTagNames.add(closingTag[1]!.toLowerCase());
}
// Hide every real tag behind a placeholder; attribute values get spacing first
newText = newText.replace(HTML_TAG_PATTERN, (match) => {
const bareTag = match.match(BARE_HTML_TAG);
if (bareTag) {
const tagName = bareTag[1]!.toLowerCase();
if (!VOID_HTML_TAGS.has(tagName) && !closedTagNames.has(tagName)) {
return mentionedTagManager.store(match);
}
}
const processedTag = match.replace(/(\w+)="([^"]*)"/g, (_attrMatch, attrName: string, attrValue: string) => {