marked icon indicating copy to clipboard operation
marked copied to clipboard

Add documentation for Slugger

Open ad-si opened this issue 5 years ago • 8 comments

Currently the heading token looks like this

{
  type: 'heading', 
  depth: 3, 
  text: 'Chapter 7',
}

I think it should also contain the heading id as it is not easy to generate from the text (https://github.com/markedjs/marked/blob/master/lib/marked.js#L1312).

{
  type: 'heading', 
  depth: 3, 
  text: 'Chapter 7',
  id: 'chapter-7',
}

An alternative would be to expose the slug function via the marked module.

ad-si avatar Apr 30 '19 19:04 ad-si

the slug function is exposed https://github.com/markedjs/marked/blob/5d727cb020fd9c748b228066f44f8a34828cc17b/lib/marked.js#L1685

UziTech avatar Apr 30 '19 20:04 UziTech

You can get the slug function from

const slugger = new marked.Slugger();
slugger.slug(...)

UziTech avatar Apr 30 '19 20:04 UziTech

Haha, what the heck. I somehow overlooked it in the code. 🙈 I guess when you don't expect to see something you don't see it even when it's there 😅.

Then the questions remains if it should be part of the token already 🤔

ad-si avatar Apr 30 '19 21:04 ad-si

I don't think computed properties should be part of the AST

UziTech avatar May 01 '19 14:05 UziTech

When you say it like this, I guess you're right. Then let's change the issue to "Add documentation for Slugger"

ad-si avatar May 01 '19 15:05 ad-si

PRs are welcome

UziTech avatar May 01 '19 16:05 UziTech

@UziTech The documentation already talks about the slugger. Do we need to add more info or clarify it somehow? Otherwise we can probably close this issue.

calculuschild avatar May 30 '21 15:05 calculuschild

The documentation should say something about marked.Slugger being public and show how to use it.

UziTech avatar May 31 '21 03:05 UziTech