diff --git a/lib/cli/upgrade/v4to5.js b/lib/cli/upgrade/v4to5.js
index 24be87e8..92ad3870 100644
--- a/lib/cli/upgrade/v4to5.js
+++ b/lib/cli/upgrade/v4to5.js
@@ -2,7 +2,7 @@ const {liftSchemaVersion} = require("./version");
const api = {};
api.v4To5 = function(confData, confVersion) {
- if (confVersion > 4) {
+ if (confVersion >= 5) {
return;
}
if (typeof confData.linking === "string") {
@@ -16,6 +16,12 @@ api.v4To5 = function(confData, confVersion) {
confData.linking = Object.assign({}, confData.linking, { baseUrl: confData.baseUrl });
delete confData.baseUrl;
}
+ if (confData.generateFiles) {
+ const {indexFile} = confData.generateFiles;
+ if (typeof indexFile === "string") {
+ confData.generateFiles.indexFile = { file: indexFile };
+ }
+ }
if (confData.$schema) {
if (/node_modules/.test(confData.$schema)) {
confData.$schema = "./node_modules/glossarify-md/conf.schema.json";
diff --git a/lib/index/terms.js b/lib/index/terms.js
index b623396f..9c16e8bc 100644
--- a/lib/index/terms.js
+++ b/lib/index/terms.js
@@ -83,6 +83,7 @@ api.getAST = function (context, indexFileConf) {
indexEntries = getIndex(api.IDX_OCCURRENCES_BY_TEXT);
}
+ const indexFile = indexFileConf.file;
let title = "";
if (indexFileConf !== null && typeof indexFileConf === "object") {
title = indexFileConf.title;
@@ -98,7 +99,7 @@ api.getAST = function (context, indexFileConf) {
,...Object
.keys(indexEntries)
.sort((key1, key2) => collator.compare(key1, key2))
- .map((key) => getIndexEntryAst(context, indexEntries[key]))
+ .map((key) => getIndexEntryAst(context, indexEntries[key], indexFile))
];
return root(tree);
};
@@ -110,13 +111,13 @@ api.getAST = function (context, indexFileConf) {
* @param {string} indexFilename
* @returns {Node} mdast tree
*/
-function getIndexEntryAst(context, entriesForKey) {
+function getIndexEntryAst(context, entriesForKey, indexFile) {
const key = getNodeText(entriesForKey[0].node);
return paragraph([
heading(2, text(key))
,brk
,brk
- ,...getEntryLinksAst(context, entriesForKey)
+ ,...getEntryLinksAst(context, entriesForKey, indexFile)
]);
}
@@ -124,14 +125,13 @@ function getIndexEntryAst(context, entriesForKey) {
*
* @param {Context} context
* @param {IndexEntry} indexEntry
- * @param {string} indexFilename
+ * @param {string} indexFile
*/
-function getEntryLinksAst(context, entriesForKey) {
- const indexFilename = getIndexFilename(context);
+function getEntryLinksAst(context, entriesForKey, indexFile) {
const byHeadings = group(entriesForKey, byGroupHeading);
const links = [
- ...getGlossaryLinksAst(context, entriesForKey, indexFilename)
- ,...getDocumentLinksAst(context, byHeadings, indexFilename)
+ ...getGlossaryLinksAst(context, entriesForKey, indexFile)
+ ,...getDocumentLinksAst(context, byHeadings, indexFile)
];
const linksSeparated = [];
for (let i = 0, len = links.length; i < len; i++) {
@@ -230,14 +230,4 @@ function byHeading(indexEntry) {
return `${indexEntry.file}#${pos}:${anchor}`;
}
-/**
- * @param {Context} context
- */
-function getIndexFilename(context) {
- const {indexFile} = context.conf.generateFiles;
- if (indexFile && typeof indexFile === "object") {
- return indexFile.file;
- }
-}
-
module.exports = api;
diff --git a/test/input/config-indexFiles/154-deep-dir/document.md b/test/input/config-indexFiles/154-deep-dir/document.md
index 426177d8..134a82a3 100644
--- a/test/input/config-indexFiles/154-deep-dir/document.md
+++ b/test/input/config-indexFiles/154-deep-dir/document.md
@@ -15,13 +15,21 @@ AND a configuration
{
"generateFiles": {
"indexFiles": [
- { "title": "Index A", "file": "./index-a.md", "glossary": "./glossary-a.md" },
- { "title": "Index B", "file": "./index-b.md", "glossary": "./sub1/glossary-b.md" },
- { "title": "Index C", "file": "./index-c.md", "glossary": "./sub1/sub2/glossary-c.md" }
+ {
+ "title": "Index A", "file": "./index-a.md", "glossary": "./glossary-a.md"
+ },
+ {
+ "title": "Index B", "file": "./sub1-index/index-b.md", "glossary": "./sub1/glossary-b.md"
+ },
+ {
+ "title": "Index C", "file": "./sub1-index/sub2-index/index-c.md", "glossary": "./sub1/sub2/glossary-c.md"
+ }
]
},
"glossaries": [
- { "file": "./**/glossary-*.md" }
+ {
+ "file": "./**/glossary-*.md"
+ }
]
}
~~~
@@ -30,7 +38,11 @@ THEN the system MUST generate three files
- index-a.md
- WITH terms GlossaryA_Term1, GlossaryA_Term2, GlossaryABC_Term3, only
-- index-b.md
+- sub1-index/index-b.md
- WITH terms GlossaryB_Term1, GlossaryB_Term2, GlossaryABC_Term3, only
-- index-c.md
+- sub1-index/sub2-index/index-c.md
- WITH terms GlossaryC_Term1, GlossaryC_Term2, GlossaryABC_Term3, only
+
+AND
+
+- links from within indexes at each depth MUST resolve to the document's section of occurrence.
diff --git a/test/input/config-indexFiles/154-deep-dir/glossarify-md.conf.json b/test/input/config-indexFiles/154-deep-dir/glossarify-md.conf.json
index f7820303..fcbf75b0 100644
--- a/test/input/config-indexFiles/154-deep-dir/glossarify-md.conf.json
+++ b/test/input/config-indexFiles/154-deep-dir/glossarify-md.conf.json
@@ -15,10 +15,10 @@
"title": "Index A", "file": "./index-a.md", "glossary": "./glossary-a.md"
},
{
- "title": "Index B", "file": "./index-b.md", "glossary": "./sub1/glossary-b.md"
+ "title": "Index B", "file": "./sub1-index/index-b.md", "glossary": "./sub1/glossary-b.md"
},
{
- "title": "Index C", "file": "./index-c.md", "glossary": "./sub1/sub2/glossary-c.md"
+ "title": "Index C", "file": "./sub1-index/sub2-index/index-c.md", "glossary": "./sub1/sub2/glossary-c.md"
}
]
},
diff --git a/test/output-expected/config-indexFiles/154-deep-dir/document.md b/test/output-expected/config-indexFiles/154-deep-dir/document.md
index 7920abe3..b52a9a8e 100644
--- a/test/output-expected/config-indexFiles/154-deep-dir/document.md
+++ b/test/output-expected/config-indexFiles/154-deep-dir/document.md
@@ -16,13 +16,21 @@ AND a configuration
{
"generateFiles": {
"indexFiles": [
- { "title": "Index A", "file": "./index-a.md", "glossary": "./glossary-a.md" },
- { "title": "Index B", "file": "./index-b.md", "glossary": "./sub1/glossary-b.md" },
- { "title": "Index C", "file": "./index-c.md", "glossary": "./sub1/sub2/glossary-c.md" }
+ {
+ "title": "Index A", "file": "./index-a.md", "glossary": "./glossary-a.md"
+ },
+ {
+ "title": "Index B", "file": "./sub1-index/index-b.md", "glossary": "./sub1/glossary-b.md"
+ },
+ {
+ "title": "Index C", "file": "./sub1-index/sub2-index/index-c.md", "glossary": "./sub1/sub2/glossary-c.md"
+ }
]
},
"glossaries": [
- { "file": "./**/glossary-*.md" }
+ {
+ "file": "./**/glossary-*.md"
+ }
]
}
```
@@ -31,11 +39,15 @@ THEN the system MUST generate three files
* index-a.md
* WITH terms [GlossaryA_Term1][1], [GlossaryA_Term2][2], [GlossaryABC_Term3][7][2)][8][ 3)][9], only
-* index-b.md
+* sub1-index/index-b.md
* WITH terms [GlossaryB_Term1][3], [GlossaryB_Term2][4], [GlossaryABC_Term3][7][2)][8][ 3)][9], only
-* index-c.md
+* sub1-index/sub2-index/index-c.md
* WITH terms [GlossaryC_Term1][5], [GlossaryC_Term2][6], [GlossaryABC_Term3][7][2)][8][ 3)][9], only
+AND
+
+* links from within indexes at each depth MUST resolve to the document's section of occurrence.
+
[1]: ./glossary-a.md#glossarya_term1
[2]: ./glossary-a.md#glossarya_term2
diff --git a/test/output-expected/config-indexFiles/154-deep-dir/glossarify-md.conf.json b/test/output-expected/config-indexFiles/154-deep-dir/glossarify-md.conf.json
index f7820303..fcbf75b0 100644
--- a/test/output-expected/config-indexFiles/154-deep-dir/glossarify-md.conf.json
+++ b/test/output-expected/config-indexFiles/154-deep-dir/glossarify-md.conf.json
@@ -15,10 +15,10 @@
"title": "Index A", "file": "./index-a.md", "glossary": "./glossary-a.md"
},
{
- "title": "Index B", "file": "./index-b.md", "glossary": "./sub1/glossary-b.md"
+ "title": "Index B", "file": "./sub1-index/index-b.md", "glossary": "./sub1/glossary-b.md"
},
{
- "title": "Index C", "file": "./index-c.md", "glossary": "./sub1/sub2/glossary-c.md"
+ "title": "Index C", "file": "./sub1-index/sub2-index/index-c.md", "glossary": "./sub1/sub2/glossary-c.md"
}
]
},
diff --git a/test/output-expected/config-indexFiles/154-deep-dir/index-b.md b/test/output-expected/config-indexFiles/154-deep-dir/sub1-index/index-b.md
similarity index 59%
rename from test/output-expected/config-indexFiles/154-deep-dir/index-b.md
rename to test/output-expected/config-indexFiles/154-deep-dir/sub1-index/index-b.md
index 0c6d3240..4bba741a 100644
--- a/test/output-expected/config-indexFiles/154-deep-dir/index-b.md
+++ b/test/output-expected/config-indexFiles/154-deep-dir/sub1-index/index-b.md
@@ -12,14 +12,14 @@
[Glossary B][6] ○ [Testing config indexFiles with multiple index files][4]
-[1]: ./glossary-a.md#glossaryabc_term3
+[1]: ../glossary-a.md#glossaryabc_term3
-[2]: ./sub1/glossary-b.md#glossaryabc_term3
+[2]: ../sub1/glossary-b.md#glossaryabc_term3
-[3]: ./sub1/sub2/glossary-c.md#glossaryabc_term3
+[3]: ../sub1/sub2/glossary-c.md#glossaryabc_term3
-[4]: ./document.md#testing-config-indexfiles-with-multiple-index-files
+[4]: ../document.md#testing-config-indexfiles-with-multiple-index-files
-[5]: ./sub1/glossary-b.md#glossaryb_term1
+[5]: ../sub1/glossary-b.md#glossaryb_term1
-[6]: ./sub1/glossary-b.md#glossaryb_term2
+[6]: ../sub1/glossary-b.md#glossaryb_term2
diff --git a/test/output-expected/config-indexFiles/154-deep-dir/index-c.md b/test/output-expected/config-indexFiles/154-deep-dir/sub1-index/sub2-index/index-c.md
similarity index 57%
rename from test/output-expected/config-indexFiles/154-deep-dir/index-c.md
rename to test/output-expected/config-indexFiles/154-deep-dir/sub1-index/sub2-index/index-c.md
index c24abace..fc3b3bbe 100644
--- a/test/output-expected/config-indexFiles/154-deep-dir/index-c.md
+++ b/test/output-expected/config-indexFiles/154-deep-dir/sub1-index/sub2-index/index-c.md
@@ -12,14 +12,14 @@
[Glossary C][6] ○ [Testing config indexFiles with multiple index files][4]
-[1]: ./glossary-a.md#glossaryabc_term3
+[1]: ../../glossary-a.md#glossaryabc_term3
-[2]: ./sub1/glossary-b.md#glossaryabc_term3
+[2]: ../../sub1/glossary-b.md#glossaryabc_term3
-[3]: ./sub1/sub2/glossary-c.md#glossaryabc_term3
+[3]: ../../sub1/sub2/glossary-c.md#glossaryabc_term3
-[4]: ./document.md#testing-config-indexfiles-with-multiple-index-files
+[4]: ../../document.md#testing-config-indexfiles-with-multiple-index-files
-[5]: ./sub1/sub2/glossary-c.md#glossaryc_term1
+[5]: ../../sub1/sub2/glossary-c.md#glossaryc_term1
-[6]: ./sub1/sub2/glossary-c.md#glossaryc_term2
+[6]: ../../sub1/sub2/glossary-c.md#glossaryc_term2