Skip to content

Commit

Permalink
New option 'linking.headingDepths' (not yet effective)
Browse files Browse the repository at this point in the history
  • Loading branch information
about-code committed Dec 21, 2020
1 parent 949c815 commit 95708c7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
12 changes: 11 additions & 1 deletion conf/v5/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@
"default": {
"baseUrl": "",
"paths": "relative",
"mentions": "all"
"mentions": "all",
"headingDepths": [2,3,4,5,6]
}
},
"outDir": {
Expand Down Expand Up @@ -231,6 +232,15 @@
"description": "Control the link density and whether every occurrence of a term in your documents should be linked with its glossary definition or only the first occurrence within a particular range.",
"type": "string",
"enum": ["all", "first-in-paragraph"]
},
"headingDepths": {
"description": "An array of numerical values each in a range of 1-6 denoting the depths of headings that should be nor not be linked.",
"type": "array",
"items": {
"type": "integer",
"minimum": 1,
"maximum": 6
}
}
}
},
Expand Down
1 change: 1 addition & 0 deletions lib/model/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Context {
conf.baseDir = toForwardSlash(conf.baseDir || "");
conf.outDir = toForwardSlash(conf.outDir || "");
conf.glossaries = conf.glossaries.map(conf => new Glossary(conf));
conf.linking.headingDepths = [...conf.linking.headingDepths];
if (conf.generateFiles.listOfFigures) {
conf.generateFiles.listOfFigures = Object.assign({ class: "figure", title: "Figures"}, conf.generateFiles.listOfFigures);
conf.generateFiles.listOf.push(conf.generateFiles.listOfFigures);
Expand Down
10 changes: 5 additions & 5 deletions lib/terminator.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,26 @@ api.terminator = function(args) {
function getNodeVisitor(context, glossary) {

const State = {};
State.NEW_GLOSSARY = 1;
State.AWAIT_HEADING = 2;
State.AWAIT_LINK = 4;
State.AWAIT_ALIAS = 8;
State.AWAIT_PARAGRAPH = 16;
State.active = State.NEW_GLOSSARY;
State.active = State.AWAIT_HEADING;
State.is = (state) => State.active & state;
State.next = (nextState) => State.active = nextState;

const {conf} = context;
const {headingDepths} = conf.linking;
let termNode = null;
return function visitor(node, idx, parent) {
if (node.type === "heading") {
if (node.depth === 1) {
glossary.title = getNodeText(node);
State.next(State.NEW_GLOSSARY);
} else if (node.depth > 1) {
}
if (node.depth > 1) {// || headingDepths.has(node.depth)) {
State.next(State.AWAIT_LINK);
} else {
State.next(State.NEW_GLOSSARY);
State.next(State.AWAIT_HEADING);
}
} else if (
State.is(State.AWAIT_LINK)
Expand Down
2 changes: 1 addition & 1 deletion test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"test_21": "npx . --config ./input/config-linking/mentions-first-in-paragraph/glossarify-md.conf.json",
"test_22": "npx . --init > ./input/config-cli/arg-init/conf.gitignore.json && npx . --config ./input/config-cli/arg-init/conf.gitignore.json --shallow \"{ 'outDir': '../../../../output-actual/config-cli/arg-init/' }\"",
"test_23": "npx . --shallow \"{'baseDir':'./input/config-cli/arg-config-skip', 'outDir':'../../../output-actual/config-cli/arg-config-skip', 'includeFiles':['.'], 'glossaries':[{'file':'./glossary.md'}] }\"",
"test_24": "npx . --config ./input/config-cli/arg-shallow/glossarify-md.conf.json --shallow \"{'baseUrl': 'cli://localhost', 'linking': 'absolute', 'glossaries':[{'file':'./glossary2.md'}] }\"",
"test_24": "npx . --config ./input/config-cli/arg-shallow/glossarify-md.conf.json --shallow \"{'linking': {'baseUrl': 'cli://localhost', 'paths': 'absolute'}, 'glossaries':[{'file':'./glossary2.md'}] }\"",
"test_25": "npx . --config ./input/config-cli/arg-deep/glossarify-md.conf.json --deep \"{'glossaries':[{'file':'./glossary2.md'}]}\"",
"test_26": "npx . --config ./input/config-cli/deep-defaults/glossarify-md.conf.json",
"test_27": "npx . --config ./input/config-indexFile/glossary-in-subdir/glossarify-md.conf.json",
Expand Down

0 comments on commit 95708c7

Please sign in to comment.