Skip to content

Fix slugify bug affecting headings containing special characters#19

Open
michaelhogg wants to merge 1 commit intowibblemonkey:masterfrom
michaelhogg:fix-slugify-bug
Open

Fix slugify bug affecting headings containing special characters#19
michaelhogg wants to merge 1 commit intowibblemonkey:masterfrom
michaelhogg:fix-slugify-bug

Conversation

@michaelhogg
Copy link

🔴 Problem

As described in issue #17, Markdown heading text containing special characters doesn't get correctly slugified, and so the links from the TOC to the headings don't work.

🔬 Investigation

By default, this extension uses the slugify() function provided by markdown-it-table-of-contents:

However, that function's output is incompatible with VSCode's slugifier ❌

🟢 Solution

This PR copies the exact logic from VSCode's slugifier:

to ensure that the slugification logic is accurate.

ℹ️ Example

The following example heading text:

This example heading & contains — special → characters 🌈

is slugified by markdown-it-table-of-contents's slugify() function like this: ❌

this-example-heading-%26-contains-%E2%80%94-special-%E2%86%92-characters-%F0%9F%8C%88

This PR fixes the slugification logic, so that that example heading text is now slugified to:

this-example-heading--contains--special--characters-

which is identical to the slug generated by VSCode's slugifier ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant