Hoist regex to module scope

This commit is contained in:
Jared Miller 2025-12-25 10:28:12 -05:00
parent bf3d6dcc0d
commit e3b8f7188f
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C

View file

@ -187,6 +187,8 @@ const resolveTerm = (term) => {
return candidates.find((candidate) => entryMap.has(candidate)) || null;
};
const CAPS_TERM_REGEX = /\b[A-Z][A-Z0-9''\-]*(?:\s+[A-Z][A-Z0-9''\-]*)*\b/g;
const linkifyTextNode = (node) => {
const text = node.nodeValue;
if (!text || !/[A-Z]{2}/.test(text)) {
@ -194,9 +196,9 @@ const linkifyTextNode = (node) => {
}
const matches = [];
const regex = /\b[A-Z][A-Z0-9'\-]*(?:\s+[A-Z][A-Z0-9'\-]*)*\b/g;
CAPS_TERM_REGEX.lastIndex = 0;
let match;
while ((match = regex.exec(text)) !== null) {
while ((match = CAPS_TERM_REGEX.exec(text)) !== null) {
const raw = match[0];
const cleaned = cleanTerm(raw);
const resolved = resolveTerm(cleaned);