Skip to content

Commit

Permalink
feat: New option --experimentalFootnotes for Markdown footnotes (#38)…
Browse files Browse the repository at this point in the history
…. Support for Pandoc footnote syntax will be considered *experimental* until it becomes part of the official CommonMark Specification at https://spec.commonmark.org. See also https://pandoc.org/MANUAL.html#footnotes.
  • Loading branch information
about-code committed Oct 4, 2019
1 parent 490874e commit f75a21c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ Path to directory where to search for the glossary and markdown files. All paths
Paths or Glob-Patterns of files to exclude. Use `keepRawFiles` if you just
want to ignore certain markdown files from being modified.

### `--experimentalFootnotes`

Enable support for markdown footnote syntax as defined at https://pandoc.org/MANUAL.html#footnotes. Footnotes will be considered an *experimental* feature until they become official part of the CommonMark Specification at https://spec.commonmark.org.

### `--glossaries`

- **Range:** Array<{file: string, [termHint: string]}>
Expand Down
6 changes: 6 additions & 0 deletions conf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
"alias": "e",
"default": ["node_modules", ".git"]
},
"experimentalFootnotes": {
"description": "Enable support for markdown footnotes as defined in https://pandoc.org/MANUAL.html#footnotes. Footnotes are considered 'experimental' until they become part of the CommonMark Specification at https://spec.commonmark.org.",
"type": "boolean",
"alias": "",
"default": false
},
"force": {
"description": "Choose true, only if you know the consequences.",
"type": "boolean",
Expand Down
3 changes: 3 additions & 0 deletions doc/vuepress.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ npm i --save glossarify-md
"outDir": "../target",
"includeFiles": ["."],
"excludeFiles": ["**/*.exclude.md"],
"experimentalFootnotes": true,
"keepRawFiles": ["**/*.raw.md"],
"glossaries": [
{ "file": "./glossary.md", "termHint": ""},
Expand All @@ -56,6 +57,8 @@ npm i --save glossarify-md
> **☛ Tip:** You are free to choose a different structure, e.g. with `.vuepress/` or `images/` being siblings *next to* `baseDir` (src) rather than being children of it. This reduces the number of files being copied from `baseDir` to `outDir` (target) and could improve build times if there are many static assets. Relative paths may just become a bit longer.
> **☛ Since v2.1.0** you can enable `experimentalFootnotes` if you use *vuepress* with [markdown-it-footnote](https://www.npmjs.com/package/markdown-it-footnote) plug-in.
## Configure *vuepress*

*vuepress* and *glossarify-md* use "slug" algorithms to create friendly URL fragments (#...) for section links. When *vuepress* translates glossarified markdown to HTML it slugifies anchor names a second time by its own algorithm. Unfortunately it does so inconsistently for links with unicode characters. E.g it translates the heading anchor `#äquator` for a glossary term *Äquator* into an HTML anchor `#aquator` with a different first letter ([vuejs/vuepress#1815](https://github.com/vuejs/vuepress/issues/1815)). Though, any links to it still point to `#äquator`. As a consequence there'll be term links navigating to the glossary, though, not to the anchor position of the term's definition ([about-code/glossarify-md#27](https://github.com/about-code/glossarify-md/issues/27)).
Expand Down
9 changes: 7 additions & 2 deletions lib/linker.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ const api = {};
* @param {*} context
*/
api.linkTermOccurrences = function(context) {
const {baseDir, outDir, includeFiles, keepRawFiles, excludeFiles, glossaries} = context.opts;
const {
baseDir, outDir, includeFiles, keepRawFiles,
excludeFiles, glossaries, experimentalFootnotes
} = context.opts;
return new Promise((resolve, reject) => {
unifiedNgin({
processor: unified()
.use(remark_parse)
.use(remark_parse, {
footnotes: experimentalFootnotes
})
.use(common.printAst(context.opts.dev.printInputAst)) // Might be regex. /.*\/table\.md/g;
.use(linker(context))
.use(remark_ref_links)
Expand Down
9 changes: 7 additions & 2 deletions lib/terminator.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ const api = {};
* @return {Promise<Term[]>} terms
*/
api.readTermDefinitions = function(context) {
const {baseDir, outDir, glossaries, keepRawFiles, excludeFiles} = context.opts;
const {
baseDir, outDir, glossaries, keepRawFiles, excludeFiles,
experimentalFootnotes
} = context.opts;
return new Promise((resolve, reject) => {
unifiedNgin(
{
processor: unified()
.use(remark_parse)
.use(remark_parse, {
footnotes: experimentalFootnotes
})
.use(common.printAst(context.opts.dev.printInputAst)) // Might be regex. /.*\/table\.md/g;
.use(remark_slug)
.use(remark_link_headings, {behavior: 'wrap'})
Expand Down

0 comments on commit f75a21c

Please sign in to comment.