valeriangalliat / markdown-it-anchor

A markdown-it plugin that adds an `id` attribute to headings and optionally permalinks.
The Unlicense
291 stars 72 forks source link

Issue with linkAfterHeader #92

Closed Antonio-Laguna closed 3 years ago

Antonio-Laguna commented 3 years ago

Somehow the new version is eating up some headings. Given that the library is minified I can't test to see what could be causing it without downloading the repo but this markup

'## One\n\n## Two\n\n### Three\n\n## Four\n\n### Five\n\n### Six\n\n### Seven\n\n### Eight\n\n## Nine\n\n## Ten\n\n## Eleven\n\n## Twelve\n\n### Thirteen\n\n### Fourteen\n\n## Fifteen\n\n## Sixteen'

Is only riding up until four with this config:

strictEqual(
  md().use(anchor, {
    permalink: anchor.permalink.linkAfterHeader({
      style: 'visually-hidden',
      assistiveText: title => `Link To ${title}โ€`,
      visuallyHiddenClass: 'visually-hidden',
      class: 'direct-link',
      symbol: '๐Ÿ”—'
    }),
    level: [1, 2, 3, 4]
  }).render('## One\n\n## Two\n\n### Three\n\n## Four\n\n### Five\n\n### Six\n\n### Seven\n\n### Eight\n\n## Nine\n\n## Ten\n\n## Eleven\n\n## Twelve\n\n### Thirteen\n\n### Fourteen\n\n## Fifteen\n\n## Sixteen'),
  ''
)

I think it's linkAfterHeader since optionless seems to work fine. This is the output:

+ '<h2 id="one" tabindex="-1">One</h2>\n' +
+   '<a class="direct-link" href="#one"><span class="visually-hidden">Link To Oneโ€</span> <span aria-hidden="true">๐Ÿ”—</span></a><h2 id="two" tabindex="-1">Two</h2>\n' +
+   '<a class="direct-link" href="#two"><span class="visually-hidden">Link To Twoโ€</span> <span aria-hidden="true">๐Ÿ”—</span></a><h3 id="three" tabindex="-1">Three</h3>\n' +
+   '<a class="direct-link" href="#three"><span class="visually-hidden">Link To Threeโ€</span> <span aria-hidden="true">๐Ÿ”—</span></a><h2 id="four" tabindex="-1">Four</h2>\n' +
+   '<a class="direct-link" href="#four"><span class="visually-hidden">Link To Fourโ€</span> <span aria-hidden="true">๐Ÿ”—</span></a><h3>Five</h3>\n' +
+   '<h3>Six</h3>\n' +
+   '<h3>Seven</h3>\n' +
+   '<h3>Eight</h3>\n' +
+   '<h2>Nine</h2>\n' +
+   '<h2>Ten</h2>\n' +
+   '<h2>Eleven</h2>\n' +
+   '<h2>Twelve</h2>\n' +
+   '<h3>Thirteen</h3>\n' +
+   '<h3>Fourteen</h3>\n' +
+   '<h2>Fifteen</h2>\n' +
+   '<h2>Sixteen</h2>\n'