Skip to content

Commit 7ec8d39

Browse files
committed
Last optimization
1 parent 0df0fc1 commit 7ec8d39

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/plugins/definition-wrapper.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,17 @@ module.exports = function remarkWordWrapper(stuff) {
1515
parent?.tagName === "a" ||
1616
parent?.tagName === "Link"
1717
) {
18-
// Don't wrap terms in headings or links
18+
// Skip terms in headings or links
1919
return;
2020
}
2121
let matchingTitle = "";
2222
const matchingTerm = terms.find((term) => {
23+
/**
24+
* Find the first term that matches the node value
25+
* and is not already found in the foundTerms array.
26+
* We use indexOf so we can pull the exact term out
27+
* of the node value.
28+
*/
2329
let termIndex;
2430
const nodeValue = term.caseSensitive
2531
? node.value
@@ -49,6 +55,10 @@ module.exports = function remarkWordWrapper(stuff) {
4955
}
5056

5157
const parts = node.value.split(matchingTitle);
58+
if (parts.length < 2) {
59+
// If the term is not found in the text, return
60+
return;
61+
}
5262
foundTerms.push(matchingTerm);
5363

5464
return parent.children.splice(

0 commit comments

Comments
 (0)