aboutsummaryrefslogtreecommitdiff
path: root/src/Formats
diff options
context:
space:
mode:
authorDmitry Jemerov <yole@jetbrains.com>2015-03-03 19:35:56 +0100
committerDmitry Jemerov <yole@jetbrains.com>2015-03-03 19:35:56 +0100
commit6659337410225b813ea902bfa4b2e5ba3c2c1aaa (patch)
tree3c3679f01bca4497f800a371e42681246843d5d3 /src/Formats
parente961960934e2f43cdfc6ad63126c005866a60003 (diff)
downloaddokka-6659337410225b813ea902bfa4b2e5ba3c2c1aaa.tar.gz
dokka-6659337410225b813ea902bfa4b2e5ba3c2c1aaa.tar.bz2
dokka-6659337410225b813ea902bfa4b2e5ba3c2c1aaa.zip
support ordered lists
Diffstat (limited to 'src/Formats')
-rw-r--r--src/Formats/HtmlFormatService.kt7
-rw-r--r--src/Formats/MarkdownFormatService.kt8
-rw-r--r--src/Formats/StructuredFormatService.kt21
3 files changed, 22 insertions, 14 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