CJK characters are stripped from markdown headings
Problem
When parsing markdown files with Chinese, Japanese, or Korean (CJK) headings, all non-ASCII characters are stripped due to the current implementation of sanitizeText() in bin/md-tree.js.
Example:
sanitizeText("标题一") // => ''
This makes it difficult to use non-English markdown documents with this tool, as all CJK headings are reduced to empty or meaningless slugs.
Proposed Fix
Update the regular expression to preserve common CJK character ranges:
- .replace(/[^a-z0-9\s-]/g, '')
+ .replace(/[^a-z0-9\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af\s-]/g, '')
This will allow:
- Chinese characters:
\u4E00–\u9FFF - Hiragana:
\u3040–\u309F - Katakana:
\u30A0–\u30FF - Hangul syllables:
\uAC00–\uD7AF
Benefit
This change improves multilingual compatibility while preserving the intended ASCII-based slug behavior.
Let me know if you're open to this change — I’d be happy to submit a PR if needed.
Thanks for this, @circus1990666 - I'll put in the suggested fix (and add tests).
Fixed in 1.6.0