From 25592f52ea3e70e183a2a72bc411346b1650ed9a Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Mon, 9 Feb 2015 21:05:56 +0100 Subject: correctly render @see links --- src/Kotlin/DocumentationBuilder.kt | 33 ++++++++++++++++++++++++++------- src/Model/Content.kt | 4 ++-- test/data/format/see.html | 27 +++++++++++++++++++++++++++ test/data/format/see.kt | 12 ++++++++++++ test/src/format/HtmlFormatTest.kt | 6 ++++++ 5 files changed, 73 insertions(+), 9 deletions(-) create mode 100644 test/data/format/see.html create mode 100644 test/data/format/see.kt diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt index 1680b407..c9c45214 100644 --- a/src/Kotlin/DocumentationBuilder.kt +++ b/src/Kotlin/DocumentationBuilder.kt @@ -51,13 +51,17 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati if (kdoc is KDocSection) { val tags = kdoc.getTags() tags.forEach { - if (it.getName() == "sample") { - content.append(functionBody(descriptor, it.getSubjectName())) - } else { - val section = content.addSection(displayName(it.getName()), it.getSubjectName()) - val sectionContent = it.getContent() - val markdownNode = parseMarkdown(sectionContent) - buildInlineContentTo(markdownNode, section) + when (it.getName()) { + "sample" -> + content.append(functionBody(descriptor, it.getSubjectName())) + "see" -> + content.addTagToSeeAlso(it) + else -> { + val section = content.addSection(displayName(it.getName()), it.getSubjectName()) + val sectionContent = it.getContent() + val markdownNode = parseMarkdown(sectionContent) + buildInlineContentTo(markdownNode, section) + } } } } @@ -73,6 +77,18 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati else -> sectionName?.capitalize() } + private fun Content.addTagToSeeAlso(seeTag: KDocTag) { + val subjectName = seeTag.getSubjectName() + if (subjectName != null) { + val seeSection = findSectionByTag("See Also") ?: addSection("See Also", null) + val link = ContentExternalLink(subjectName) + link.append(ContentText(subjectName)) + val para = ContentParagraph() + para.append(link) + seeSection.append(para) + } + } + fun link(node: DocumentationNode, descriptor: DeclarationDescriptor) { links.put(node, descriptor) } @@ -505,6 +521,9 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati } resolveContentLinks(node, node.content) + for (section in node.content.sections) { + resolveContentLinks(node, section) + } for (child in node.members) { resolveReferences(child) diff --git a/src/Model/Content.kt b/src/Model/Content.kt index e59037d2..bb0ff00f 100644 --- a/src/Model/Content.kt +++ b/src/Model/Content.kt @@ -58,8 +58,8 @@ public class Content() : ContentNode() { public val sections: List get() = sectionList - fun addSection(name: String?, subjectName: String?): ContentSection { - val section = ContentSection(name ?: "", subjectName) + fun addSection(tag: String?, subjectName: String?): ContentSection { + val section = ContentSection(tag ?: "", subjectName) sectionList.add(section) return section } diff --git a/test/data/format/see.html b/test/data/format/see.html new file mode 100644 index 00000000..fa283363 --- /dev/null +++ b/test/data/format/see.html @@ -0,0 +1,27 @@ + + + + +test /  / quux
+
+

quux

+
fun quux(): Unit

+
+
+
+See Also
+

foo

+

bar

+
+test /  / foo
+
+

foo

+
fun foo(): Unit

+
+test /  / bar
+
+

bar

+
fun bar(): Unit

+
+ + diff --git a/test/data/format/see.kt b/test/data/format/see.kt new file mode 100644 index 00000000..a0b153b0 --- /dev/null +++ b/test/data/format/see.kt @@ -0,0 +1,12 @@ +/** + * @see foo + * @see bar + */ +fun quux() { +} + +fun foo() { +} + +fun bar() { +} \ No newline at end of file diff --git a/test/src/format/HtmlFormatTest.kt b/test/src/format/HtmlFormatTest.kt index 251c7074..e180a86c 100644 --- a/test/src/format/HtmlFormatTest.kt +++ b/test/src/format/HtmlFormatTest.kt @@ -51,4 +51,10 @@ public class HtmlFormatTest { htmlService.appendNodes(tempLocation, output, model.members.single().members) } } + + Test fun see() { + verifyOutput("test/data/format/see.kt", ".html") { model, output -> + htmlService.appendNodes(tempLocation, output, model.members.single().members) + } + } } -- cgit