Skip to content

Commit

Permalink
fix: dangling anchor links with german umlauts (#27). See updates to …
Browse files Browse the repository at this point in the history
…doc/vuepress.md and slugify option.
  • Loading branch information
about-code committed Sep 25, 2019
1 parent f464ceb commit 475d692
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
Empty file modified bin/index.js
100644 → 100755
Empty file.
21 changes: 21 additions & 0 deletions lib/glossarify.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const terminator = require("./terminator");
const linker = require("./linker");
const writer = require("./writer");
const Dictionary = require("./dictionary");
const GitHubSlugger = require("github-slugger");

const api = {};
const CWD = proc.cwd();
Expand All @@ -31,6 +32,26 @@ api.glossarify = function(opts) {
.catch(err => console.error(err) && proc.exit(1));
}

/**
* Provide internally used slugifier to allow for better integration with vuepress
* See also https://github.com/about-code/glossarify-md/issues/27.
*/
api.getSlugger = function() {
return (url) => {
const slugger = new GitHubSlugger();
return slugger.slug(url);
};
// Implementation note:
// GitHubSlugger is stateful to be able to create unique names if the same
// anchor/headline/term occurs twice on a *single page*. But slugify function
// provided to vuepress will be invoked for different pages of a project.
// They would appear to GitHubSlugger as being a single page / namespace if
// we didn't create a new GitHubSlugger with every call, here. Rather than
// creating a new instance we could also close over a single instance and
// call 'slugger.reset()'. But, we decided to create an instance in the
// function body which can be garbage collected immediately after the call.
}

/**
* @private
* @param {} context
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"license": "MIT",
"dependencies": {
"fs-extra": "^8.1.0",
"github-slugger": "^1.0.0",
"glob": "^7.0.3",
"minimist": "^1.2.0",
"minimist-options": "^4.0.1",
Expand Down

0 comments on commit 475d692

Please sign in to comment.