aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main
diff options
context:
space:
mode:
authorMarcin Aman <marcin.aman@gmail.com>2021-03-01 11:57:59 +0100
committerGitHub <noreply@github.com>2021-03-01 11:57:59 +0100
commit32fc2899cbe08e4e30326128e0f642ac4e08a342 (patch)
tree66bbd6784f9d2f3dac7b7467f5b5d9aec2dd5f3a /plugins/base/src/main
parentc01e49eec9558736959d12820361624a3c3e41e5 (diff)
downloaddokka-32fc2899cbe08e4e30326128e0f642ac4e08a342.tar.gz
dokka-32fc2899cbe08e4e30326128e0f642ac4e08a342.tar.bz2
dokka-32fc2899cbe08e4e30326128e0f642ac4e08a342.zip
Bump markdown to 0.2.0 and fix negation in links being interpreted as img (#1754)
* Bump markdown library to 0.2.0 * Render shorthand images as link with text
Diffstat (limited to 'plugins/base/src/main')
-rw-r--r--plugins/base/src/main/kotlin/parsers/MarkdownParser.kt18
1 files changed, 16 insertions, 2 deletions
diff --git a/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt b/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt
index a27734cc..9a4aa39f 100644
--- a/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt
+++ b/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt
@@ -1,6 +1,7 @@
package org.jetbrains.dokka.base.parsers
import com.intellij.psi.PsiElement
+import org.intellij.markdown.MarkdownElementType
import org.intellij.markdown.MarkdownElementTypes
import org.intellij.markdown.MarkdownTokenTypes
import org.intellij.markdown.ast.ASTNode
@@ -370,7 +371,19 @@ open class MarkdownParser(
this.filterNot { it.type == GFMTokenTypes.TABLE_SEPARATOR }
private fun List<ASTNode>.evaluateChildren(): List<DocTag> =
- this.removeUselessTokens().mergeLeafASTNodes().map { visitNode(it) }
+ this.removeUselessTokens().swapImagesThatShouldBeLinks().mergeLeafASTNodes().map { visitNode(it) }
+
+ private fun List<ASTNode>.swapImagesThatShouldBeLinks(): List<ASTNode> =
+ flatMap { node ->
+ if (node.type == MarkdownElementTypes.IMAGE
+ && node.children.firstOrNull()?.let { it is LeafASTNode && it.type.name == "!" } == true
+ && node.children.lastOrNull()?.type == MarkdownElementTypes.SHORT_REFERENCE_LINK
+ ) {
+ node.children
+ } else {
+ listOf(node)
+ }
+ }
private fun List<ASTNode>.removeUselessTokens(): List<ASTNode> =
this.filterIndexed { index, node ->
@@ -452,7 +465,8 @@ open class MarkdownParser(
if (link is DocumentationLink) link.dri else null
}
- val allTags = listOf(kDocTag) + if(kDocTag.canHaveParent()) getAllKDocTags(findParent(kDocTag)) else emptyList()
+ val allTags =
+ listOf(kDocTag) + if (kDocTag.canHaveParent()) getAllKDocTags(findParent(kDocTag)) else emptyList()
DocumentationNode(
allTags.map {
when (it.knownTag) {