From 8c5415b41d3702378d493c18bd63d334fcd53bd2 Mon Sep 17 00:00:00 2001 From: IgnatBeresnev Date: Wed, 18 Oct 2023 00:08:41 +0200 Subject: [PATCH] Update org.jetbrains.markdown from 0.3.1 to 0.5.2 --- gradle/libs.versions.toml | 2 +- .../analysis/markdown/jb/MarkdownParser.kt | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 0060b6519c..032d040e3e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -26,7 +26,7 @@ korlibs-template = "4.0.10" kotlinx-html = "0.9.1" ## Markdown -jetbrains-markdown = "0.3.1" +jetbrains-markdown = "0.5.2" ## JSON jackson = "2.12.7" # jackson 2.13.X does not support kotlin language version 1.4, check before updating diff --git a/subprojects/analysis-markdown-jb/src/main/kotlin/org/jetbrains/dokka/analysis/markdown/jb/MarkdownParser.kt b/subprojects/analysis-markdown-jb/src/main/kotlin/org/jetbrains/dokka/analysis/markdown/jb/MarkdownParser.kt index 256c7b9870..cb050c8537 100644 --- a/subprojects/analysis-markdown-jb/src/main/kotlin/org/jetbrains/dokka/analysis/markdown/jb/MarkdownParser.kt +++ b/subprojects/analysis-markdown-jb/src/main/kotlin/org/jetbrains/dokka/analysis/markdown/jb/MarkdownParser.kt @@ -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 { + // 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 `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 + + 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)