From 9f0ff55b5f126c31b6d8f3cd28907e5b87601e28 Mon Sep 17 00:00:00 2001 From: Ilya Ryzhenkov Date: Mon, 13 Oct 2014 13:38:40 +0400 Subject: Parse and format inline code, fix strong & emph formatting. --- src/Formats/HtmlFormatService.kt | 20 ++++++++++++-------- src/Formats/MarkdownFormatService.kt | 6 +++++- src/Formats/StructuredFormatService.kt | 9 ++++++--- 3 files changed, 23 insertions(+), 12 deletions(-) (limited to 'src/Formats') diff --git a/src/Formats/HtmlFormatService.kt b/src/Formats/HtmlFormatService.kt index 20cd4f83..c337b69b 100644 --- a/src/Formats/HtmlFormatService.kt +++ b/src/Formats/HtmlFormatService.kt @@ -20,15 +20,15 @@ public open class HtmlFormatService(locationService: LocationService, } override fun appendBlockCode(to: StringBuilder, line: String) { - to.appendln("") - to.appendln(line) - to.appendln("") + to.append("
")
+        to.append(line)
+        to.append("
") } override fun appendBlockCode(to: StringBuilder, lines: Iterable) { - to.appendln("") - to.appendln(lines.join("\n")) - to.appendln("") + to.append("
")
+        to.append(lines.join("\n"))
+        to.append("
") } override fun appendHeader(to: StringBuilder, text: String, level: Int) { @@ -85,8 +85,12 @@ public open class HtmlFormatService(locationService: LocationService, return "${text}" } - override fun formatBold(text: String): String { - return "${text}" + override fun formatStrong(text: String): String { + return "${text}" + } + + override fun formatEmphasis(text: String): String { + return "${text}" } override fun formatCode(code: String): String { diff --git a/src/Formats/MarkdownFormatService.kt b/src/Formats/MarkdownFormatService.kt index a835a673..54298e2a 100644 --- a/src/Formats/MarkdownFormatService.kt +++ b/src/Formats/MarkdownFormatService.kt @@ -30,10 +30,14 @@ public open class MarkdownFormatService(locationService: LocationService, return "`$code`" } - override public fun formatBold(text: String): String { + override public fun formatStrong(text: String): String { return "**$text**" } + override fun formatEmphasis(text: String): String { + return "*$text*" + } + override public fun formatLink(text: String, location: Location): String { return "[$text](${location.path})" } diff --git a/src/Formats/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt index df11b835..75b51ab8 100644 --- a/src/Formats/StructuredFormatService.kt +++ b/src/Formats/StructuredFormatService.kt @@ -27,7 +27,8 @@ public abstract class StructuredFormatService(val locationService: LocationServi public abstract fun formatLink(text: String, location: Location): String public abstract fun formatLink(text: String, href: String): String public open fun formatLink(link: FormatLink): String = formatLink(formatText(link.text), link.location) - public abstract fun formatBold(text: String): String + public abstract fun formatStrong(text: String): String + public abstract fun formatEmphasis(text: String): String public abstract fun formatCode(code: String): String public abstract fun formatBreadcrumbs(items: Iterable): String @@ -42,7 +43,9 @@ public abstract class StructuredFormatService(val locationService: LocationServi is ContentSymbol -> append(formatSymbol(content.text)) is ContentKeyword -> append(formatKeyword(content.text)) is ContentIdentifier -> append(formatIdentifier(content.text)) - is ContentEmphasis -> append(formatBold(formatText(location, content.children))) + is ContentStrong -> append(formatStrong(formatText(location, content.children))) + is ContentCode -> append(formatCode(formatText(location, content.children))) + is ContentEmphasis -> append(formatEmphasis(formatText(location, content.children))) is ContentNodeLink -> { val linkTo = locationService.relativeLocation(location, content.node, extension) val linkText = formatText(location, content.children) @@ -77,7 +80,7 @@ public abstract class StructuredFormatService(val locationService: LocationServi for ((label, section) in node.doc.sections) { if (label.startsWith("$")) continue - appendLine(to, formatBold(formatText(label))) + appendLine(to, formatStrong(formatText(label))) appendLine(to, formatText(location, section)) appendLine(to) } -- cgit