git.iko.soy/typeable/remark-validate-links
on main help sign in
Remove use of `remark-slug`
commit91449c659f7feff93516447d35169ac95afc05c8 authorTitus Wormer <tituswormer@gmail.com> dateSun 12 Aug 2018, 12:43 (8 years ago) parentff5eb0d
2 files changed+11−8
index.js+9−7 package.json+2−1
index.js+9−7
@@ -4,9 +4,10 @@ var url = require('url')
44var propose = require('propose')
55var visit = require('unist-util-visit')
66var definitions = require('mdast-util-definitions')
7+var toString = require('mdast-util-to-string')
78var hostedGitInfo = require('hosted-git-info')
89var urljoin = require('urljoin')
9−var slug = require('remark-slug')
10+var slugs = require('github-slugger')()
1011var xtend = require('xtend/mutable.js')
1112
1213/* Optional Node dependencies. */
@@ -75,8 +76,8 @@ function validateLinks(options, fileSet) {
7576 }
7677 }
7778
78− /* Attach `slug` and a plugin that adds our transformer after it. */
79− this.use(slug).use(subplugin)
79+ /* Attach a plugin that adds our transformer after it. */
80+ this.use(subplugin)
8081
8182 /* Attach a `completer`. */
8283 if (fileSet) {
@@ -103,10 +104,9 @@ function apiTransform(tree, file) {
103104/* Completer for the CLI (multiple files, and support to add more). */
104105function cliCompleter(set, done) {
105106 var exposed = {}
106− var check = checkFactory(exposed)
107107
108108 set.valueOf().forEach(expose)
109− set.valueOf().forEach(check)
109+ set.valueOf().forEach(checkFactory(exposed))
110110
111111 done()
112112
@@ -169,6 +169,8 @@ function transformerFactory(fileSet, info) {
169169
170170 landmarks[filePath] = true
171171
172+ slugs.reset()
173+
172174 visit(ast, mark)
173175
174176 space[referenceId] = references
@@ -176,8 +178,8 @@ function transformerFactory(fileSet, info) {
176178
177179 function mark(node) {
178180 var data = node.data || {}
179− var attrs = data.hProperties || data.htmlAttributes || {}
180− var id = attrs.name || attrs.id || data.id
181+ var props = data.hProperties || {}
182+ var id = props.name || props.id || data.id || slugs.slug(toString(node))
181183
182184 if (id) {
183185 landmarks[filePath + '#' + id] = true
package.json+2−1
@@ -21,10 +21,11 @@
2121 "index.js"
2222 ],
2323 "dependencies": {
24+ "github-slugger": "^1.2.0",
2425 "hosted-git-info": "^2.5.0",
2526 "mdast-util-definitions": "^1.0.0",
27+ "mdast-util-to-string": "^1.0.4",
2628 "propose": "0.0.5",
27− "remark-slug": "^5.0.0",
2829 "unist-util-visit": "^1.0.0",
2930 "urljoin": "^0.1.5",
3031 "xtend": "^4.0.1"