File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -15,11 +15,17 @@ module.exports = function remarkWordWrapper(stuff) {
15
15
parent ?. tagName === "a" ||
16
16
parent ?. tagName === "Link"
17
17
) {
18
- // Don't wrap terms in headings or links
18
+ // Skip terms in headings or links
19
19
return ;
20
20
}
21
21
let matchingTitle = "" ;
22
22
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
+ */
23
29
let termIndex ;
24
30
const nodeValue = term . caseSensitive
25
31
? node . value
@@ -49,6 +55,10 @@ module.exports = function remarkWordWrapper(stuff) {
49
55
}
50
56
51
57
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
+ }
52
62
foundTerms . push ( matchingTerm ) ;
53
63
54
64
return parent . children . splice (
You can’t perform that action at this time.
0 commit comments