Skip to content

Commit a3efb80

Browse files
committed
Update mdast-slug
1 parent f34429b commit a3efb80

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

component.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"mdast"
1818
],
1919
"dependencies": {
20-
"wooorm/mdast-slug": "^1.0.0",
20+
"wooorm/mdast-slug": "^2.0.0",
2121
"wooorm/mdast-util-to-string": "^1.0.0"
2222
},
2323
"repository": "wooorm/mdast-toc",

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function search(root, expression, maxDepth) {
104104
map.push({
105105
'depth': child.depth,
106106
'value': value,
107-
'id': child.attributes.id
107+
'id': child.data.htmlAttributes.id
108108
});
109109
}
110110
}

mdast-toc.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function search(root, expression, maxDepth) {
105105
map.push({
106106
'depth': child.depth,
107107
'value': value,
108-
'id': child.attributes.id
108+
'id': child.data.htmlAttributes.id
109109
});
110110
}
111111
}
@@ -529,6 +529,18 @@ function attacher(mdast, options) {
529529
library = githubFactory(library);
530530
}
531531

532+
/**
533+
* Patch `value` on `context` at `key`, if
534+
* `context[key]` does not already exist.
535+
*/
536+
function patch(context, key, value) {
537+
if (!context[key]) {
538+
context[key] = value;
539+
}
540+
541+
return context[key];
542+
}
543+
532544
/**
533545
* Adds an example section based on a valid example
534546
* JavaScript document to a `Usage` section.
@@ -537,11 +549,12 @@ function attacher(mdast, options) {
537549
*/
538550
function transformer(ast) {
539551
visit(ast, 'heading', function (node) {
540-
if (!node.attributes) {
541-
node.attributes = {};
542-
}
552+
var id = library(toString(node));
553+
var data = patch(node, 'data', {});
543554

544-
node.attributes.id = library(toString(node));
555+
patch(data, 'id', id);
556+
patch(data, 'htmlAttributes', {});
557+
patch(data.htmlAttributes, 'id', id);
545558
});
546559
}
547560

mdast-toc.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"mdast"
1818
],
1919
"dependencies": {
20-
"mdast-slug": "^1.0.0",
20+
"mdast-slug": "^2.0.0",
2121
"mdast-util-to-string": "^1.0.0"
2222
},
2323
"repository": "wooorm/mdast-toc",

0 commit comments

Comments
 (0)