Skip to content

Commit

Permalink
fix: formatted headers (#235)
Browse files Browse the repository at this point in the history
* test: add test for formatted headers

* fix(deps): update anchor-markdown-header to v0.7.0
  • Loading branch information
hongaar authored Dec 7, 2022
1 parent fac090d commit 95715a3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
14 changes: 10 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/readme-with-formatted-headers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!-- START doctoc -->
<!-- END doctoc -->

## foo _bar_
## foo **baz**
## foo ~baf~
## bar_foo
## baz_foo_
## _foo_bax_
20 changes: 20 additions & 0 deletions test/transform-weird-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})

0 comments on commit 95715a3

Please sign in to comment.