From c900a305a9b1f581490883e467163d2ff651c5e5 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Sun, 10 Dec 2017 13:32:24 +0100 Subject: [PATCH] Remove deprecated use of `htmlAttributes` --- index.js | 31 +++++++++++++------------------ test.js | 6 +----- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/index.js b/index.js index 2639fd3..5498d09 100644 --- a/index.js +++ b/index.js @@ -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; + } } diff --git a/test.js b/test.js index f7e8a8d..9e2ba0e 100644 --- a/test.js +++ b/test.js @@ -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)] : []); }