diff options
author | Andrzej Ratajczak <andrzej.ratajczak98@gmail.com> | 2020-08-24 10:43:10 +0200 |
---|---|---|
committer | Sebastian Sellmair <34319766+sellmair@users.noreply.github.com> | 2020-08-28 15:35:09 +0200 |
commit | e64cb9bfbef093bcc4046a5081393f3c9778b42a (patch) | |
tree | 5b92ffeabcce5ebc1d8c86240ce4a8891bdd8cda | |
parent | 56199ef712c442a960e11ec9a7bff6de4bc4a532 (diff) | |
download | dokka-e64cb9bfbef093bcc4046a5081393f3c9778b42a.tar.gz dokka-e64cb9bfbef093bcc4046a5081393f3c9778b42a.tar.bz2 dokka-e64cb9bfbef093bcc4046a5081393f3c9778b42a.zip |
Fix losing tokens while parsing markdown italic text
-rw-r--r-- | plugins/base/src/main/kotlin/parsers/MarkdownParser.kt | 13 | ||||
-rw-r--r-- | plugins/base/src/test/kotlin/markdown/ParserTest.kt | 48 |
2 files changed, 59 insertions, 2 deletions
diff --git a/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt b/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt index dfb95373..8422d3be 100644 --- a/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt +++ b/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt @@ -48,9 +48,18 @@ class MarkdownParser( private fun emphasisHandler(node: ASTNode): DocTag = DocTagsFromIElementFactory.getInstance( node.type, - children = listOf(visitNode(node.children[node.children.size / 2])) + children = node.children.evaluateChildrenWithDroppedEnclosingTokens(1) ) + private fun strongHandler(node: ASTNode): DocTag = + DocTagsFromIElementFactory.getInstance( + node.type, + children = node.children.evaluateChildrenWithDroppedEnclosingTokens(2) + ) + + private fun List<ASTNode>.evaluateChildrenWithDroppedEnclosingTokens(count: Int) = + drop(count).dropLast(count).evaluateChildren() + private fun blockquotesHandler(node: ASTNode): DocTag = DocTagsFromIElementFactory.getInstance( node.type, children = node.children @@ -256,7 +265,7 @@ class MarkdownParser( MarkdownElementTypes.ATX_5, MarkdownElementTypes.ATX_6 -> headersHandler(node) MarkdownTokenTypes.HORIZONTAL_RULE -> horizontalRulesHandler(node) - MarkdownElementTypes.STRONG, + MarkdownElementTypes.STRONG -> strongHandler(node) MarkdownElementTypes.EMPH -> emphasisHandler(node) MarkdownElementTypes.FULL_REFERENCE_LINK, MarkdownElementTypes.SHORT_REFERENCE_LINK -> referenceLinksHandler(node) diff --git a/plugins/base/src/test/kotlin/markdown/ParserTest.kt b/plugins/base/src/test/kotlin/markdown/ParserTest.kt index ee6170c2..838233eb 100644 --- a/plugins/base/src/test/kotlin/markdown/ParserTest.kt +++ b/plugins/base/src/test/kotlin/markdown/ParserTest.kt @@ -167,6 +167,54 @@ class ParserTest : KDocTest() { } @Test + fun `Stars as italic bounds`() { + val kdoc = "The abstract syntax tree node for a multiplying expression. A multiplying\n" + + "expression is a binary expression where the operator is a multiplying operator\n" + + "such as \"*\", \"/\", or \"mod\". A simple example would be \"5*x\"." + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P( + listOf( + Text("The abstract syntax tree node for a multiplying expression. A multiplying " + + "expression is a binary expression where the operator is a multiplying operator " + + "such as \"" + ), + I(listOf(Text("\", \"/\", or \"mod\". A simple example would be \"5"))), + Text("x\".") + ) + ) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test + fun `Stars as bold bounds`() { + val kdoc = "The abstract syntax tree node for a multiplying expression. A multiplying\n" + + "expression is a binary expression where the operator is a multiplying operator\n" + + "such as \"**\", \"/\", or \"mod\". A simple example would be \"5**x\"." + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P( + listOf( + Text("The abstract syntax tree node for a multiplying expression. A multiplying " + + "expression is a binary expression where the operator is a multiplying operator " + + "such as \"" + ), + B(listOf(Text("\", \"/\", or \"mod\". A simple example would be \"5"))), + Text("x\".") + ) + ) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Embedded star`() { val kdoc = "Embedded*Star" val expectedDocumentationNode = DocumentationNode( |