diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/kotlin/Kotlin/ContentBuilder.kt | 28 | ||||
-rw-r--r-- | core/src/test/kotlin/format/HtmlFormatTest.kt | 13 | ||||
-rw-r--r-- | core/testdata/format/markdownInLinks.html | 15 | ||||
-rw-r--r-- | core/testdata/format/markdownInLinks.kt | 4 |
4 files changed, 51 insertions, 9 deletions
diff --git a/core/src/main/kotlin/Kotlin/ContentBuilder.kt b/core/src/main/kotlin/Kotlin/ContentBuilder.kt index 496c886b..9e89a20a 100644 --- a/core/src/main/kotlin/Kotlin/ContentBuilder.kt +++ b/core/src/main/kotlin/Kotlin/ContentBuilder.kt @@ -48,16 +48,16 @@ fun buildContentTo(tree: MarkdownNode, target: ContentBlock, linkResolver: (Stri MarkdownElementTypes.PARAGRAPH -> appendNodeWithChildren(ContentParagraph()) MarkdownElementTypes.INLINE_LINK -> { - val labelText = node.child(MarkdownElementTypes.LINK_TEXT)?.getLabelText() + val linkTextNode = node.child(MarkdownElementTypes.LINK_TEXT) val destination = node.child(MarkdownElementTypes.LINK_DESTINATION) - if (labelText != null) { + if (linkTextNode != null) { if (destination != null) { val link = ContentExternalLink(destination.text) - link.append(ContentText(labelText)) + renderLinkTextTo(linkTextNode, link, linkResolver) parent.append(link) } else { - val link = ContentExternalLink(labelText) - link.append(ContentText(labelText)) + val link = ContentExternalLink(linkTextNode.getLabelText()) + renderLinkTextTo(linkTextNode, link, linkResolver) parent.append(link) } } @@ -67,8 +67,13 @@ fun buildContentTo(tree: MarkdownNode, target: ContentBlock, linkResolver: (Stri val labelText = node.child(MarkdownElementTypes.LINK_LABEL)?.getLabelText() if (labelText != null) { val link = linkResolver(labelText) - val linkText = node.child(MarkdownElementTypes.LINK_TEXT)?.getLabelText() - link.append(ContentText(linkText ?: labelText)) + val linkText = node.child(MarkdownElementTypes.LINK_TEXT) + if (linkText != null) { + renderLinkTextTo(linkText, link, linkResolver) + } + else { + link.append(ContentText(labelText)) + } parent.append(link) } } @@ -104,7 +109,8 @@ fun buildContentTo(tree: MarkdownNode, target: ContentBlock, linkResolver: (Stri } MarkdownTokenTypes.EMPH -> { - if (node.parent?.type != MarkdownElementTypes.EMPH) { + val parentNodeType = node.parent?.type + if (parentNodeType != MarkdownElementTypes.EMPH && parentNodeType != MarkdownElementTypes.STRONG) { parent.append(ContentText(node.text)) } } @@ -138,3 +144,9 @@ fun buildInlineContentTo(tree: MarkdownNode, target: ContentBlock, linkResolver: } } +fun renderLinkTextTo(tree: MarkdownNode, target: ContentBlock, linkResolver: (String) -> ContentBlock) { + val linkTextNodes = tree.children.drop(1).dropLast(1) + linkTextNodes.forEach { + buildContentTo(it, target, linkResolver) + } +} diff --git a/core/src/test/kotlin/format/HtmlFormatTest.kt b/core/src/test/kotlin/format/HtmlFormatTest.kt index 8045d38c..0fc56361 100644 --- a/core/src/test/kotlin/format/HtmlFormatTest.kt +++ b/core/src/test/kotlin/format/HtmlFormatTest.kt @@ -8,7 +8,7 @@ import org.jetbrains.kotlin.config.KotlinSourceRoot import org.junit.Test import java.io.File -public class HtmlFormatTest { +class HtmlFormatTest { private val htmlService = HtmlFormatService(InMemoryLocationService, KotlinLanguageService(), HtmlTemplateService.default()) @Test fun classWithCompanionObject() { @@ -159,5 +159,16 @@ public class HtmlFormatTest { htmlService.appendNodes(tempLocation, output, model.members.single().members) } } + + @Test fun markdownInLinks() { + verifyHtmlNode("markdownInLinks") + } + + private fun verifyHtmlNode(fileName: String, withKotlinRuntime: Boolean = false) { + verifyOutput("testdata/format/$fileName.kt", ".html", withKotlinRuntime = withKotlinRuntime) { model, output -> + htmlService.appendNodes(tempLocation, output, model.members.single().members) + } + } + } diff --git a/core/testdata/format/markdownInLinks.html b/core/testdata/format/markdownInLinks.html new file mode 100644 index 00000000..38158eac --- /dev/null +++ b/core/testdata/format/markdownInLinks.html @@ -0,0 +1,15 @@ +<HTML> +<HEAD> +<title>foo - test</title> +</HEAD> +<BODY> +<a href="test/index">test</a> / <a href="test/foo">foo</a><br/> +<br/> +<h1>foo</h1> +<a name="$foo()"></a> +<code><span class="keyword">fun </span><span class="identifier">foo</span><span class="symbol">(</span><span class="symbol">)</span><span class="symbol">: </span><span class="identifier">Unit</span></code><br/> +<p><a href="http://www.ibm.com">a<strong>b</strong><strong>d</strong>kas</a></p> +<br/> +<br/> +</BODY> +</HTML> diff --git a/core/testdata/format/markdownInLinks.kt b/core/testdata/format/markdownInLinks.kt new file mode 100644 index 00000000..67b6311f --- /dev/null +++ b/core/testdata/format/markdownInLinks.kt @@ -0,0 +1,4 @@ +/** + * [a**b**__d__ kas ](http://www.ibm.com) + */ +fun foo() {} |