-
Notifications
You must be signed in to change notification settings - Fork 413
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
Update org.jetbrains.markdown from 0.3.1 to 0.5.2 #3231
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,28 @@ public open class MarkdownParser( | |
).flatMap { it.children } | ||
) | ||
|
||
/** | ||
* Handler for [MarkdownTokenTypes.ATX_CONTENT], which is the content of the header | ||
* elements like [MarkdownElementTypes.ATX_1], [MarkdownElementTypes.ATX_2] and so on. | ||
* | ||
* For example, a header line like `# Header text` is expected to be parsed into: | ||
* - One [MarkdownTokenTypes.ATX_HEADER] with startOffset = 0, endOffset = 1 (only the `#` symbol) | ||
* - Composite [MarkdownTokenTypes.ATX_CONTENT] with four children: WHITE_SPACE, TEXT, WHITE_SPACE, TEXT. | ||
*/ | ||
private fun headerContentHandler(node: ASTNode): List<DocTag> { | ||
// ATX_CONTENT contains everything after the `#` symbol, so if there's a space | ||
// in-between the `#` symbol and the text (like `# header`), it will be present here too. | ||
// However, we don't need the first space between the `#` symbol and the text, | ||
// so we just skip it (otherwise the header text will be parsed as `<whitespace>header` instead of `header`). | ||
val textStartsWithWhitespace = node.children.firstOrNull()?.type == MarkdownTokenTypes.WHITE_SPACE | ||
val children = if (textStartsWithWhitespace) node.children.subList(1, node.children.size) else node.children | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some tests started failing because they expected Quick debugging showed that before the update
After the update,
Maybe there's a nicer or a better way to fix it - I honestly didn't spend much time on it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just interesting, how it worked before/after if there are multiple spaces in the beginning? f.e. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Excellent thought, I'll check 👍 From what I've seen, my guess would be that there will still be a single There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like it's how I expected - there's only one I've added a test and a comment about it though. Also created #3233 after seeing a single test file with 1.6k lines of code 😅 |
||
|
||
return DocTagsFromIElementFactory.getInstance( | ||
MarkdownElementTypes.PARAGRAPH, // PARAGRAPH instead of TEXT to preserve compatibility with prev. versions | ||
children = children.evaluateChildren() | ||
) | ||
} | ||
|
||
private fun horizontalRulesHandler() = | ||
DocTagsFromIElementFactory.getInstance(MarkdownTokenTypes.HORIZONTAL_RULE) | ||
|
||
|
@@ -365,6 +387,7 @@ public open class MarkdownParser( | |
MarkdownElementTypes.ATX_5, | ||
MarkdownElementTypes.ATX_6, | ||
-> headersHandler(node) | ||
MarkdownTokenTypes.ATX_CONTENT -> headerContentHandler(node) | ||
MarkdownTokenTypes.HORIZONTAL_RULE -> horizontalRulesHandler() | ||
MarkdownElementTypes.STRONG -> strongHandler(node) | ||
MarkdownElementTypes.EMPH -> emphasisHandler(node) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should trim not only the beginning.
See https://spec.commonmark.org/0.30/#atx-headings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good thought, fixed