diff options
-rw-r--r-- | src/Java/JavaDocumentationBuilder.kt | 3 | ||||
-rw-r--r-- | src/Kotlin/ContentBuilder.kt | 6 | ||||
-rw-r--r-- | test/data/format/javaLinkTagWithLabel.html | 25 | ||||
-rw-r--r-- | test/data/format/javaLinkTagWithLabel.java | 8 | ||||
-rw-r--r-- | test/data/format/linkWithLabel.html | 37 | ||||
-rw-r--r-- | test/data/format/linkWithLabel.kt | 6 | ||||
-rw-r--r-- | test/src/format/HtmlFormatTest.kt | 12 |
7 files changed, 94 insertions, 3 deletions
diff --git a/src/Java/JavaDocumentationBuilder.kt b/src/Java/JavaDocumentationBuilder.kt index c2a15a45..00a7f3ac 100644 --- a/src/Java/JavaDocumentationBuilder.kt +++ b/src/Java/JavaDocumentationBuilder.kt @@ -126,7 +126,8 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions, val valueElement = tag.linkElement() val linkSignature = resolveLink(valueElement) if (linkSignature != null) { - val link = "<a docref=\"$linkSignature\">${valueElement!!.getText().htmlEscape()}</a>" + val labelText = tag.getDataElements().firstOrNull { it is PsiDocToken }?.getText() ?: valueElement!!.getText() + val link = "<a docref=\"$linkSignature\">${labelText.htmlEscape()}</a>" if (tag.getName() == "link") "<code>$link</code>" else link } else if (valueElement != null) { diff --git a/src/Kotlin/ContentBuilder.kt b/src/Kotlin/ContentBuilder.kt index 4081dc6e..0aa80df0 100644 --- a/src/Kotlin/ContentBuilder.kt +++ b/src/Kotlin/ContentBuilder.kt @@ -74,11 +74,13 @@ public fun buildContentTo(tree: MarkdownNode, target: ContentBlock, linkResolver } } } - MarkdownElementTypes.SHORT_REFERENCE_LINK -> { + MarkdownElementTypes.SHORT_REFERENCE_LINK, + MarkdownElementTypes.FULL_REFERENCE_LINK -> { val label = node.child(MarkdownElementTypes.LINK_LABEL)?.child(MarkdownTokenTypes.TEXT) if (label != null) { val link = linkResolver(label.text) - link.append(ContentText(label.text)) + val linkText = node.child(MarkdownElementTypes.LINK_TEXT)?.child(MarkdownTokenTypes.TEXT) + link.append(ContentText(linkText?.text ?: label.text)) parent.append(link) } } diff --git a/test/data/format/javaLinkTagWithLabel.html b/test/data/format/javaLinkTagWithLabel.html new file mode 100644 index 00000000..ccf3c712 --- /dev/null +++ b/test/data/format/javaLinkTagWithLabel.html @@ -0,0 +1,25 @@ +<HTML> +<HEAD> +<title>test / test.Foo</title> +</HEAD> +<BODY> +<a href="test/index">test</a> / <a href="test/test/index">test</a> / <a href="test/test/-foo/index">Foo</a><br/> +<br/> +<h1>Foo</h1> +<code><span class="keyword">open</span> <span class="keyword">class </span><span class="identifier">Foo</span></code><br/> +<p>Call <code><a href="test/test/-foo/bar">this wonderful method</a></code> to do the job. </p> +<br/> +<br/> +<h3>Functions</h3> +<table> +<tbody> +<tr> +<td> +<a href="test/test/-foo/bar">bar</a></td> +<td> +<code><span class="keyword">open</span> <span class="keyword">fun </span><span class="identifier">bar</span><span class="symbol">(</span><span class="symbol">)</span><span class="symbol">: </span><span class="identifier">Unit</span></code></td> +</tr> +</tbody> +</table> +</BODY> +</HTML> diff --git a/test/data/format/javaLinkTagWithLabel.java b/test/data/format/javaLinkTagWithLabel.java new file mode 100644 index 00000000..7226f1c9 --- /dev/null +++ b/test/data/format/javaLinkTagWithLabel.java @@ -0,0 +1,8 @@ +package test; + +/** + * Call {@link #bar() this wonderful method} to do the job. + */ +class Foo { + public void bar() +} diff --git a/test/data/format/linkWithLabel.html b/test/data/format/linkWithLabel.html new file mode 100644 index 00000000..75769ffd --- /dev/null +++ b/test/data/format/linkWithLabel.html @@ -0,0 +1,37 @@ +<HTML> +<HEAD> +<title>test / Bar</title> +</HEAD> +<BODY> +<a href="test/index">test</a> / <a href="test/-bar/index">Bar</a><br/> +<br/> +<h1>Bar</h1> +<code><span class="keyword">class </span><span class="identifier">Bar</span></code><br/> +<p>Use <a href="test/-bar/foo">this method</a> for best results.</p> +<br/> +<br/> +<h3>Constructors</h3> +<table> +<tbody> +<tr> +<td> +<a href="test/-bar/-init-"><init></a></td> +<td> +<code><span class="identifier">Bar</span><span class="symbol">(</span><span class="symbol">)</span></code><p>Use <a href="test/-bar/foo">this method</a> for best results.</p> +</td> +</tr> +</tbody> +</table> +<h3>Functions</h3> +<table> +<tbody> +<tr> +<td> +<a href="test/-bar/foo">foo</a></td> +<td> +<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></td> +</tr> +</tbody> +</table> +</BODY> +</HTML> diff --git a/test/data/format/linkWithLabel.kt b/test/data/format/linkWithLabel.kt new file mode 100644 index 00000000..4a85c505 --- /dev/null +++ b/test/data/format/linkWithLabel.kt @@ -0,0 +1,6 @@ +/** + * Use [this method][Bar.foo] for best results. + */ +class Bar { + fun foo() {} +} diff --git a/test/src/format/HtmlFormatTest.kt b/test/src/format/HtmlFormatTest.kt index 66eefe93..f8afab8f 100644 --- a/test/src/format/HtmlFormatTest.kt +++ b/test/src/format/HtmlFormatTest.kt @@ -106,6 +106,12 @@ public class HtmlFormatTest { } } + Test fun javaLinkTagWithLabel() { + verifyOutput("test/data/format/javaLinkTagWithLabel.java", ".html") { model, output -> + htmlService.appendNodes(tempLocation, output, model.members.single().members) + } + } + Test fun javaSeeTag() { verifyOutput("test/data/format/javaSeeTag.java", ".html") { model, output -> htmlService.appendNodes(tempLocation, output, model.members.single().members) @@ -129,4 +135,10 @@ public class HtmlFormatTest { htmlService.appendNodes(tempLocation, output, model.members.single().members.filter { it.name == "Bar" }) } } + + Test fun linkWithLabel() { + verifyOutput("test/data/format/linkWithLabel.kt", ".html") { model, output -> + htmlService.appendNodes(tempLocation, output, model.members.single().members.filter { it.name == "Bar" }) + } + } } |