Option to define custom flanking/canOpen/canClose rules for delimiters
@abhiramaab 已經在處理了。
開始於 2026年8月12日。
評估
研究方向
從 InlineParserImpl 開始,追蹤 delimiter runs 如何變成 DelimiterData,以及 processDelimiters 如何呼叫 DelimitedProcessor.process()。檢查 inlineParserFactory 路徑,並確定在不複製 InlineParserImpl 的情況下,可以在哪裡公開自訂的 canOpen/canClose 或 flanking 行為。完成的標準是,consumer 可以定義自訂 delimiter 規則,並且能夠依要求解析 loose 粗體和斜體語法。
由索引模型根據 Issue 內容生成。
描述
Is your feature request related to a problem? Please describe.
The markdown spec that I'm trying to parse has loose rules when it comes to bold and italic delimiters, i.e. *italic * is vaild syntax. These seem to be the rules:
_- same behaviour as default__(as opener) - must have a space/punctuation on the left, but what's on the right doesn't matter__(as closer),*,**- no rules (can be surrounded by anything, can have spaces on either side, and still work)
However, Commonmark-java follows the default markdown spec which is strict and has certain flanking rules. Currently these rules seem to be hardcoded in InlineParserImpl:
boolean beforeIsPunctuation = before == Scanner.END || Characters.isPunctuationCodePoint(before);
boolean beforeIsWhitespace = before == Scanner.END || Characters.isWhitespaceCodePoint(before);
boolean afterIsPunctuation = after == Scanner.END || Characters.isPunctuationCodePoint(after);
boolean afterIsWhitespace = after == Scanner.END || Characters.isWhitespaceCodePoint(after);
boolean leftFlanking = !afterIsWhitespace &&
(!afterIsPunctuation || beforeIsWhitespace || beforeIsPunctuation);
boolean rightFlanking = !beforeIsWhitespace &&
(!beforeIsPunctuation || afterIsWhitespace || afterIsPunctuation);
boolean canOpen;
boolean canClose;
if (delimiterChar == '_') {
canOpen = leftFlanking && (!rightFlanking || beforeIsPunctuation);
canClose = rightFlanking && (!leftFlanking || afterIsPunctuation);
} else {
canOpen = leftFlanking && delimiterChar == delimiterProcessor.getOpeningCharacter();
canClose = rightFlanking && delimiterChar == delimiterProcessor.getClosingCharacter();
}
return new DelimiterData(delimiters, canOpen, canClose);
As far as I understand this cannot be solved with custom DelimitedProcessors, for DelimitedProcessor.process() to be called, canOpen() (which is calculated in the code snippet above) must be true in processDelimiters(Delimiter):
...
if (opener.canOpen() && opener.delimiterChar == openingDelimiterChar) {
potentialOpenerFound = true;
usedDelims = delimiterProcessor.process(opener, closer);
...
So in other words I couldn't find an easy way to change this behaviour.
Describe the solution you'd like
I would like for it to be possible to somehow define custom flanking rules for certain delimiter runs. Maybe the part in InlineParserImpl responsible for calculating canOpen/canClose and constructing DelimiterData could be lifted into an interface of some kind, or a public method in InlineParserImpl so that it can be inherited from and the method overriden.
Describe alternatives you've considered
Copying InlineParserImpl over to my project and changing the relevant lines, then using it via inlineParserFactory when building a Parser
- 主要語言
- Java
- 星號
- 2.7k
- 分支
- 336
- PR 合併指標
- 30 天內沒有已合併 PR
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
commonmark/commonmark-java 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 70/100
commonmark/commonmark-java#460 ·
-
Second code span not recognised after an unclosed backtick string and another code span可能已有人在做 @TanbirRamim 於 13 天前認領。 未關閉
難度 3/5 1-2 天 新手友好度 68/100
commonmark/commonmark-java#458 ·
-
難度 4/5 3-5 天 新手友好度 74/100
commonmark/commonmark-java#457 ·
-
難度 3/5 1-2 天 新手友好度 48/100
commonmark/commonmark-java#443 · 4 則留言 ·
-
enhancement
難度 5/5 一週以上 新手友好度 25/100
commonmark/commonmark-java#414 · 1 則留言 · 1 個 reaction ·
查看 commonmark/commonmark-java 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 64/100
-
C21 publishes `reactivemongo/core/SSL` as Java 23 bytecode — TLS connections fail on any JDK < 23未關閉
難度 2/5 1-3 小時 新手友好度 74/100
ReactiveMongo/ReactiveMongo#1520 ·
維護者通常 1 天內回覆
-
enhancement
難度 2/5 1-3 小時 新手友好度 65/100
liquid-java/liquidjava#373 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 70/100
ga4gh/phenopacket-schema#465 ·
-
難度 2/5 1-3 小時 新手友好度 72/100
NationalSecurityAgency/ghidra#9748 ·
維護者通常 1 天內回覆