aboutsummaryrefslogtreecommitdiff
path: root/src/Formats
diff options
context:
space:
mode:
Diffstat (limited to 'src/Formats')
-rw-r--r--src/Formats/HtmlFormatService.kt46
-rw-r--r--src/Formats/MarkdownFormatService.kt29
-rw-r--r--src/Formats/StructuredFormatService.kt54
3 files changed, 97 insertions, 32 deletions
diff --git a/src/Formats/HtmlFormatService.kt b/src/Formats/HtmlFormatService.kt
index 406065d6..e6d09991 100644
--- a/src/Formats/HtmlFormatService.kt
+++ b/src/Formats/HtmlFormatService.kt
@@ -10,42 +10,72 @@ public open class HtmlFormatService(locationService: LocationService, signatureG
override fun appendBlockCode(to: StringBuilder, line: String) {
to.appendln("<code>")
- to.appendln(formatText(line))
+ to.appendln(line)
to.appendln("</code>")
}
override fun appendBlockCode(to: StringBuilder, lines: Iterable<String>) {
to.appendln("<code>")
- to.appendln(lines.map { formatText(it) }.join("\n"))
+ to.appendln(lines.map { it }.join("\n"))
to.appendln("</code>")
}
override fun appendHeader(to: StringBuilder, text: String, level: Int) {
- to.appendln("<h$level>${formatText(text)}</h$level>")
+ to.appendln("<h$level>${text}</h$level>")
}
override fun appendText(to: StringBuilder, text: String) {
- to.appendln("<p>${formatText(text)}</p>")
+ to.appendln("<p>${text}</p>")
}
override fun appendLine(to: StringBuilder, text: String) {
- to.appendln("${formatText(text)}<br/>")
+ to.appendln("${text}<br/>")
}
override fun appendLine(to: StringBuilder) {
to.appendln("<br/>")
}
+ override fun appendTable(to: StringBuilder, body: () -> Unit) {
+ to.appendln("<table>")
+ body()
+ to.appendln("</table>")
+ }
+
+ override fun appendTableHeader(to: StringBuilder, body: () -> Unit) {
+ to.appendln("<thead>")
+ body()
+ to.appendln("</thead>")
+ }
+
+ override fun appendTableBody(to: StringBuilder, body: () -> Unit) {
+ to.appendln("<tbody>")
+ body()
+ to.appendln("</tbody>")
+ }
+
+ override fun appendTableRow(to: StringBuilder, body: () -> Unit) {
+ to.appendln("<tr>")
+ body()
+ to.appendln("</tr>")
+ }
+
+ override fun appendTableCell(to: StringBuilder, body: () -> Unit) {
+ to.appendln("<td>")
+ body()
+ to.appendln("</td>")
+ }
+
override fun formatLink(text: String, location: Location): String {
- return "<a href=\"${location.path}\">${formatText(text)}</a>"
+ return "<a href=\"${location.path}\">${text}</a>"
}
override fun formatBold(text: String): String {
- return "<b>${formatText(text)}</b>"
+ return "<b>${text}</b>"
}
override fun formatCode(code: String): String {
- return "<code>${formatText(code)}</code>"
+ return "<code>${code}</code>"
}
override fun formatBreadcrumbs(items: Iterable<FormatLink>): String {
diff --git a/src/Formats/MarkdownFormatService.kt b/src/Formats/MarkdownFormatService.kt
index 3768c3f1..60e38290 100644
--- a/src/Formats/MarkdownFormatService.kt
+++ b/src/Formats/MarkdownFormatService.kt
@@ -31,11 +31,11 @@ public open class MarkdownFormatService(locationService: LocationService, signat
}
override public fun appendLine(to: StringBuilder, text: String) {
- to.appendln(formatText(text))
+ to.appendln(text)
}
override public fun appendText(to: StringBuilder, text: String) {
- to.append(formatText(text))
+ to.append(text)
}
override public fun appendHeader(to: StringBuilder, text: String, level: Int) {
@@ -59,6 +59,31 @@ public open class MarkdownFormatService(locationService: LocationService, signat
appendLine(to, "```")
}
+ override fun appendTable(to: StringBuilder, body: () -> Unit) {
+ to.appendln()
+ body()
+ to.appendln()
+ }
+
+ override fun appendTableHeader(to: StringBuilder, body: () -> Unit) {
+ body()
+ }
+
+ override fun appendTableBody(to: StringBuilder, body: () -> Unit) {
+ body()
+ }
+
+ override fun appendTableRow(to: StringBuilder, body: () -> Unit) {
+ to.append("|")
+ body()
+ to.appendln()
+ }
+
+ override fun appendTableCell(to: StringBuilder, body: () -> Unit) {
+ body()
+ to.append("|")
+ }
+
var outlineLevel = 0
override fun appendOutlineHeader(to: StringBuilder, node: DocumentationNode) {
val indent = " ".repeat(outlineLevel)
diff --git a/src/Formats/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt
index 87115f8b..13af77ce 100644
--- a/src/Formats/StructuredFormatService.kt
+++ b/src/Formats/StructuredFormatService.kt
@@ -14,9 +14,15 @@ public abstract class StructuredFormatService(val locationService: LocationServi
abstract public fun appendLine(to: StringBuilder, text: String)
public abstract fun appendLine(to: StringBuilder)
- public abstract fun formatLink(text: String, location: Location): String
- public open fun formatLink(link: FormatLink): String = formatLink(link.text, link.location)
+ public abstract fun appendTable(to: StringBuilder, body: () -> Unit)
+ public abstract fun appendTableHeader(to: StringBuilder, body: () -> Unit)
+ public abstract fun appendTableBody(to: StringBuilder, body: () -> Unit)
+ public abstract fun appendTableRow(to: StringBuilder, body: () -> Unit)
+ public abstract fun appendTableCell(to: StringBuilder, body: () -> Unit)
+ public abstract fun formatText(text: String): String
+ public abstract fun formatLink(text: String, location: Location): String
+ public open fun formatLink(link: FormatLink): String = formatLink(formatText(link.text), link.location)
public abstract fun formatBold(text: String): String
public abstract fun formatCode(code: String): String
public abstract fun formatBreadcrumbs(items: Iterable<FormatLink>): String
@@ -36,11 +42,11 @@ public abstract class StructuredFormatService(val locationService: LocationServi
if (!single) {
appendBlockCode(to, languageService.render(node))
}
- appendLine(to, node.doc.description)
+ appendLine(to, formatText(node.doc.description))
appendLine(to)
for (section in node.doc.sections) {
- appendLine(to, formatBold(section.label))
- appendLine(to, section.text)
+ appendLine(to, formatBold(formatText(section.label)))
+ appendLine(to, formatText(section.text))
appendLine(to)
}
}
@@ -61,7 +67,7 @@ public abstract class StructuredFormatService(val locationService: LocationServi
open public fun appendLocation(to: StringBuilder, nodes: Iterable<DocumentationNode>) {
val breakdownByName = nodes.groupByTo(LinkedHashMap()) { node -> node.name }
for ((name, items) in breakdownByName) {
- appendHeader(to, "${name}")
+ appendHeader(to, formatText(name))
appendSummary(to, items)
appendDescription(to, items)
}
@@ -82,28 +88,33 @@ public abstract class StructuredFormatService(val locationService: LocationServi
if (node.members.any()) {
appendHeader(to, "Members", 3)
- appendLine(to, "| Name | Summary |") // TODO: hardcoded
- appendLine(to, "|------|---------|")
val children = node.members.sortBy { it.name }
val membersMap = children.groupByTo(LinkedHashMap()) { link(node, it) }
- for ((location, members) in membersMap) {
- appendText(to, "|${formatLink(location)}|")
- val breakdownBySummary = members.groupByTo(LinkedHashMap()) { it.doc.summary }
- for ((summary, items) in breakdownBySummary) {
- if (!summary.isEmpty()) {
- appendText(to, summary)
- to.append("<br/>") // TODO: hardcoded
+ appendTable(to) {
+ appendTableBody(to) {
+ for ((location, members) in membersMap) {
+ appendTableRow(to) {
+ appendTableCell(to) {
+ appendText(to, formatLink(location))
+ }
+ appendTableCell(to) {
+ val breakdownBySummary = members.groupByTo(LinkedHashMap()) { it.doc.summary }
+ for ((summary, items) in breakdownBySummary) {
+ if (!summary.isEmpty()) {
+ appendText(to, formatText(summary))
+ to.append("<br/>") // TODO: hardcoded
+ }
+
+ val signatures = items.map { formatBold(formatCode("${languageService.render(it)}")) }
+ to.append(signatures.join("<br/>")) // TODO: hardcoded
+ }
+ }
+ }
}
-
- val signatures = items.map { formatBold(formatCode("${languageService.render(it)}")) }
- to.append(signatures.join("<br/>")) // TODO: hardcoded
}
-
- appendLine(to, "|")
}
}
-
}
}
@@ -118,5 +129,4 @@ public abstract class StructuredFormatService(val locationService: LocationServi
}
}
}
- public abstract fun formatText(text: String): String
} \ No newline at end of file