Skip to content

Commit

Permalink
38 footnotes stop working when using glossarify (#40)
Browse files Browse the repository at this point in the history
* feat: New option `--experimentalFootnotes` for Markdown footnotes (#38). 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 authored Oct 4, 2019
1 parent 490874e commit 3a6b411
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [2.1.0](https://github.com/about-code/glossarify-md/compare/v2.0.0...v2.1.0) (2019-10-04)

### Features

* New option `--experimentalFootnotes` for Markdown footnotes ([#38](https://github.com/about-code/glossarify-md/issues/38)). 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. ([f75a21c](https://github.com/about-code/glossarify-md/commit/f75a21c))
---

### [2.0.1](https://github.com/about-code/glossarify-md/compare/v2.0.0...v2.0.1) (2019-10-04)


Expand Down
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
1 change: 1 addition & 0 deletions test/input/config-shared/glossarify-md.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"outDir": "../../output-actual/config-shared",
"includeFiles": ["."],
"excludeFiles": [],
"experimentalFootnotes": true,
"keepRawFiles": [],
"glossaries": [
{ "file": "./markdown/glossary.md", "termHint": "" },
Expand Down
12 changes: 12 additions & 0 deletions test/input/config-shared/markdown/footnotes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Markdown Extensions: Footnotes

<!--
Footnotes are not yet part of CommonMark Spec
under spec.commonmark.org
-->

GIVEN option `experimentalFootnotes: true`
AND text with a footnote [^footnote]
THEN colons of the footnote definition prior to 'Footnote text' MUST NOT be converted to HTML entities.

[^footnote]: Footnote text.
1 change: 1 addition & 0 deletions test/output-expected/config-shared/glossarify-md.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"outDir": "../../output-actual/config-shared",
"includeFiles": ["."],
"excludeFiles": [],
"experimentalFootnotes": true,
"keepRawFiles": [],
"glossaries": [
{ "file": "./markdown/glossary.md", "termHint": "" },
Expand Down
12 changes: 12 additions & 0 deletions test/output-expected/config-shared/markdown/footnotes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Markdown Extensions: Footnotes

<!--
Footnotes are not yet part of CommonMark Spec
under spec.commonmark.org
-->

GIVEN option `experimentalFootnotes: true`
AND text with a footnote [^footnote]
THEN colons of the footnote definition prior to 'Footnote text' MUST NOT be converted to HTML entities.

[^footnote]: Footnote text.

0 comments on commit 3a6b411

Please sign in to comment.