-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: escape terms containing characters with special meaning in regExp
chore(): Count term occurrences based on AST nodes. Don't count occurrences in term's own definition. This change is necessary because with introducing linkification of term occurrences in glossaries, too, we also counted occurrences in the term's own definition. This way we were no longer able to detect orphan terms and term definitions used no longer anywhere else.
- Loading branch information
1 parent
cc199a3
commit 1815304
Showing
29 changed files
with
714 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const uVisit = require('unist-util-visit'); | ||
const {getLinkUrl} = require('./ast-tools'); | ||
/** | ||
* Unified plug-in to count occurrences and mentions of a term. | ||
* Won't count occurrences in the terms own definition. | ||
*/ | ||
function counter(context) { | ||
return () => (tree, vFile) => { | ||
uVisit(tree, 'term-occurrence', (node, idx, parent) => { | ||
node.termDefs.forEach(term => { | ||
if (vFile.path === term.glossary.vFile.path) { | ||
// current file is the glossary in which the term has been | ||
// defined... | ||
if (getLinkUrl(node.headingNode) !== term.anchor) { | ||
// ...count term occurence only, if it is not in the | ||
// terms own definition. | ||
term.countOccurrence(); | ||
} | ||
} else { | ||
term.countOccurrence(); | ||
} | ||
}); | ||
}); | ||
return tree; | ||
}; | ||
} | ||
|
||
module.exports = { counter }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
test/input/config-tailored/count-term-occurrences/document.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Count Term Occurrences | ||
|
||
## Once | ||
|
||
GIVEN a document | ||
AND it mentions the term "Mentioned-in-document-once" once | ||
AND noohere else | ||
THEN the term's term occurrence count MUST be 1. | ||
|
||
## Twice | ||
|
||
GIVEN a document | ||
AND it mentions the term "Mentioned-in-document-twice" once | ||
AND it mentions the term "Mentioned-in-document-twice" twice | ||
THEN the term's term occurrence count MUST be 2. |
19 changes: 19 additions & 0 deletions
19
test/input/config-tailored/count-term-occurrences/glossarify-md.conf.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"$schema": "../../../../conf.schema.json", | ||
"baseDir": ".", | ||
"outDir": "../../../output-actual/config-tailored/count-term-occurrences", | ||
"includeFiles": ["."], | ||
"excludeFiles": [], | ||
"keepRawFiles": [], | ||
"glossaries": [ | ||
{ "file": "./glossary.md", "termHint": "" } | ||
], | ||
"linking": "relative", | ||
"ignoreCase": false, | ||
"dev": { | ||
"termsFile": "../../../output-actual/config-tailored/count-term-occurrences/terms.json", | ||
"printInputAst": false, | ||
"reproducablePaths": true, | ||
"printOutputAst": false | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
test/input/config-tailored/count-term-occurrences/glossary.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Glossary | ||
|
||
## Zero | ||
|
||
GIVEN a term "Zero" | ||
AND the term "Zero" is mentioned twice in its own definition | ||
AND nowhere else | ||
THEN this term's occurrence count MUST be 0. | ||
|
||
## One | ||
|
||
GIVEN a term "One" | ||
AND the term is mentioned only once in a subsequent term definition | ||
AND nowhere else | ||
THEN this term's occurrence count MUST be 1. | ||
|
||
#### mention-one-once | ||
|
||
GIVEN this definition | ||
AND it mentions another term "One" once | ||
AND itself is being mentioned nowhere else | ||
THEN the other term's occurrence count MUST be 1 | ||
AND this term's occurrence count MUST be 0. | ||
|
||
## Two | ||
|
||
GIVEN a term "Two" | ||
AND the term is mentioned term two times in a subsequent term definition | ||
AND nowhere else | ||
THEN this term's occurrence count MUST be 2. | ||
|
||
#### mention-two-twice | ||
|
||
GIVEN this definition | ||
AND it mentions another term "Two" Two times | ||
AND itself is being mentioned nowhere else | ||
THEN the other term's occurrence count MUST be 2 | ||
AND this term's occurrence count MUST be 0. | ||
|
||
## Mentioned-in-document-once | ||
|
||
GIVEN a term | ||
AND it is mentioned once in a document | ||
AND not in the glossary | ||
THEN this term's occurrence count MUST be 1. | ||
|
||
## Mentioned-in-document-twice | ||
|
||
GIVEN a term | ||
AND it is mentioned twice in a document | ||
AND not in the glossary | ||
THEN this term's occurrence count MUST be 2. |
21 changes: 21 additions & 0 deletions
21
test/input/config-tailored/glossary-crosslinks/glossarify-md.conf.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"$schema": "../../../../conf.schema.json", | ||
"baseDir": ".", | ||
"outDir": "../../../output-actual/config-tailored/glossary-crosslinks", | ||
"includeFiles": ["."], | ||
"excludeFiles": [], | ||
"experimentalFootnotes": true, | ||
"keepRawFiles": [], | ||
"glossaries": [ | ||
{ "file": "./glossary-g1.md", "termHint": "" } | ||
,{ "file": "./glossary-g2.md", "termHint": "" } | ||
], | ||
"linking": "relative", | ||
"ignoreCase": false, | ||
"dev": { | ||
"termsFile": "../../../output-actual/config-tailored/glossary-crosslinks/terms.json", | ||
"printInputAst": false, | ||
"reproducablePaths": true, | ||
"printOutputAst": false | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
test/input/config-tailored/glossary-crosslinks/glossary-g1.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Glossary G1 | ||
|
||
## Term A | ||
|
||
"Term A" only exists for the sake of being linked to from within this glossary. | ||
|
||
## Term B | ||
|
||
GIVEN a term "Term A" AND a definition of "Term B" in the same glossary G1 | ||
THEN any occurrence of "Term A" in the definition of "Term B" MUST be linked | ||
to the definition of "Term A". | ||
|
||
## Term C | ||
|
||
GIVEN a term "Term C" in glossary G1 AND a term "Term D" in another glossary G2 | ||
THEN any occurrence of "Term D" in glossary G1 MUST be linked to the definition | ||
of "Term D". | ||
|
||
## Term E | ||
|
||
"Term E" only exists for the sake of being linked to from glossary G2. |
12 changes: 12 additions & 0 deletions
12
test/input/config-tailored/glossary-crosslinks/glossary-g2.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Glossary G2 | ||
|
||
## Term D | ||
|
||
"Term D" only exists for the sake of being linked to by the definition of | ||
"Term C" in Glossary G1. | ||
|
||
## Term F | ||
|
||
GIVEN a term "Term F" in glossary G2 AND a term "Term E" in another glossary G1 | ||
THEN any occurrence of "Term E" in glossary G2 MUST be linked to the definition | ||
of "Term E". |
File renamed without changes.
20 changes: 20 additions & 0 deletions
20
test/input/config-tailored/substring_behavior/glossarify-md.conf.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"$schema": "../../../../conf.schema.json", | ||
"baseDir": ".", | ||
"outDir": "../../../output-actual/config-tailored/substring_behavior", | ||
"includeFiles": ["."], | ||
"excludeFiles": [], | ||
"experimentalFootnotes": true, | ||
"keepRawFiles": [], | ||
"glossaries": [ | ||
{ "file": "./glossary.md", "termHint": "" } | ||
], | ||
"linking": "relative", | ||
"ignoreCase": false, | ||
"dev": { | ||
"termsFile": "../../../output-actual/config-tailored/substring_behavior/terms.json", | ||
"printInputAst": false, | ||
"reproducablePaths": true, | ||
"printOutputAst": false | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.