chore: improve CJK emphasis handling in markdown processing#331
chore: improve CJK emphasis handling in markdown processing#331
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR improves CJK (Chinese, Japanese, Korean) emphasis handling in markdown processing by inserting zero-width space HTML entities around emphasis markers when they are adjacent to CJK characters without spaces.
- Adds preprocessing to detect CJK characters and insert HTML entities around emphasis markers
- Implements post-processing to remove these entities from final HTML output
- Includes comprehensive handling of code blocks and inline code spans to avoid affecting literal content
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
What do you think about the idea in this PR? Could you please review it? |
|
Hmm, I don't think I'm capable of reviewing this PR. I haven't written any parser before, so I can't offer advices better than LLM. I have indeed been tortured by this markdown parsing problem, but my usual solution is changing the parser (or installing an extension to the parser) rather than patching it on my own… |
|
Thank you for your comment. I also believe that improving the parser logic is the smart way to address this. Since this is mainly a workaround, I don't feel confident enough to propose it upstream. At the very least, if we can confirm that it doesn't break the documentation, it would be best to first operate this experimentally as a workaround within the Japanese community. |
kimushun1101
left a comment
There was a problem hiding this comment.
I understood the situation and was able to verify the behavior.
However, I’m not as good as Copilot at reviewing my own source code.
I measured the time using the following command:
time mise run generate
The build time hasn’t increased noticeably compared to before.
gomazarashi
left a comment
There was a problem hiding this comment.
I’m not very familiar with the code itself, but I’ve confirmed that the documentation was generated correctly.
Thank you for addressing this issue.
ultimatile
left a comment
There was a problem hiding this comment.
Looks nice, thank you!
731a679 to
9e22d59
Compare
|
pulldown-cmarkをmarkdown-cjk-friendlyのサポートが追加されたカスタムバージョンに変更し、既存のドキュメントのCJK強調の回避策を削除しました。お手数ですが再度レビューをお願いします。 |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 30 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
In typst-docs, we use pulldown-cmark to parse Markdown. This library faithfully implements the CommonMark specification along with several dialects.
However, since the CommonMark spec is designed for languages that use word separation, its rules for emphasis are quite odd when applied to CJK markup.
Please add the following markup to an appropriate page:
In such cases, to apply emphasis, you need workarounds like inserting spaces or replacing with HTML tags.
To address this, we replaced pulldown-cmark with a custom version which supports markdown-cjk-friendly, so emphasis can be applied naturally without such workarounds.
References
**がたまに認識されないので緩和用プラグイン作った #JavaScript - Qiita