Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
Remove deprecated use of htmlAttributes
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Dec 10, 2017
1 parent 9acfc00 commit c900a30
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
31 changes: 13 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,20 @@ function slug() {
function transformer(ast) {
slugs.reset();

visit(ast, 'heading', function (node) {
visit(ast, 'heading', visitor);

function visitor(node) {
var id = slugs.slug(toString(node));
var data = patch(node, 'data', {});

/* Non-html */
patch(data, 'id', id);
/* Legacy remark-html */
patch(data, 'htmlAttributes', {});
/* Current remark-html */
patch(data, 'hProperties', {});
patch(data.htmlAttributes, 'id', id);
patch(data.hProperties, 'id', id);
});
}

function patch(context, key, value) {
if (!context[key]) {
context[key] = value;
}
if (!node.data) {
node.data = {};
}

return context[key];
if (!node.data.hProperties) {
node.data.hProperties = {};
}

node.data.id = id;
node.data.hProperties.id = id;
}
}
6 changes: 1 addition & 5 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@ test('slugs', function (t) {
function heading(label, id) {
return u('heading', {
depth: 2,
data: {
id: id,
htmlAttributes: {id: id},
hProperties: {id: id}
}
data: {id: id, hProperties: {id: id}}
}, label ? [u('text', label)] : []);
}

0 comments on commit c900a30

Please sign in to comment.