diff options
author | Marcin Aman <marcin.aman@gmail.com> | 2021-07-12 09:58:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-12 09:58:38 +0200 |
commit | cc6b2991df60f43607c8271d9657be89b3463a69 (patch) | |
tree | c705aa2808224a6b80de270ac65d61936e93f253 /plugins/base/src/main/kotlin/parsers/factories | |
parent | 4548d1d929950c794b81cdad648bd2e0fd13a4e1 (diff) | |
download | dokka-cc6b2991df60f43607c8271d9657be89b3463a69.tar.gz dokka-cc6b2991df60f43607c8271d9657be89b3463a69.tar.bz2 dokka-cc6b2991df60f43607c8271d9657be89b3463a69.zip |
Handle NBSP and other html entries (#2005)
Diffstat (limited to 'plugins/base/src/main/kotlin/parsers/factories')
-rw-r--r-- | plugins/base/src/main/kotlin/parsers/factories/DocTagsFromIElementFactory.kt | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/plugins/base/src/main/kotlin/parsers/factories/DocTagsFromIElementFactory.kt b/plugins/base/src/main/kotlin/parsers/factories/DocTagsFromIElementFactory.kt index 9ee11732..a3cbcc2e 100644 --- a/plugins/base/src/main/kotlin/parsers/factories/DocTagsFromIElementFactory.kt +++ b/plugins/base/src/main/kotlin/parsers/factories/DocTagsFromIElementFactory.kt @@ -6,12 +6,15 @@ import org.intellij.markdown.MarkdownElementTypes import org.intellij.markdown.MarkdownTokenTypes import org.intellij.markdown.flavours.gfm.GFMElementTypes import org.intellij.markdown.flavours.gfm.GFMTokenTypes +import org.jetbrains.dokka.base.translators.parseWithNormalisedSpaces import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.doc.DocTag.Companion.contentTypeParam import java.lang.NullPointerException object DocTagsFromIElementFactory { - fun getInstance(type: IElementType, children: List<DocTag> = emptyList(), params: Map<String, String> = emptyMap(), body: String? = null, dri: DRI? = null) = + + @Suppress("IMPLICIT_CAST_TO_ANY") + fun getInstance(type: IElementType, children: List<DocTag> = emptyList(), params: Map<String, String> = emptyMap(), body: String? = null, dri: DRI? = null, keepFormatting: Boolean = false) = when(type) { MarkdownElementTypes.SHORT_REFERENCE_LINK, MarkdownElementTypes.FULL_REFERENCE_LINK, @@ -33,7 +36,11 @@ object DocTagsFromIElementFactory { MarkdownElementTypes.ORDERED_LIST -> Ol(children, params) MarkdownElementTypes.UNORDERED_LIST -> Ul(children, params) MarkdownElementTypes.PARAGRAPH -> P(children, params) - MarkdownTokenTypes.TEXT -> Text(body ?: throw NullPointerException("Text body should be at least empty string passed to DocNodes factory!"), children, params ) + MarkdownTokenTypes.TEXT -> if (keepFormatting) Text( + body.orEmpty(), + children, + params + ) else body?.parseWithNormalisedSpaces(renderWhiteCharactersAsSpaces = false).orEmpty() MarkdownTokenTypes.HORIZONTAL_RULE -> HorizontalRule MarkdownTokenTypes.HARD_LINE_BREAK -> Br GFMElementTypes.STRIKETHROUGH -> Strikethrough(children, params) @@ -46,5 +53,10 @@ object DocTagsFromIElementFactory { MarkdownTokenTypes.HTML_TAG, MarkdownTokenTypes.HTML_BLOCK_CONTENT -> Text(body.orEmpty(), params = params + contentTypeParam("html")) else -> CustomDocTag(children, params, type.name) + }.let { + when (it) { + is List<*> -> it as List<DocTag> + else -> listOf(it as DocTag) + } } } |