Option to define custom flanking/canOpen/canClose rules for delimiters
@abhiramaab is already working on this.
Since Aug 12, 2026.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
Research direction
Start with InlineParserImpl and trace how delimiter runs become DelimiterData and how processDelimiters invokes DelimitedProcessor.process(). Review the inlineParserFactory path and determine where custom canOpen/canClose or flanking behavior could be exposed without copying InlineParserImpl. Done means a consumer can define custom delimiter rules and the requested loose bold and italic syntax is parsed accordingly.
Written by the indexing model from the issue text.
Description
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
- Dominant language
- Java
- Stars
- 2.7k
- Forks
- 336
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from commonmark/commonmark-java
-
Unclosed link reference definition title keeps the partial title and the following paragraph's source spans (0.30.0)Possibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
commonmark/commonmark-java#460 ·
-
Second code span not recognised after an unclosed backtick string and another code spanPossibly taken @TanbirRamim claimed this 15 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 68/100
commonmark/commonmark-java#458 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 74/100
commonmark/commonmark-java#457 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
commonmark/commonmark-java#443 · 4 comments ·
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 25/100
commonmark/commonmark-java#414 · 1 comment · 1 reaction ·
All issues in commonmark/commonmark-java
Similar issues
-
[BUG] 订单:会员凭订单号即可取消其他会员的待付款订单(取消接口不校验订单归属)Possibly taken @dadiyang claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
macrozheng/mall#1016 ·
-
[Bug] The producer summary counts an unreported client version as a second version and warns about a version mixPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
apache/rocketmq-dashboard#6110 ·
Maintainers usually reply within 4 days
-
Feature:Resolution
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
intellij-elixir/intellij-elixir#4396 ·
Maintainers usually reply within 1 day
-
Python 3.15 supportPossibly taken @amnesiaof claimed this today. OpenL: python L: python:uv
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
dependabot/dependabot-core#16524 · 1 comment ·
Maintainers usually reply within 1 day
-
`Processing lsp` never exits and leaves orphaned processesPossibly taken @overcast302 claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
processing/processing4#1578 · 1 comment ·