yzhang-gh / vscode-markdown

Markdown All in One
https://marketplace.visualstudio.com/items?itemName=yzhang.markdown-all-in-one
MIT License
2.91k stars 322 forks source link

add more slugification strategies #1417

Closed float3 closed 4 months ago

float3 commented 5 months ago

Proposal

none of the markdown.extension.toc.slugifyMode options allow you to turn cnjpkr characters into something that a static site generator would expect for example, a static site generator might turn

# 誰にでも長所と短所がある
# 命来犯天写最大巡祭視死乃読
# 국무위원은 국무총리의 제청으로 대통령이 임명한다

into

      <h1 id=shui-nidemochang-suo-toduan-suo-gaaru>誰にでも長所と短所がある</h1>
      <h1 id=ming-lai-fan-tian-xie-zui-da-xun-ji-shi-si-nai-du>命来犯天写最大巡祭視死乃読</h1>
      <h1 id=gugmuwiweoneun-gugmucongriyi-jeceongeuro-daetongryeongi-immyeonghanda>국무위원은 국무총리의 제청으로 대통령이 임명한다</h1>

this will break if a TOC is generated because none of the TOC slugification strategies offer this functionality.

Other information

tested with Zola, but i'm sure it applies to other static site generators.

yzhang-gh commented 5 months ago

Thanks for the feedback. However, we need to know the underline implementation so we can mimic the output. For example, GitHub uses this code

https://github.com/yzhang-gh/vscode-markdown/blob/d2862ca363656c244ff587e6ce17e875e02457ed/src/util/slugify.ts#L99-L109

so we can simple convert it to javascript.

If you can find out how Zola does this, we can add a new slugify mode for it. PR is welcomed.

float3 commented 5 months ago

https://github.com/Stebalien/slug-rs

this is the library Zola uses, I'll look into making a PR

float3 commented 5 months ago

since it's written in rust it would be possible to leverage wasm, to have identical behavior without rewriting it in JavaScript/Typescript, I assume vscode extensions can do wasm etc.

yzhang-gh commented 5 months ago

I assume vscode extensions can do wasm etc.

I don't have such experience but it sounds good to do it.

float3 commented 5 months ago

I assume vscode extensions can do wasm etc.

I don't have such experience but it sounds good to do it.

ok just to make sure we're on the same page, this would involve adding some amount of rust (<10 lines) to the repository to make a bridge between the rust library and the javascript

yzhang-gh commented 5 months ago

100% fine

float3 commented 5 months ago

ok great, i'm working on it