mixu / markdown-styles

Markdown to static HTML generator and multiple CSS themes for Markdown
1.85k stars 250 forks source link

Question mark(?) is replaced by hyphen(-) in the header links in the conversion process #43

Closed jitendersandhu closed 7 years ago

jitendersandhu commented 8 years ago

Hi,

Firstly, thanks for this awesome tool!

I am facing an issue with header links, when the markdown(.md) files are converted into HTML, the question(?) mark in the header links is replaced with a hyphen(-). This is causing problem for me since, I am using DocToc to create a Table of Contents for the document and the DocToc, removes question mark while generating links inside Table of Contents.

As per my understanding, this is happening due to the following line in renderer.heading function inside markdown-styles/lib/convert-md.js file.

var id = this.options.headerPrefix + raw.trim().toLowerCase().replace(/[^\w]+/g, '-');

Is there a way to configure markdown-styles to simply remove any special character like question(?) mark when header links are generated.

Though, I am not sure whether this is intended or a bug. Any help would be highly appreciated!

mixu commented 8 years ago

I think we could make this smarter! Trailing special characters probably should not be in the header link. Any chance you could write a PR? It would be nice to have a flag to keep the old behavior in case someone already depends on it (or perhaps generate a second anchor with the old URL as well in the same spot so we don't need a new flag)

jitendersandhu commented 8 years ago

Thanks for a quick response!

Trailing special characters probably should not be in the header link.

My use case here is an FAQ doc, where header-links are the questions itself, i was thinking it would nice to include the question mark and have both markdown-styles and DocToc work at same time.

keep the old behavior in case someone already depends on it

Totally agree, definitely the old behavior should be intact.

Any chance you could write a PR?

Sure, I will try to give it some time (though, I may not be able to get to it for another week or two ☺).

Meantime, if you want to close this issue, it's totally fine and i will re-open if i'm able to work on this PR.

Thanks again!

mixu commented 7 years ago

fixed in v.3.1.9 (the rules around anchor links were relaxed to support Chinese characters)