diff options
author | Kamil Doległo <kamilok1965@interia.pl> | 2020-08-20 12:18:07 +0200 |
---|---|---|
committer | Sebastian Sellmair <34319766+sellmair@users.noreply.github.com> | 2020-08-20 16:47:11 +0200 |
commit | 96e70c4b1657aa59ddab8276b4b748a3f7df9ca8 (patch) | |
tree | 4fb40d1c8d3bf752264e72c7a0e2a4155128f413 /plugins/base/src/main/kotlin | |
parent | bac8cfd5e94360c79b16ffd0f2f39720c8929eff (diff) | |
download | dokka-96e70c4b1657aa59ddab8276b4b748a3f7df9ca8.tar.gz dokka-96e70c4b1657aa59ddab8276b4b748a3f7df9ca8.tar.bz2 dokka-96e70c4b1657aa59ddab8276b4b748a3f7df9ca8.zip |
Make MarkdownParser output text instead of broken links
Diffstat (limited to 'plugins/base/src/main/kotlin')
-rw-r--r-- | plugins/base/src/main/kotlin/parsers/MarkdownParser.kt | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt b/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt index 05eb71ab..dfb95373 100644 --- a/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt +++ b/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt @@ -1,7 +1,6 @@ package org.jetbrains.dokka.base.parsers import com.intellij.psi.PsiElement -import org.jetbrains.dokka.model.doc.* import org.intellij.markdown.MarkdownElementTypes import org.intellij.markdown.MarkdownTokenTypes import org.intellij.markdown.ast.ASTNode @@ -13,8 +12,10 @@ import org.intellij.markdown.flavours.gfm.GFMFlavourDescriptor import org.intellij.markdown.flavours.gfm.GFMTokenTypes import org.jetbrains.dokka.analysis.DokkaResolutionFacade import org.jetbrains.dokka.analysis.from -import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.base.parsers.factories.DocTagsFromIElementFactory +import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.model.doc.* +import org.jetbrains.dokka.model.doc.Suppress import org.jetbrains.dokka.utilities.DokkaLogger import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor @@ -23,6 +24,7 @@ import org.jetbrains.kotlin.kdoc.parser.KDocKnownTag import org.jetbrains.kotlin.kdoc.psi.impl.KDocSection import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag import java.net.MalformedURLException +import java.net.URL import org.intellij.markdown.parser.MarkdownParser as IntellijMarkdownParser class MarkdownParser( @@ -159,17 +161,37 @@ class MarkdownParser( private fun linksHandler(linkText: ASTNode, link: String, linkTitle: ASTNode? = null): DocTag { val dri: DRI? = resolveDRI(link) + val linkTextString = + if (linkTitle == null) link else text.substring(linkTitle.startOffset + 1, linkTitle.endOffset - 1) + val params = if (linkTitle == null) mapOf("href" to link) else - mapOf("href" to link, "title" to text.substring(linkTitle.startOffset + 1, linkTitle.endOffset - 1)) + mapOf("href" to link, "title" to linkTextString) - return DocTagsFromIElementFactory.getInstance( - MarkdownElementTypes.INLINE_LINK, - params = params, - children = linkText.children.drop(1).dropLast(1).evaluateChildren(), - dri = dri - ) + + return if (dri == null && !link.isRemoteLink()) { + DocTagsFromIElementFactory.getInstance( + MarkdownTokenTypes.TEXT, + params = params, + children = linkText.children.drop(1).dropLast(1).evaluateChildren(), + body = linkTextString.removeSurrounding("[", "]") + ) + } else { + DocTagsFromIElementFactory.getInstance( + MarkdownElementTypes.INLINE_LINK, + params = params, + children = linkText.children.drop(1).dropLast(1).evaluateChildren(), + dri = dri + ) + } + } + + private fun String.isRemoteLink() = try { + URL(this) + true + } catch(e: MalformedURLException){ + false } private fun imagesHandler(node: ASTNode): DocTag { @@ -417,4 +439,4 @@ class MarkdownParser( } ) } -}
\ No newline at end of file +} |