diff --git a/package-lock.json b/package-lock.json index 71c59bf..7a4e8b7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -329,11 +329,12 @@ } }, "anchor-markdown-header": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/anchor-markdown-header/-/anchor-markdown-header-0.6.0.tgz", - "integrity": "sha512-v7HJMtE1X7wTpNFseRhxsY/pivP4uAJbidVhPT+yhz4i/vV1+qx371IXuV9V7bN6KjFtheLJxqaSm0Y/8neJTA==", + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/anchor-markdown-header/-/anchor-markdown-header-0.7.0.tgz", + "integrity": "sha512-OYUgo5tYN+WipGB2R3sZUvXLpTzqSnm0b3AXRqN9Rhi2Z+uCQsFSguDDgpoSdhDrnu/aCYHFGHosdL9hbaWSHA==", "requires": { - "emoji-regex": "~10.1.0" + "emoji-regex": "~10.1.0", + "remove-markdown": "^0.5.0" } }, "ansi-regex": { @@ -1708,6 +1709,11 @@ "mdast-util-from-markdown": "^0.8.0" } }, + "remove-markdown": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/remove-markdown/-/remove-markdown-0.5.0.tgz", + "integrity": "sha512-x917M80K97K5IN1L8lUvFehsfhR8cYjGQ/yAMRI9E7JIKivtl5Emo5iD13DhMr+VojzMCiYk8V2byNPwT/oapg==" + }, "repeat-string": { "version": "1.6.1", "resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz", diff --git a/package.json b/package.json index 94ada54..e907f82 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "bin": "doctoc.js", "dependencies": { "@textlint/markdown-to-ast": "^12.1.1", - "anchor-markdown-header": "^0.6.0", + "anchor-markdown-header": "^0.7.0", "htmlparser2": "^7.2.0", "minimist": "^1.2.6", "underscore": "^1.13.2", diff --git a/test/fixtures/readme-with-formatted-headers.md b/test/fixtures/readme-with-formatted-headers.md new file mode 100644 index 0000000..4ba61d6 --- /dev/null +++ b/test/fixtures/readme-with-formatted-headers.md @@ -0,0 +1,9 @@ + + + +## foo _bar_ +## foo **baz** +## foo ~baf~ +## bar_foo +## baz_foo_ +## _foo_bax_ diff --git a/test/transform-weird-headers.js b/test/transform-weird-headers.js index 19ddcd5..5154429 100644 --- a/test/transform-weird-headers.js +++ b/test/transform-weird-headers.js @@ -60,3 +60,23 @@ test('\nemoji-first header names', function (t) { t.end() }) + +test('\nformatted headers', function (t) { + var content = require('fs').readFileSync(__dirname + '/fixtures/readme-with-formatted-headers.md', 'utf8'); + var headers = transform(content); + + t.same( + headers.toc.split('\n') + , [ '', + '- [foo _bar_](#foo-bar)', + '- [foo **baz**](#foo-baz)', + '- [foo ~baf~](#foo-baf)', + '- [bar_foo](#bar_foo)', + '- [baz_foo_](#baz_foo_)', + '- [_foo_bax_](#foo_bax)', + '' ] + , 'generates a correct toc when readme includes formatting in the heading title' + ) + + t.end() +})