-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does not parse emphesis like **bold** or *italic* #19
Comments
Hi. A PR with a fix would be very welcome. Although I would argue that no styling should be transfered to the TOC. The formatting should rather be stripped away. |
|
Workaround: const removeMarkdown = require('remove-markdown');
const toc = require('markdown-it-table-of-contents');
const md = require('markdown-it')();
md.use(toc, {
format: removeMarkdown,
});
const src = `
[[toc]]
# *Title*
## Subtitle
`;
md.render(src, {}); |
I guess we can close this. Workaround/Solution mentioned above work for most usecases. |
👍 |
Hi. Thanks for making this plugin! It's been really helpful. I'd like to re-raise this issue. By default, I think this library should either:
The current default behavior – rendering unprocessed markdown – is probably not what anyone wants or expects. I understand you can achieve either of these outcomes using a Of the two options I've suggested, I think it would be better and easier to process the markdown. (Stripping could be tricky given the full range of possibilities, especially if you consider rarer options like superscript, subscript, etc.). I'm using this lib to render ToCs for scientific articles. In my (admittedly complex) use case, headers may include a variety of formatting (e.g. italics, superscripts, even equations). And this formatting is often integral to header's legibility / meaning (i.e. it's not just a matter of style). How to implement / Need help?Looking at your code, I think the
And this allowed me to process markdown text within my extension – which I think is what we want in this case as well. I'm not 100% sure how this would work in your code, but I think it's possible (and probably pretty easy). If you need help, lemme know and could probably make a PR. |
Hi! Thanks for chipping in...
I agree.
I haven't considered this scenario. It makes sense.
Given your examples I see your point. However, I think it would be preferable if it could be an option like so: Do you think it's somewhat plausible to implement stripping markdown? Haven't looked at it in any depth but I imagine it's possible by either hooking into the markdown-it parser or by stripping markdown in the raw text via regexp or similar (I've seen libs that do that)... |
Thanks for considering this change! I like the idea of adding a As I said, I think processing the markdown should be easy (maybe even a one-liner). Stripping the markdown is a bit trickier. Here's what I would suggest: 1. Use an existing libraryBoth remove-markdown and strip-markdown seem decent. That said, they do seem a little greedy and could result in striping non-markdown text in rare edge cases (e.g. if your heading includes a non-markdown 2. Don't even tryMaybe, instead, give folks the option to render the raw markdown (i.e. Most of all, I would avoid trying to write your own regex. Just my opinion but I think it could end up being a messy, half-solution. And, given a tricky problem, I'd rather avoid it altogether than apply a partial fix. But that's just my opinion. |
Ok, I hear you... Then maybe we could just consider changing the default for the A PR with this change would be very welcome! |
@martinlissmyr Sorry I dropped the ball on this fix for several months. But, finally, I have a PR for you to review: #41 Thanks again for creating this extension! |
example:
# My **bold** title
should render as:
<li>My <strong>bold</strong> title</li>
does render as:
<li>My **bold** title</li>
The text was updated successfully, but these errors were encountered: