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

Improvement: render a nbsp instead of a space #88

Closed jamesplease closed 2 years ago

jamesplease commented 3 years ago

Hi! Thanks for the great library. I noticed that regular spaces are used, which means that the permalink can be wrapped separately from the header text. If this is switched to a non-breaking space ( ) then it ensures that the final word and the permalink will always appear side-to-side.

For folks who may be reading this issue, this can currently be solved in user-land as follows:

 md.use(require('markdown-it-anchor'), {
  permalink: true,
  permalinkSpace: false,
  permalinkSymbol: ' #',
});
valeriangalliat commented 2 years ago

The permalinkSymbol trick is a pretty good workaround! I wouldn't want to make   the default since it would be quite a breaking change, but I just released v8.6.1 with a way to customize the space option, so you can now do this:

const anchor = require('markdown-it-anchor')
const md = require('markdown-it')()

md.use(anchor, {
  permalink: anchor.permalink.linkInsideHeader({
    permalink: true,
    space: ' ',
  })
})

Sorry for the late reply!

jamesplease commented 2 years ago

Thanks so much @valeriangalliat !