JetBrains / markdown

Markdown parser written in kotlin
Apache License 2.0
682 stars 75 forks source link

Extra whitespace for headers with level 2..6 #116

Closed SerVB closed 1 year ago

SerVB commented 1 year ago

Works OK for headers of level 1.

I've tried debugging it and noticed that it starts to differ here: InlineBuilder.kt-addRawTokens#L66. exitOffset is passed always as +1, but iterator.rawStart(rawIdx + dx) != exitOffset when the header level is bigger than 1. I'm not sure how to to fix it so reporting.

To reproduce:

MarkdownParser(CommonMarkFlavourDescriptor()).buildMarkdownTreeFromString("# HEader TXT")
// gives correct tree, without whitespace:
// MARKDOWN_FILE
// * ATX_1
// ** ATX_HEADER
// ** ATX_CONTENT
// *** TEXT
// two or more hash symbols:
MarkdownParser(CommonMarkFlavourDescriptor()).buildMarkdownTreeFromString("## HEader TXT")
// gives incorrect tree, with redundant whitespace:
// MARKDOWN_FILE
// * ATX_2
// ** ATX_HEADER
// ** ATX_CONTENT
// *** WHITE_SPACE  // <== here
// *** TEXT

Expected: the second tree is the same as the first one: without whitespaces.

Checked on 0.3.1 and 0.3.6.

SerVB commented 1 year ago

Looks resolved in 0.4.0. Now the behavior is the same across different header levels. A redundant whitespace can be removed from the user-side in the same way.