diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Formats/HtmlFormatService.kt | 2 | ||||
-rw-r--r-- | src/Formats/MarkdownFormatService.kt | 2 | ||||
-rw-r--r-- | src/Formats/StructuredFormatService.kt | 2 | ||||
-rw-r--r-- | src/Kotlin/KotlinLanguageService.kt | 41 | ||||
-rw-r--r-- | src/Model/Content.kt | 2 |
5 files changed, 35 insertions, 14 deletions
diff --git a/src/Formats/HtmlFormatService.kt b/src/Formats/HtmlFormatService.kt index 751c5d5b..46e4be4a 100644 --- a/src/Formats/HtmlFormatService.kt +++ b/src/Formats/HtmlFormatService.kt @@ -145,6 +145,8 @@ public open class HtmlFormatService(locationService: LocationService, body() to.appendln("</ul>") } + + override fun formatNonBreakingSpace(): String = " " } fun getPageTitle(nodes: Iterable<DocumentationNode>): String? { diff --git a/src/Formats/MarkdownFormatService.kt b/src/Formats/MarkdownFormatService.kt index 2bd12c53..2ea169dd 100644 --- a/src/Formats/MarkdownFormatService.kt +++ b/src/Formats/MarkdownFormatService.kt @@ -117,4 +117,6 @@ public open class MarkdownFormatService(locationService: LocationService, body() to.append(" |") } + + override fun formatNonBreakingSpace(): String = " " } diff --git a/src/Formats/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt index 794b0990..ee835aa0 100644 --- a/src/Formats/StructuredFormatService.kt +++ b/src/Formats/StructuredFormatService.kt @@ -37,6 +37,7 @@ public abstract class StructuredFormatService(locationService: LocationService, public abstract fun formatList(text: String): String public abstract fun formatListItem(text: String): 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("") @@ -49,6 +50,7 @@ public abstract class StructuredFormatService(locationService: LocationService, is ContentSymbol -> append(formatSymbol(content.text)) is ContentKeyword -> append(formatKeyword(content.text)) is ContentIdentifier -> append(formatIdentifier(content.text)) + is ContentNonBreakingSpace -> append(formatNonBreakingSpace()) is ContentStrong -> append(formatStrong(formatText(location, content.children))) is ContentStrikethrough -> append(formatStrikethrough(formatText(location, content.children))) is ContentCode -> append(formatCode(formatText(location, content.children))) diff --git a/src/Kotlin/KotlinLanguageService.kt b/src/Kotlin/KotlinLanguageService.kt index 56baad58..435fbc64 100644 --- a/src/Kotlin/KotlinLanguageService.kt +++ b/src/Kotlin/KotlinLanguageService.kt @@ -48,12 +48,18 @@ class KotlinLanguageService : LanguageService { identifier(node.name) } - private fun ContentBlock.renderList(nodes: List<DocumentationNode>, separator: String = ", ", renderItem: (DocumentationNode) -> Unit) { + private fun ContentBlock.renderList(nodes: List<DocumentationNode>, separator: String = ", ", + noWrap: Boolean = false, renderItem: (DocumentationNode) -> Unit) { if (nodes.none()) return renderItem(nodes.first()) nodes.drop(1).forEach { - symbol(separator) + if (noWrap) { + symbol(separator.trimTrailing(" ")) + nbsp() + } else { + symbol(separator) + } renderItem(it) } } @@ -73,13 +79,13 @@ class KotlinLanguageService : LanguageService { if (node.name == "Function${typeArguments.count() - 1}") { // lambda symbol("(") - renderList(typeArguments.take(typeArguments.size - 1)) { + renderList(typeArguments.take(typeArguments.size() - 1), noWrap = true) { renderType(it) } symbol(")") - text(" ") + nbsp() symbol("->") - text(" ") + nbsp() renderType(typeArguments.last()) return } @@ -88,20 +94,20 @@ class KotlinLanguageService : LanguageService { renderType(typeArguments.first()) symbol(".") symbol("(") - renderList(typeArguments.drop(1).take(typeArguments.size - 2)) { + renderList(typeArguments.drop(1).take(typeArguments.size() - 2), noWrap = true) { renderType(it) } symbol(")") - text(" ") + nbsp() symbol("->") - text(" ") + nbsp() renderType(typeArguments.last()) return } renderLinked(node) { identifier(it.name) } if (typeArguments.any()) { symbol("<") - renderList(typeArguments) { + renderList(typeArguments, noWrap = true) { renderType(it) } symbol(">") @@ -122,8 +128,10 @@ class KotlinLanguageService : LanguageService { val constraints = node.details(DocumentationNode.Kind.UpperBound) identifier(node.name) if (constraints.any()) { - symbol(" : ") - renderList(constraints) { + nbsp() + symbol(":") + nbsp() + renderList(constraints, noWrap=true) { renderType(it) } } @@ -132,12 +140,15 @@ class KotlinLanguageService : LanguageService { private fun ContentBlock.renderParameter(node: DocumentationNode) { renderAnnotationsForNode(node) identifier(node.name) - symbol(": ") + symbol(":") + nbsp() val parameterType = node.detail(DocumentationNode.Kind.Type) renderType(parameterType) val valueNode = node.details(DocumentationNode.Kind.Value).firstOrNull() if (valueNode != null) { - symbol(" = ") + nbsp() + symbol("=") + nbsp() text(valueNode.name) } } @@ -156,7 +167,9 @@ class KotlinLanguageService : LanguageService { private fun ContentBlock.renderSupertypesForNode(node: DocumentationNode) { val supertypes = node.details(DocumentationNode.Kind.Supertype) if (supertypes.any()) { - symbol(" : ") + nbsp() + symbol(":") + nbsp() renderList(supertypes) { renderType(it) } diff --git a/src/Model/Content.kt b/src/Model/Content.kt index 5688e2b8..8e9c068d 100644 --- a/src/Model/Content.kt +++ b/src/Model/Content.kt @@ -30,6 +30,7 @@ public data class ContentText(val text: String) : ContentNode() public data class ContentKeyword(val text: String) : ContentNode() public data class ContentIdentifier(val text: String) : ContentNode() public data class ContentSymbol(val text: String) : ContentNode() +public object ContentNonBreakingSpace: ContentNode() public class ContentParagraph() : ContentBlock() public class ContentEmphasis() : ContentBlock() @@ -89,6 +90,7 @@ fun ContentBlock.text(value: String) = append(ContentText(value)) fun ContentBlock.keyword(value: String) = append(ContentKeyword(value)) fun ContentBlock.symbol(value: String) = append(ContentSymbol(value)) fun ContentBlock.identifier(value: String) = append(ContentIdentifier(value)) +fun ContentBlock.nbsp() = append(ContentNonBreakingSpace) fun ContentBlock.link(to: DocumentationNode, body: ContentBlock.() -> Unit) { val block = ContentNodeDirectLink(to) |