Skip to content
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

java.lang.IllegalArgumentException: Cannot add two delimiter processors for char '~' and minimum length 1 #271

Closed
lpellegr opened this issue Oct 21, 2022 · 5 comments
Labels

Comments

@lpellegr
Copy link

lpellegr commented Oct 21, 2022

Using version 0.20.0 of commonmark-java with strikethrough extension leads to this exception at runtime:

Caused by: java.lang.IllegalArgumentException: Cannot add two delimiter processors for char '~' and minimum length 1
at org.commonmark.internal.StaggeredDelimiterProcessor.add(StaggeredDelimiterProcessor.java:54) ~[commonmark-0.20.0.jar:na]
at org.commonmark.internal.InlineParserImpl.addDelimiterProcessors(InlineParserImpl.java:92) ~[commonmark-0.20.0.jar:na]
at org.commonmark.internal.InlineParserImpl.calculateDelimiterProcessors(InlineParserImpl.java:69) ~[commonmark-0.20.0.jar:na]
at org.commonmark.internal.InlineParserImpl.(InlineParserImpl.java:39) ~[commonmark-0.20.0.jar:na]
at org.commonmark.parser.Parser$Builder$1.create(Parser.java:272) ~[commonmark-0.20.0.jar:na]
at org.commonmark.parser.Parser.(Parser.java:45) ~[commonmark-0.20.0.jar:na]
at org.commonmark.parser.Parser.(Parser.java:28) ~[commonmark-0.20.0.jar:na]
at org.commonmark.parser.Parser$Builder.build(Parser.java:128) ~[commonmark-0.20.0.jar:na]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na]
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) ~[na:na]
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480) ~[na:na]
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:211) ~[spring-beans-5.3.23.jar:5.3.23]
... 47 common frames omitted

Gradle dependencies used are:

implementation 'org.commonmark:commonmark:0.20.0'
implementation 'org.commonmark:commonmark-ext-autolink:0.20.0'
implementation 'org.commonmark:commonmark-ext-gfm-tables:0.20.0'
implementation 'org.commonmark:commonmark-ext-gfm-strikethrough:0.20.0'
implementation 'org.commonmark:commonmark-ext-heading-anchor:0.20.0'
implementation 'org.commonmark:commonmark-ext-image-attributes:0.20.0'

The renderer is initialized as follows:

final List<Extension> extensions =
    Arrays.asList(
        AutolinkExtension.create(),
        HeadingAnchorExtension.create(),
        ImageAttributesExtension.create(),
        UnderlineExtension.create(),
        StrikethroughExtension.create(),
        SubscriptExtension.create(),
        SupscriptExtension.create(),
        TablesExtension.create());

this.markdownParser =
    Parser.builder().extensions(extensions).build();
this.markdownHtmlRenderer =
    HtmlRenderer.builder()
        .escapeHtml(true)
        .extensions(extensions)
        .nodeRendererFactory(VideoEmbedNodeRenderer::new)
        .sanitizeUrls(true)
        .build();
this.markdownPlaintextRenderer = TextContentRenderer.builder().extensions(extensions).stripNewlines(true).build();

Removing StrikethroughExtension.create() from the list of extensions or downgrading to version 0.19.0 fixes the issue.

@lpellegr lpellegr added the bug label Oct 21, 2022
@robinst
Copy link
Collaborator

robinst commented Oct 22, 2022

Oh no. What's the input markdown? Just the section with tildes (~) should be enough.

@lpellegr
Copy link
Author

lpellegr commented Oct 22, 2022

It seems the issue is at runtime when the parser/renderer initializes. No need to invoke it.

@robinst
Copy link
Collaborator

robinst commented Oct 22, 2022

Right, sorry (I hadn't looked at the stack trace because I was on mobile).

So I guess another extension also registers a delimiter processor for ~, probably the subscript one?

So in 0.20.0 we adjusted the strikethrough extension to also handle single tildes, same as GitHub. So that is now a genuine conflict of syntaxes.

For that case we should probably add an option to configure the strikethrough extension to require double tildes, so that there's no conflict. What do you think?

@lpellegr
Copy link
Author

Thanks for your answer. I confirm the issue is caused by the conflict with the SubscriptExtension which shares the same delimiter.

For that case we should probably add an option to configure the strikethrough extension to require double tildes, so that there's no conflict. What do you think?

This would be really appreciated!

@robinst
Copy link
Collaborator

robinst commented Oct 24, 2022

Prepared a fix in #272

It also improves the documentation and the error message mentions which delimiter processors conflict, which would have helped too for this.

robinst added a commit that referenced this issue Oct 27, 2022
…ildes

Add `requireTwoTildes` for `StrikethroughExtension` (fixes #271)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants