node-gfmtoc icon indicating copy to clipboard operation
node-gfmtoc copied to clipboard

Generated Links Fail With Non-Ascii Headers

Open tajmone opened this issue 7 years ago • 1 comments

I've created a test page with two different auto-genereated TOCs, using the SublimeText plugin MarkdownTOC and gfmtoc (the second TOC):

  • https://github.com/tajmone/github-tests/blob/030a90e/headers-ids.md

As you can see by testing the two generated TOCS, the autogenerated links by gfmtoc fail with non-Ascii chars.

These are MarkdownTOC settings:

<!-- MarkdownTOC autolink="true" bracket="round" autoanchor="false" 
lowercase="true" lowercase_only_ascii="true" uri_encoding="true" -->

... the problem with gfmtoc seems to be caused by how it handles lower-casing (only Ascii range should be lowercased).

These are the TOC-links generated by MarkdownTOC:

- [Introduction](#introduction)
- [ESPAÑA](#espa%C3%91a)
- [ESPAÑA](#espa%C3%91a-1)
- [English中文标题](#english%E4%B8%AD%E6%96%87%E6%A0%87%E9%A2%98)

... and these the TOC-links by gfmtoc:

  - [Introduction](#introduction)
  - [ESPAÑA](#espa%C3%B1a)
  - [ESPAÑA](#espa%C3%B1a-1)
  - [English中文标题](#english%E4%B8%AD%E6%96%87%E6%A0%87%E9%A2%98)

Reference Links

I think this is the Ruby script used by GitHub to generate TOCs in documents previews:

  • https://github.com/jch/html-pipeline/blob/master/lib/html/pipeline/toc_filter.rb

tajmone avatar Nov 26 '17 12:11 tajmone

Thanks, reproduced. encodeURIComponent() returns different result. I’ll look into it.

hail2u avatar Nov 26 '17 23:11 hail2u