diff options
-rw-r--r-- | src/Formats/HtmlFormatService.kt | 7 | ||||
-rw-r--r-- | src/Formats/MarkdownFormatService.kt | 8 | ||||
-rw-r--r-- | src/Formats/StructuredFormatService.kt | 21 | ||||
-rw-r--r-- | src/Java/JavaDocumentationBuilder.kt | 3 | ||||
-rw-r--r-- | src/Kotlin/ContentBuilder.kt | 4 | ||||
-rw-r--r-- | src/Model/Content.kt | 3 | ||||
-rw-r--r-- | test/data/format/javadocHtml.md | 1 | ||||
-rw-r--r-- | test/data/format/javadocOrderedList.java | 10 | ||||
-rw-r--r-- | test/data/format/javadocOrderedList.md | 14 | ||||
-rw-r--r-- | test/data/format/orderedList.html | 31 | ||||
-rw-r--r-- | test/data/format/orderedList.kt | 8 | ||||
-rw-r--r-- | test/src/format/HtmlFormatTest.kt | 6 | ||||
-rw-r--r-- | test/src/format/MarkdownFormatTest.kt | 6 |
13 files changed, 104 insertions, 18 deletions
diff --git a/src/Formats/HtmlFormatService.kt b/src/Formats/HtmlFormatService.kt index fee21738..78d3cff2 100644 --- a/src/Formats/HtmlFormatService.kt +++ b/src/Formats/HtmlFormatService.kt @@ -98,11 +98,10 @@ public open class HtmlFormatService(locationService: LocationService, return "<code>${code}</code>" } - override fun formatList(text: String): String { - return "<ul>${text}</ul>" - } + override fun formatUnorderedList(text: String): String = "<ul>${text}</ul>" + override fun formatOrderedList(text: String): String = "<ol>${text}</ol>" - override fun formatListItem(text: String): String { + override fun formatListItem(text: String, kind: ListKind): String { return "<li>${text}</li>" } diff --git a/src/Formats/MarkdownFormatService.kt b/src/Formats/MarkdownFormatService.kt index 8809fa96..ba7d8f7b 100644 --- a/src/Formats/MarkdownFormatService.kt +++ b/src/Formats/MarkdownFormatService.kt @@ -27,10 +27,12 @@ public open class MarkdownFormatService(locationService: LocationService, return "`$code`" } - override public fun formatList(text: String): String = text + "\n" + override public fun formatUnorderedList(text: String): String = text + "\n" + override public fun formatOrderedList(text: String): String = text + "\n" - override fun formatListItem(text: String): String { - return "* $text" + override fun formatListItem(text: String, kind: ListKind): String { + val itemText = if (text.endsWith("\n")) text else text + "\n" + return if (kind == ListKind.Unordered) "* $itemText" else "1. $itemText" } override public fun formatStrong(text: String): String { diff --git a/src/Formats/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt index b3d1463e..7b9374ec 100644 --- a/src/Formats/StructuredFormatService.kt +++ b/src/Formats/StructuredFormatService.kt @@ -5,6 +5,11 @@ import org.jetbrains.dokka.LanguageService.RenderMode public data class FormatLink(val text: String, val href: String) +enum class ListKind { + Ordered + Unordered +} + public abstract class StructuredFormatService(locationService: LocationService, val languageService: LanguageService, override val extension: String) : FormatService { @@ -33,16 +38,17 @@ public abstract class StructuredFormatService(locationService: LocationService, public abstract fun formatStrikethrough(text: String): String public abstract fun formatEmphasis(text: String): String public abstract fun formatCode(code: String): String - public abstract fun formatList(text: String): String - public abstract fun formatListItem(text: String): String + public abstract fun formatUnorderedList(text: String): String + public abstract fun formatOrderedList(text: String): String + public abstract fun formatListItem(text: String, kind: ListKind): String public abstract fun formatBreadcrumbs(items: Iterable<FormatLink>): String public abstract fun formatNonBreakingSpace(): String - open fun formatText(location: Location, nodes: Iterable<ContentNode>): String { - return nodes.map { formatText(location, it) }.join("") + open fun formatText(location: Location, nodes: Iterable<ContentNode>, listKind: ListKind = ListKind.Unordered): String { + return nodes.map { formatText(location, it, listKind) }.join("") } - open fun formatText(location: Location, content: ContentNode): String { + open fun formatText(location: Location, content: ContentNode, listKind: ListKind = ListKind.Unordered): String { return StringBuilder { when (content) { is ContentText -> append(formatText(content.text)) @@ -54,8 +60,9 @@ public abstract class StructuredFormatService(locationService: LocationService, is ContentStrikethrough -> append(formatStrikethrough(formatText(location, content.children))) is ContentCode -> append(formatCode(formatText(location, content.children))) is ContentEmphasis -> append(formatEmphasis(formatText(location, content.children))) - is ContentList -> append(formatList(formatText(location, content.children))) - is ContentListItem -> append(formatListItem(formatText(location, content.children))) + is ContentUnorderedList -> append(formatUnorderedList(formatText(location, content.children, ListKind.Unordered))) + is ContentOrderedList -> append(formatOrderedList(formatText(location, content.children, ListKind.Ordered))) + is ContentListItem -> append(formatListItem(formatText(location, content.children), listKind)) is ContentNodeLink -> { val node = content.node diff --git a/src/Java/JavaDocumentationBuilder.kt b/src/Java/JavaDocumentationBuilder.kt index 5720850d..c2a15a45 100644 --- a/src/Java/JavaDocumentationBuilder.kt +++ b/src/Java/JavaDocumentationBuilder.kt @@ -84,7 +84,8 @@ public class JavaDocumentationBuilder(private val options: DocumentationOptions, "s", "del" -> ContentStrikethrough() "code" -> ContentCode() "pre" -> ContentBlockCode() - "ul" -> ContentList() + "ul" -> ContentUnorderedList() + "ol" -> ContentOrderedList() "li" -> ContentListItem() "a" -> createLink(element) else -> ContentBlock() diff --git a/src/Kotlin/ContentBuilder.kt b/src/Kotlin/ContentBuilder.kt index 44a4f39e..4081dc6e 100644 --- a/src/Kotlin/ContentBuilder.kt +++ b/src/Kotlin/ContentBuilder.kt @@ -25,12 +25,12 @@ public fun buildContentTo(tree: MarkdownNode, target: ContentBlock, linkResolver val parent = nodeStack.peek()!! when (node.type) { MarkdownElementTypes.UNORDERED_LIST -> { - nodeStack.push(ContentList()) + nodeStack.push(ContentUnorderedList()) processChildren() parent.append(nodeStack.pop()) } MarkdownElementTypes.ORDERED_LIST -> { - nodeStack.push(ContentList()) // TODO: add list kind + nodeStack.push(ContentOrderedList()) processChildren() parent.append(nodeStack.pop()) } diff --git a/src/Model/Content.kt b/src/Model/Content.kt index 91a7da81..d9c3d139 100644 --- a/src/Model/Content.kt +++ b/src/Model/Content.kt @@ -76,7 +76,8 @@ public class ContentExternalLink(val href : String) : ContentBlock() { children.hashCode() * 31 + href.hashCode() } -public class ContentList() : ContentBlock() +public class ContentUnorderedList() : ContentBlock() +public class ContentOrderedList() : ContentBlock() public class ContentListItem() : ContentBlock() public class ContentSection(public val tag: String, public val subjectName: String?) : ContentBlock() { diff --git a/test/data/format/javadocHtml.md b/test/data/format/javadocHtml.md index 303b102c..64b7a5a4 100644 --- a/test/data/format/javadocHtml.md +++ b/test/data/format/javadocHtml.md @@ -14,6 +14,7 @@ Block code ``` * List Item + diff --git a/test/data/format/javadocOrderedList.java b/test/data/format/javadocOrderedList.java new file mode 100644 index 00000000..1c7f8a3e --- /dev/null +++ b/test/data/format/javadocOrderedList.java @@ -0,0 +1,10 @@ +package test; + +/** + * <ol> + * <li>Rinse</li> + * <li>Repeat</li> + * </ol> + */ +public class Bar { +} diff --git a/test/data/format/javadocOrderedList.md b/test/data/format/javadocOrderedList.md new file mode 100644 index 00000000..ba5935e2 --- /dev/null +++ b/test/data/format/javadocOrderedList.md @@ -0,0 +1,14 @@ +[test](test/index) / [test](test/test/index) / [Bar](test/test/-bar) + + +# Bar + +`public open class Bar` + + 1. Rinse + 1. Repeat + + + + + diff --git a/test/data/format/orderedList.html b/test/data/format/orderedList.html new file mode 100644 index 00000000..223684ff --- /dev/null +++ b/test/data/format/orderedList.html @@ -0,0 +1,31 @@ +<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>Usage instructions:</p> +<h3>Description</h3> +<ol><li><p>Rinse</p> +</li><li><p>Repeat</p> +</li></ol><br/> +<br/> +<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>Usage instructions:</p> +</td> +</tr> +</tbody> +</table> +</BODY> +</HTML> diff --git a/test/data/format/orderedList.kt b/test/data/format/orderedList.kt new file mode 100644 index 00000000..03681c7a --- /dev/null +++ b/test/data/format/orderedList.kt @@ -0,0 +1,8 @@ +/** + * Usage instructions: + * + * 1. Rinse + * 1. Repeat + */ +class Bar { +} diff --git a/test/src/format/HtmlFormatTest.kt b/test/src/format/HtmlFormatTest.kt index c81b2d85..66eefe93 100644 --- a/test/src/format/HtmlFormatTest.kt +++ b/test/src/format/HtmlFormatTest.kt @@ -123,4 +123,10 @@ public class HtmlFormatTest { htmlService.appendNodes(tempLocation, output, model.members.single().members.filter { it.name == "Bar" }) } } + + Test fun orderedList() { + verifyOutput("test/data/format/orderedList.kt", ".html") { model, output -> + htmlService.appendNodes(tempLocation, output, model.members.single().members.filter { it.name == "Bar" }) + } + } } diff --git a/test/src/format/MarkdownFormatTest.kt b/test/src/format/MarkdownFormatTest.kt index 31ffc3cf..33718e87 100644 --- a/test/src/format/MarkdownFormatTest.kt +++ b/test/src/format/MarkdownFormatTest.kt @@ -154,4 +154,10 @@ public class MarkdownFormatTest { markdownService.appendNodes(tempLocation, output, model.members.single().members.single { it.name == "C" }.members.filter { it.name == "plus" }) } } + + Test fun javadocOrderedLIst() { + verifyOutput("test/data/format/javadocOrderedList.java", ".md") { model, output -> + markdownService.appendNodes(tempLocation, output, model.members.single().members.filter { it.name == "Bar" }) + } + } } |