vsch / flexmark-java

CommonMark/Markdown Java parser with source level AST. CommonMark 0.28, emulation of: pegdown, kramdown, markdown.pl, MultiMarkdown. With HTML to MD, MD to PDF, MD to DOCX conversion modules.
BSD 2-Clause "Simplified" License
2.29k stars 272 forks source link

For emphasis, using asterisks to bold and italicize the middle of a word doesn't work. #557

Open arjun2 opened 1 year ago

arjun2 commented 1 year ago

For emphasis, using asterisks to bold and italicize the middle of a word doesn't work.

Example: Input: "This is really***very***important text."

Expected: <p>This is really<em><strong>very</strong></em>important text.</p>

Actual: <p>This is really***very***important text.</p>

arjun2 commented 1 year ago

Can I please get some help on this ? I was looking at options on Parser but don't see any thing that can help. Note that it works with https://github.com/commonmark/commonmark-java

david-waltermire commented 1 year ago

@arjun2 I am seeing the same. This is example 415 from the CommonMark specification.

A parser creates the following AST:

Document[0, 16]
  Paragraph[0, 16]
    Text[0, 15] chars:[0, 15, "foo** … **baz"]

Notice the missing StrongEmphasis and Emphasis nodes.

This seems like a bug in Flexmark.

david-waltermire commented 1 year ago

Tracing this, I believe the problem relates to the code at:

https://github.com/vsch/flexmark-java/blame/cc3a2f59ba6e532833f4805f8134b4dc966ff837/flexmark/src/main/java/com/vladsch/flexmark/parser/internal/InlineParserImpl.java#L1418

It looks like the loop here is rewinding the stack to find the outer most opener and closer. Then processing the result.

This code is a bit complex, so I am not fully sure what is happening, but this seems to result in the delimiters getting ignored.

david-waltermire commented 1 year ago

@vsch Is there a possibility of prioritizing a fix? I am not sure I am able to fully debug this to create a PR or I would.

david-waltermire commented 1 year ago

@vsch Is there a possibility of prioritizing a fix? I am not sure I am able to fully debug this to create a PR or I would.

I was able to create a PR after all. Let me know if this works or needs adjustments.