Skip to content
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

id attribute in heading is not show in the right way when they contains some Chinese #1329

Closed
hangboss1761 opened this issue Aug 31, 2018 · 5 comments
Labels
category: headings L2 - annoying Similar to L1 - broken but there is a known workaround available for the issue

Comments

@hangboss1761
Copy link

I have a markdown string contains some Chinese like this:

# 中文English中文

use marked I got this:

<h1 id="-Englist-">中文English中文</h1>

I wish I cloud get this:

<h1 id="中文Englist中文">中文English中文</h1>

id attribute in headings (h1,h2,h3,etc) is not show in the right way

@UziTech UziTech added L2 - annoying Similar to L1 - broken but there is a known workaround available for the issue category: headings labels Aug 31, 2018
@UziTech
Copy link
Member

UziTech commented Aug 31, 2018

demo

@styfle
Copy link
Member

styfle commented Aug 31, 2018

Related: #1280

It looks like github-slugger could be used to solve this issue too.

@jinasonlin
Copy link

I also encountered this problem, try custom renderer

  const renderer = new marked.Renderer();
  renderer.heading = (text, level, raw) => {
    const id = raw.toLowerCase().replace(/[^a-zA-Z0-9\u4e00-\u9fa5]+/g, '-');
    return `<h${level} id=${id}>${text}</h${level}>\n`;
  };

  const result = marked(src, { renderer });

@hangboss1761
Copy link
Author

@jinasonlin
It works!Thank you!

@joshbruce
Copy link
Member

Closing as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: headings L2 - annoying Similar to L1 - broken but there is a known workaround available for the issue
Projects
None yet
Development

No branches or pull requests

5 participants