commonmark-java icon indicating copy to clipboard operation
commonmark-java copied to clipboard

How to avoid delimiter conflict with other nodes?

Open le-tyang opened this issue 10 months ago • 1 comments

Background

We have a custom format for providing extra attributes to a piece of content.

Example format as

^[CONTENT](Attributes go here)

The reason behind using this format is because it is supported out-of-box from iOS which we do understand it is NOT part of commonmark.

After few attempts, we got there, like 90%.

Problem

We found out that when the content is in certain format, the parser takes Link parsing as higher priority and render it as

Image

content as

This is considered as a LINK somehow
 ^[NoAttributes]( 'u': 'underline' ) suffix

I believe this is cause by Link parse runs first?

Help needed

Would like to get some help on this issue to see either we can:

  1. Change priority of parsing
  2. Configure Link parser to ignore ^[]() format.

Any suggestion would be helpful.

Snippet

    class AttributesDelimiterProcessor: DelimiterProcessor {
        override fun getOpeningCharacter(): Char = '^'
        override fun getClosingCharacter(): Char = ')'
        override fun getMinLength(): Int = 1

        override fun process(
            openingRun: DelimiterRun?,
            closingRun: DelimiterRun?
        ): Int {
           // Seems like doesn't matter how you'd process it.
        }
    }

le-tyang avatar Mar 31 '25 14:03 le-tyang

The class that may help LinkProcessor. As mentioned the markdown is being processed before it gets to the DelimiterProcessor.

You may be able to implement a LinkProcessor check the LinkInfo.marker() and see if the marker is a ^, you can then use LinkResult to ignore or move the logic from DelimiterProcessor and wrap or replace the node.

nealhippo avatar Apr 03 '25 19:04 nealhippo

@le-tyang Have you explored @nealhippo's suggestion yet? LinkProcessor should work nicely for your use case. Let us know if you run into a problem with it or are unsure how to use it.

robinst avatar Jun 22 '25 12:06 robinst