From 8a65a7ab62e4567bbb20cececcad88eb9ac396d9 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 27 Feb 2015 16:58:27 +0100 Subject: handle @code and @literal tags in javadoc --- src/Java/JavaDocumentationBuilder.kt | 6 ++++++ src/Utilities/Html.kt | 1 - test/data/format/javaCodeLiteralTags.java | 8 ++++++++ test/data/format/javaCodeLiteralTags.md | 17 +++++++++++++++++ test/src/format/MarkdownFormatTest.kt | 6 ++++++ 5 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 test/data/format/javaCodeLiteralTags.java create mode 100644 test/data/format/javaCodeLiteralTags.md diff --git a/src/Java/JavaDocumentationBuilder.kt b/src/Java/JavaDocumentationBuilder.kt index 8a5d8fb9..055d64d3 100644 --- a/src/Java/JavaDocumentationBuilder.kt +++ b/src/Java/JavaDocumentationBuilder.kt @@ -128,6 +128,12 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions, valueElement!!.getText() } } + "code", "literal" -> { + val text = StringBuilder() + tag.getDataElements().forEach { text.append(it.getText()) } + val escaped = text.toString().trimLeading().htmlEscape() + if (tag.getName() == "code") "$escaped" else escaped + } else -> tag.getText() } diff --git a/src/Utilities/Html.kt b/src/Utilities/Html.kt index 9630c8cb..ce3a1982 100644 --- a/src/Utilities/Html.kt +++ b/src/Utilities/Html.kt @@ -6,4 +6,3 @@ package org.jetbrains.dokka * Replaces & with &, < with < and > with > */ public fun String.htmlEscape(): String = replace("&", "&").replace("<", "<").replace(">", ">") - diff --git a/test/data/format/javaCodeLiteralTags.java b/test/data/format/javaCodeLiteralTags.java new file mode 100644 index 00000000..cf071f07 --- /dev/null +++ b/test/data/format/javaCodeLiteralTags.java @@ -0,0 +1,8 @@ +package test; + +/** + *

{@code AC}

+ *

{@literal AC}

+ */ +class C { +} diff --git a/test/data/format/javaCodeLiteralTags.md b/test/data/format/javaCodeLiteralTags.md new file mode 100644 index 00000000..17438bff --- /dev/null +++ b/test/data/format/javaCodeLiteralTags.md @@ -0,0 +1,17 @@ +[test](test/index) / [test](test/test/index) / [C](test/test/-c) + + +# C + +`open class C` + + +`A<B>C` + + +A<B>C + + + + + diff --git a/test/src/format/MarkdownFormatTest.kt b/test/src/format/MarkdownFormatTest.kt index 7253ddb4..2ee4fa46 100644 --- a/test/src/format/MarkdownFormatTest.kt +++ b/test/src/format/MarkdownFormatTest.kt @@ -124,4 +124,10 @@ public class MarkdownFormatTest { markdownService.appendNodes(tempLocation, output, model.members.single().members) } } + + Test fun javaCodeLiteralTags() { + verifyOutput("test/data/format/javaCodeLiteralTags.java", ".md") { model, output -> + markdownService.appendNodes(tempLocation, output, model.members.single().members) + } + } } -- cgit