naokazuterada / MarkdownTOC

SublimeText3 plugin which generate a table of contents (TOC) in a markdown document.
https://packagecontrol.io/packages/MarkdownTOC
MIT License
301 stars 48 forks source link

Broken autolink when - (dash) used in the title #143

Closed ig-vb closed 4 years ago

ig-vb commented 4 years ago

Autolinking generates wrong TOC when dash (- ) used in the title.

How can the issue be reproduced

# One title

# Second - title

What was expected

<!-- MarkdownTOC autolink="true" -->

- [One title](#one-title)
- [Second - title](#second-title)

<!-- /MarkdownTOC -->

What actually occurred

<!-- MarkdownTOC autolink="true" -->

- [One title](#one-title)
- [Second - title](#second---title)

<!-- /MarkdownTOC -->

What was the version of the involved component

MarkdownTOC v3.0.5 and Sublime 3.2.2 build 3211

jonasbn commented 4 years ago

Hi @ig-vb

What does the anchored ID look like? does it match the generated autolink with the consecutive dashes:

<a id="#second---title"></a>

or is it different?

Do the links work even though they do not resemble the titles exactly.

ig-vb commented 4 years ago

Hi @jonasbn

The generated autolink is:

- [Second - title](#second---title)

but the anchored ID is different.

This title:

Second - title

will get this anchor:

#second-title

So the links do not work. Correct, working link, generated by the plugin should be:

- [Second - title](#second-title)
Odyseus commented 4 years ago

Hello, everybody.

I can't reproduce the issue reported here, neither in MarkdownTOC 3.0.4 nor in the recently updated to 3.0.5. The generated markup with the example given is:

<!-- MarkdownTOC autolink="true" -->

- [One title](#one-title)
- [Second - title](#second---title)

<!-- /MarkdownTOC -->

<a id="one-title"></a>
# One title

<a id="second---title"></a>
# Second - title

The ID second---title is a valid ID and it's functional.

ig-vb commented 4 years ago

After further testing, the generated links work with GitHub, but they are not working in GitLab.

It seems that the plugin is working correctly, the problem seems to be at GitLab. Please close this issue if you agree.

naokazuterada commented 4 years ago

@ig-vb

Hi, you can deal with this by:

{
  "id_replacements": [
    {
      "pattern": "\\s+",
      "replacement": "-"
    }
  ]
}

{
  "id_replacements": [
    {
      "pattern": "\\s+",
      "replacement": ""
    }
  ]
}

on your user settings (MarkdownTOC.sublime-setting).

Ref: Manipulation of auto link ids

ig-vb commented 4 years ago

Thank you!