Hoist regex to module scope
This commit is contained in:
parent
bf3d6dcc0d
commit
e3b8f7188f
1 changed files with 4 additions and 2 deletions
|
|
@ -187,6 +187,8 @@ const resolveTerm = (term) => {
|
||||||
return candidates.find((candidate) => entryMap.has(candidate)) || null;
|
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 linkifyTextNode = (node) => {
|
||||||
const text = node.nodeValue;
|
const text = node.nodeValue;
|
||||||
if (!text || !/[A-Z]{2}/.test(text)) {
|
if (!text || !/[A-Z]{2}/.test(text)) {
|
||||||
|
|
@ -194,9 +196,9 @@ const linkifyTextNode = (node) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const matches = [];
|
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;
|
let match;
|
||||||
while ((match = regex.exec(text)) !== null) {
|
while ((match = CAPS_TERM_REGEX.exec(text)) !== null) {
|
||||||
const raw = match[0];
|
const raw = match[0];
|
||||||
const cleaned = cleanTerm(raw);
|
const cleaned = cleanTerm(raw);
|
||||||
const resolved = resolveTerm(cleaned);
|
const resolved = resolveTerm(cleaned);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue