From 2016ba9a4c6fbd1cc1644eff6d7ac606d624bd23 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Mon, 29 Dec 2014 21:05:53 +0100 Subject: render class object properties and functions --- test/data/format/classWithClassObject.kt | 7 +++++ test/data/format/classWithClassObject.md | 53 ++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 test/data/format/classWithClassObject.kt create mode 100644 test/data/format/classWithClassObject.md (limited to 'test/data/format') diff --git a/test/data/format/classWithClassObject.kt b/test/data/format/classWithClassObject.kt new file mode 100644 index 00000000..459efad6 --- /dev/null +++ b/test/data/format/classWithClassObject.kt @@ -0,0 +1,7 @@ +class Klass() { + class object { + val x = 1 + + fun foo() {} + } +} diff --git a/test/data/format/classWithClassObject.md b/test/data/format/classWithClassObject.md new file mode 100644 index 00000000..10cac365 --- /dev/null +++ b/test/data/format/classWithClassObject.md @@ -0,0 +1,53 @@ +[test](out.md) / [](out.md) / [Klass](out.md) + + +# Klass + + +``` +class Klass +``` + + + + +### Constructors + + +| +[<init>](out.md) + + | +``` +public Klass() +``` + + | + + +### Class Object Properties + + +| +[x](out.md) + + | +``` +val x: Int +``` + + | + + +### Class Object Functions + + +| +[foo](out.md) + + | +``` +fun foo(): Unit +``` + + | -- cgit From 8ef68182c02d8ec8fc33d0de0b7fcdef183e7ee7 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 30 Dec 2014 12:36:14 +0100 Subject: more correct formatting of Markdown tables --- src/Formats/HtmlFormatService.kt | 4 +-- src/Formats/MarkdownFormatService.kt | 2 +- src/Formats/StructuredFormatService.kt | 15 ++++++---- test/data/format/classWithClassObject.html | 44 ++++++++++++++++++++++++++++++ test/data/format/classWithClassObject.md | 29 ++------------------ test/src/TestAPI.kt | 7 ++--- test/src/format/HtmlFormatTest.kt | 15 ++++++++++ test/src/format/MarkdownFormatTest.kt | 4 +-- 8 files changed, 79 insertions(+), 41 deletions(-) create mode 100644 test/data/format/classWithClassObject.html create mode 100644 test/src/format/HtmlFormatTest.kt (limited to 'test/data/format') diff --git a/src/Formats/HtmlFormatService.kt b/src/Formats/HtmlFormatService.kt index 48291b48..b23e4a45 100644 --- a/src/Formats/HtmlFormatService.kt +++ b/src/Formats/HtmlFormatService.kt @@ -35,7 +35,7 @@ public open class HtmlFormatService(locationService: LocationService, to.appendln("${text}") } - override fun appendText(to: StringBuilder, text: String) { + override fun appendParagraph(to: StringBuilder, text: String) { to.appendln("

${text}

") } @@ -94,7 +94,7 @@ public open class HtmlFormatService(locationService: LocationService, } override fun formatCode(code: String): String { - return "${code.htmlEscape()}" + return "${code}" } override fun formatList(text: String): String { diff --git a/src/Formats/MarkdownFormatService.kt b/src/Formats/MarkdownFormatService.kt index 9849c674..96f64eec 100644 --- a/src/Formats/MarkdownFormatService.kt +++ b/src/Formats/MarkdownFormatService.kt @@ -62,7 +62,7 @@ public open class MarkdownFormatService(locationService: LocationService, to.appendln(text) } - override public fun appendText(to: StringBuilder, text: String) { + override public fun appendParagraph(to: StringBuilder, text: String) { to.appendln() to.appendln(text) to.appendln() diff --git a/src/Formats/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt index 60d5b7f1..2131d65d 100644 --- a/src/Formats/StructuredFormatService.kt +++ b/src/Formats/StructuredFormatService.kt @@ -10,7 +10,7 @@ public abstract class StructuredFormatService(val locationService: LocationServi abstract public fun appendBlockCode(to: StringBuilder, line: String) abstract public fun appendBlockCode(to: StringBuilder, lines: Iterable) abstract public fun appendHeader(to: StringBuilder, text: String, level: Int = 1) - abstract public fun appendText(to: StringBuilder, text: String) + abstract public fun appendParagraph(to: StringBuilder, text: String) abstract public fun appendLine(to: StringBuilder, text: String) public abstract fun appendLine(to: StringBuilder) @@ -41,7 +41,7 @@ public abstract class StructuredFormatService(val locationService: LocationServi open fun formatText(location: Location, content: ContentNode): String { return StringBuilder { when (content) { - is ContentText -> append(content.text) + is ContentText -> append(formatText(content.text)) is ContentSymbol -> append(formatSymbol(content.text)) is ContentKeyword -> append(formatKeyword(content.text)) is ContentIdentifier -> append(formatIdentifier(content.text)) @@ -61,7 +61,7 @@ public abstract class StructuredFormatService(val locationService: LocationServi append(formatLink(linkText, content.href)) } is ContentParagraph -> { - appendText(this, formatText(location, content.children)) + appendParagraph(this, formatText(location, content.children)) } is ContentBlockCode -> { appendBlockCode(this, formatText(location, content.children)) @@ -143,17 +143,20 @@ public abstract class StructuredFormatService(val locationService: LocationServi for ((memberLocation, members) in membersMap) { appendTableRow(to) { appendTableCell(to) { - appendText(to, formatLink(memberLocation)) + to.append(formatLink(memberLocation)) } appendTableCell(to) { val breakdownBySummary = members.groupBy { formatText(location, it.summary) } for ((summary, items) in breakdownBySummary) { for (signature in items) { - appendBlockCode(to, formatText(location, languageService.render(signature))) + val signature = languageService.render(signature) + val signatureAsCode = ContentCode() + signatureAsCode.append(signature) + to.append(formatText(location, signatureAsCode)) } if (!summary.isEmpty()) { - appendText(to, summary) + to.append(summary) } } } diff --git a/test/data/format/classWithClassObject.html b/test/data/format/classWithClassObject.html new file mode 100644 index 00000000..79546418 --- /dev/null +++ b/test/data/format/classWithClassObject.html @@ -0,0 +1,44 @@ + + + + +test /  / Klass
+
+

Klass

+
class Klass

+
+

Constructors

+ + + + + + + +
+<init> +public Klass()
+

Class Object Properties

+ + + + + + + +
+x +val x: Int
+

Class Object Functions

+ + + + + + + +
+foo +fun foo(): Unit
+ + diff --git a/test/data/format/classWithClassObject.md b/test/data/format/classWithClassObject.md index 10cac365..f694a76f 100644 --- a/test/data/format/classWithClassObject.md +++ b/test/data/format/classWithClassObject.md @@ -14,40 +14,17 @@ class Klass ### Constructors -| -[<init>](out.md) - - | -``` -public Klass() -``` - - | +| [<init>](out.md) | `public Klass()` | ### Class Object Properties -| -[x](out.md) - - | -``` -val x: Int -``` - - | +| [x](out.md) | `val x: Int` | ### Class Object Functions -| -[foo](out.md) - - | -``` -fun foo(): Unit -``` +| [foo](out.md) | `fun foo(): Unit` | - | diff --git a/test/src/TestAPI.kt b/test/src/TestAPI.kt index 6f4e34c2..cc09f001 100644 --- a/test/src/TestAPI.kt +++ b/test/src/TestAPI.kt @@ -51,13 +51,12 @@ public fun verifyModel(vararg files: String, verifier: (DocumentationModule) -> Disposer.dispose(environment) } -public fun verifyOutput(path: String, outputGenerator: (DocumentationModule, StringBuilder) -> Unit) { +public fun verifyOutput(path: String, outputExtension: String, outputGenerator: (DocumentationModule, StringBuilder) -> Unit) { verifyModel(path) { val output = StringBuilder() outputGenerator(it, output) - val trimmedOutput = output.toString().split('\n').map { it.trimTrailing() }.join("\n") - val expectedOutput = File(path.replace(".kt", ".md")).readText() - assertEquals(expectedOutput.trimTrailing(), trimmedOutput) + val expectedOutput = File(path.replace(".kt", outputExtension)).readText() + assertEquals(expectedOutput, output.toString()) } } diff --git a/test/src/format/HtmlFormatTest.kt b/test/src/format/HtmlFormatTest.kt new file mode 100644 index 00000000..758c6e7b --- /dev/null +++ b/test/src/format/HtmlFormatTest.kt @@ -0,0 +1,15 @@ +package org.jetbrains.dokka.tests + +import org.jetbrains.dokka.KotlinLanguageService +import org.junit.Test +import org.jetbrains.dokka.HtmlFormatService + +public class HtmlFormatTest { + private val htmlService = HtmlFormatService(InMemoryLocationService, KotlinLanguageService()) + + Test fun classWithClassObject() { + verifyOutput("test/data/format/classWithClassObject.kt", ".html") { model, output -> + htmlService.appendNodes(tempLocation, output, model.members.single().members) + } + } +} diff --git a/test/src/format/MarkdownFormatTest.kt b/test/src/format/MarkdownFormatTest.kt index ea501c53..5cdfb8b5 100644 --- a/test/src/format/MarkdownFormatTest.kt +++ b/test/src/format/MarkdownFormatTest.kt @@ -9,13 +9,13 @@ public class MarkdownFormatTest { private val markdownService = MarkdownFormatService(InMemoryLocationService, KotlinLanguageService()) Test fun emptyDescription() { - verifyOutput("test/data/format/emptyDescription.kt") { model, output -> + verifyOutput("test/data/format/emptyDescription.kt", ".md") { model, output -> markdownService.appendNodes(tempLocation, output, model.members.single().members) } } Test fun classWithClassObject() { - verifyOutput("test/data/format/classWithClassObject.kt") { model, output -> + verifyOutput("test/data/format/classWithClassObject.kt", ".md") { model, output -> markdownService.appendNodes(tempLocation, output, model.members.single().members) } } -- cgit From feca80b65581e688b1e9a3e807dfce2e17fd4a13 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 30 Dec 2014 13:41:02 +0100 Subject: add test for html escaping; fix special characters eaten from output --- src/Kotlin/ContentBuilder.kt | 19 ++++++++++++++++++- test/data/format/htmlEscaping.html | 12 ++++++++++++ test/data/format/htmlEscaping.kt | 4 ++++ test/src/format/HtmlFormatTest.kt | 6 ++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 test/data/format/htmlEscaping.html create mode 100644 test/data/format/htmlEscaping.kt (limited to 'test/data/format') diff --git a/src/Kotlin/ContentBuilder.kt b/src/Kotlin/ContentBuilder.kt index 0c82a522..0143feed 100644 --- a/src/Kotlin/ContentBuilder.kt +++ b/src/Kotlin/ContentBuilder.kt @@ -101,6 +101,17 @@ public fun DocumentationBuilder.buildContent(tree: MarkdownNode, descriptor: Dec processChildren() parent.append(nodeStack.pop()) } + MarkdownTokenTypes.COLON -> { + // TODO fix markdown parser + if (!isColonAfterSectionLabel(node)) { + parent.append(ContentText(node.text)) + } + } + MarkdownTokenTypes.DOUBLE_QUOTE, + MarkdownTokenTypes.LT, + MarkdownTokenTypes.GT -> { + parent.append(ContentText(node.text)) + } else -> { processChildren() } @@ -147,4 +158,10 @@ private fun DocumentationBuilder.resolveInScope(functionName: String, scope: Jet } return symbol -} \ No newline at end of file +} + +private fun isColonAfterSectionLabel(node: MarkdownNode): Boolean { + val parent = node.parent + return parent != null && parent.type == MarkdownElementTypes.SECTION && parent.children.size() >= 2 && + node == parent.children[1]; +} diff --git a/test/data/format/htmlEscaping.html b/test/data/format/htmlEscaping.html new file mode 100644 index 00000000..4f1409c4 --- /dev/null +++ b/test/data/format/htmlEscaping.html @@ -0,0 +1,12 @@ + + + + +test /  / x
+
+

x

+
fun <T> x(): T?

Special characters: < is "less than", > is "greater than", & is "ampersand"

+
+
+ + diff --git a/test/data/format/htmlEscaping.kt b/test/data/format/htmlEscaping.kt new file mode 100644 index 00000000..8778d8a5 --- /dev/null +++ b/test/data/format/htmlEscaping.kt @@ -0,0 +1,4 @@ +/** + * Special characters: < is "less than", > is "greater than", & is "ampersand" + */ +fun x(): T? = null diff --git a/test/src/format/HtmlFormatTest.kt b/test/src/format/HtmlFormatTest.kt index 758c6e7b..a47b5774 100644 --- a/test/src/format/HtmlFormatTest.kt +++ b/test/src/format/HtmlFormatTest.kt @@ -12,4 +12,10 @@ public class HtmlFormatTest { htmlService.appendNodes(tempLocation, output, model.members.single().members) } } + + Test fun htmlEscaping() { + verifyOutput("test/data/format/htmlEscaping.kt", ".html") { model, output -> + htmlService.appendNodes(tempLocation, output, model.members.single().members) + } + } } -- cgit From 3fc3e33a0eff0198ed89cc94197cb21653bf1ca2 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 30 Dec 2014 15:35:00 +0100 Subject: fix formatting of overload signatures --- src/Formats/StructuredFormatService.kt | 9 ++++++--- test/data/format/overloads.html | 24 ++++++++++++++++++++++++ test/data/format/overloads.kt | 5 +++++ test/src/format/HtmlFormatTest.kt | 6 ++++++ 4 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 test/data/format/overloads.html create mode 100644 test/data/format/overloads.kt (limited to 'test/data/format') diff --git a/src/Formats/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt index 2131d65d..2d326854 100644 --- a/src/Formats/StructuredFormatService.kt +++ b/src/Formats/StructuredFormatService.kt @@ -148,13 +148,16 @@ public abstract class StructuredFormatService(val locationService: LocationServi appendTableCell(to) { val breakdownBySummary = members.groupBy { formatText(location, it.summary) } for ((summary, items) in breakdownBySummary) { - for (signature in items) { + val signatureTexts = items map { signature -> val signature = languageService.render(signature) val signatureAsCode = ContentCode() signatureAsCode.append(signature) - to.append(formatText(location, signatureAsCode)) + formatText(location, signatureAsCode) } - + signatureTexts.subList(0, signatureTexts.size()-1).forEach { + appendLine(to, it) + } + to.append(signatureTexts.last()) if (!summary.isEmpty()) { to.append(summary) } diff --git a/test/data/format/overloads.html b/test/data/format/overloads.html new file mode 100644 index 00000000..9ea88869 --- /dev/null +++ b/test/data/format/overloads.html @@ -0,0 +1,24 @@ + + + + +test / 
+
+

+
package 

+
+

Functions

+ + + + + + + +
+f +fun f(x: Int): Unit
+fun f(x: String): Unit

Performs an action on x.

+
+ + diff --git a/test/data/format/overloads.kt b/test/data/format/overloads.kt new file mode 100644 index 00000000..dcd2d097 --- /dev/null +++ b/test/data/format/overloads.kt @@ -0,0 +1,5 @@ +/** Performs an action on x. */ +fun f(x: Int) { } + +/** Performs an action on x. */ +fun f(x: String) { } diff --git a/test/src/format/HtmlFormatTest.kt b/test/src/format/HtmlFormatTest.kt index a47b5774..881a7828 100644 --- a/test/src/format/HtmlFormatTest.kt +++ b/test/src/format/HtmlFormatTest.kt @@ -18,4 +18,10 @@ public class HtmlFormatTest { htmlService.appendNodes(tempLocation, output, model.members.single().members) } } + + Test fun overloads() { + verifyOutput("test/data/format/overloads.kt", ".html") { model, output -> + htmlService.appendNodes(tempLocation, output, model.members) + } + } } -- cgit