-
Notifications
You must be signed in to change notification settings - Fork 0
fix: CJK約物隣接の bold/em が壊れる問題を修正 #62
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,26 @@ import { marked } from 'marked'; | |
| // なんか増えたらココに追記 | ||
| import code from './md/code.js'; | ||
|
|
||
| // CJK約物()など)の直後にある closing ** が認識されない CommonMark 由来の問題を修正する。 | ||
| // emStrongRDelimAst の group1 lookahead に \p{L} を追加し、 | ||
| // 約物 + ** + 文字(CJK含む)の並びも closing delimiter と見なすようにする。 | ||
| let _cjkFixed = false; | ||
| marked.use({ | ||
| tokenizer: { | ||
| emStrong(src, maskedSrc, prevChar = '') { | ||
| if (!_cjkFixed) { | ||
| const orig = this.rules.inline.emStrongRDelimAst; | ||
| this.rules.inline.emStrongRDelimAst = new RegExp( | ||
| orig.source.replace('(?=[\\s]|$)', '(?=[\\s\\p{L}]|$)'), | ||
| orig.flags | ||
| ); | ||
| _cjkFixed = true; | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
| }); | ||
|
Comment on lines
+10
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Calling |
||
|
|
||
| const renderFunc = { | ||
| code, | ||
| }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This regex modification has two significant issues:
uflag: The use of Unicode property escapes like\p{L}requires theu(unicode) flag to be set on the regular expression. Without this flag,new RegExp()will throw aSyntaxErrorin modern JavaScript environments (Node.js, modern browsers).replacecall, the string literal'[\s]'results in[s]because the backslash is not escaped within the string. To correctly match the literal\sin the regex source, you must use'[\\s]'(double backslash).Additionally, consider if
\p{P}(punctuation) should also be included in the lookahead to fully support CommonMark's flanking rules for CJK punctuation (e.g.,**foo(bar)**。).