diff options
21 files changed, 55 insertions, 34 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) diff --git a/test/data/format/accessor.set.md b/test/data/format/accessor.set.md index 4350fcd3..e93766cd 100644 --- a/test/data/format/accessor.set.md +++ b/test/data/format/accessor.set.md @@ -3,6 +3,6 @@ # set -`set(value: String)` +`set(value: String)` diff --git a/test/data/format/annotations.md b/test/data/format/annotations.md index 04d16129..9e32eb24 100644 --- a/test/data/format/annotations.md +++ b/test/data/format/annotations.md @@ -22,5 +22,5 @@ ### Functions -| [bar](test/-foo/bar) | `inline fun bar(noinline notInlined: () -> Unit): Unit` | +| [bar](test/-foo/bar) | `inline fun bar(noinline notInlined: () -> Unit): Unit` | diff --git a/test/data/format/crossLanguage/kotlinExtendsJava.html b/test/data/format/crossLanguage/kotlinExtendsJava.html index 49a9ff8f..035b66b0 100644 --- a/test/data/format/crossLanguage/kotlinExtendsJava.html +++ b/test/data/format/crossLanguage/kotlinExtendsJava.html @@ -6,7 +6,7 @@ <a href="test/index">test</a> / <a href="test/test/index">test</a> / <a href="test/test/-bar/index">Bar</a><br/> <br/> <h1>Bar</h1> -<code><span class="keyword">class </span><span class="identifier">Bar</span><span class="symbol"> : </span><a href="test/test/-foo/index"><span class="identifier">Foo</span></a></code><br/> +<code><span class="keyword">class </span><span class="identifier">Bar</span> <span class="symbol">:</span> <a href="test/test/-foo/index"><span class="identifier">Foo</span></a></code><br/> <p>See <a href="test/test/-foo/xyzzy">xyzzy</a></p> <br/> <br/> diff --git a/test/data/format/extensions.class.md b/test/data/format/extensions.class.md index a4767ace..11ee9ba7 100644 --- a/test/data/format/extensions.class.md +++ b/test/data/format/extensions.class.md @@ -5,7 +5,7 @@ | [fn](test/foo/-string/fn) | `fun String.fn(): Unit` -`fun String.fn(x: Int): Unit` +`fun String.fn(x: Int): Unit` Function with receiver | diff --git a/test/data/format/functionWithDefaultParameter.md b/test/data/format/functionWithDefaultParameter.md index 43bd8d70..21e9eff7 100644 --- a/test/data/format/functionWithDefaultParameter.md +++ b/test/data/format/functionWithDefaultParameter.md @@ -3,6 +3,6 @@ # f -`fun f(x: String = ""): Unit` +`fun f(x: String = ""): Unit` diff --git a/test/data/format/javaLinkTag.html b/test/data/format/javaLinkTag.html index b5f03ef3..1a22a719 100644 --- a/test/data/format/javaLinkTag.html +++ b/test/data/format/javaLinkTag.html @@ -6,7 +6,7 @@ <a href="test/index">test</a> / <a href="test/test/index">test</a> / <a href="test/test/-foo/index">Foo</a><br/> <br/> <h1>Foo</h1> -<code><span class="keyword">open</span> <span class="keyword">class </span><span class="identifier">Foo</span><span class="symbol"> : </span><span class="identifier">Any</span></code><br/> +<code><span class="keyword">open</span> <span class="keyword">class </span><span class="identifier">Foo</span> <span class="symbol">:</span> <span class="identifier">Any</span></code><br/> <p>Call <a href="test/test/-foo/bar">#bar()</a> to do the job. </p> <br/> diff --git a/test/data/format/javaSeeTag.html b/test/data/format/javaSeeTag.html index 392b1d2e..0e4fb9a9 100644 --- a/test/data/format/javaSeeTag.html +++ b/test/data/format/javaSeeTag.html @@ -6,7 +6,7 @@ <a href="test/index">test</a> / <a href="test/test/index">test</a> / <a href="test/test/-foo/index">Foo</a><br/> <br/> <h1>Foo</h1> -<code><span class="keyword">open</span> <span class="keyword">class </span><span class="identifier">Foo</span><span class="symbol"> : </span><span class="identifier">Any</span></code><br/> +<code><span class="keyword">open</span> <span class="keyword">class </span><span class="identifier">Foo</span> <span class="symbol">:</span> <span class="identifier">Any</span></code><br/> <p></p> <strong>See Also</strong><br/> <a href="test/test/-foo/bar">#bar</a><br/> diff --git a/test/data/format/javaSupertype.html b/test/data/format/javaSupertype.html index f49a6e0f..92a53a44 100644 --- a/test/data/format/javaSupertype.html +++ b/test/data/format/javaSupertype.html @@ -6,7 +6,7 @@ <a href="test/index">test</a> / <a href="test/test/index">test</a> / <a href="test/test/-c/index">C</a> / <a href="test/test/-c/-bar/index">Bar</a><br/> <br/> <h1>Bar</h1> -<code><span class="keyword">public</span> <span class="keyword">open</span> <span class="keyword">class </span><span class="identifier">Bar</span><span class="symbol"> : </span><a href="test/test/-c/-foo"><span class="identifier">Foo</span></a></code><br/> +<code><span class="keyword">public</span> <span class="keyword">open</span> <span class="keyword">class </span><span class="identifier">Bar</span> <span class="symbol">:</span> <a href="test/test/-c/-foo"><span class="identifier">Foo</span></a></code><br/> <br/> <br/> <h3>Functions</h3> @@ -16,7 +16,7 @@ <td> <a href="test/test/-c/-bar/return-foo">returnFoo</a></td> <td> -<code><span class="keyword">public</span> <span class="keyword">open</span> <span class="keyword">fun </span><span class="identifier">returnFoo</span><span class="symbol">(</span><span class="identifier">foo</span><span class="symbol">: </span><a href="test/test/-c/-foo"><span class="identifier">Foo</span></a><span class="symbol">)</span><span class="symbol">: </span><a href="test/test/-c/-foo"><span class="identifier">Foo</span></a></code></td> +<code><span class="keyword">public</span> <span class="keyword">open</span> <span class="keyword">fun </span><span class="identifier">returnFoo</span><span class="symbol">(</span><span class="identifier">foo</span><span class="symbol">:</span> <a href="test/test/-c/-foo"><span class="identifier">Foo</span></a><span class="symbol">)</span><span class="symbol">: </span><a href="test/test/-c/-foo"><span class="identifier">Foo</span></a></code></td> </tr> </tbody> </table> diff --git a/test/data/format/overloads.html b/test/data/format/overloads.html index 9189483d..27863bac 100644 --- a/test/data/format/overloads.html +++ b/test/data/format/overloads.html @@ -16,8 +16,8 @@ <td> <a href="test/f">f</a></td> <td> -<code><span class="keyword">fun </span><span class="identifier">f</span><span class="symbol">(</span><span class="identifier">x</span><span class="symbol">: </span><span class="identifier">Int</span><span class="symbol">)</span><span class="symbol">: </span><span class="identifier">Unit</span></code><br/> -<code><span class="keyword">fun </span><span class="identifier">f</span><span class="symbol">(</span><span class="identifier">x</span><span class="symbol">: </span><span class="identifier">String</span><span class="symbol">)</span><span class="symbol">: </span><span class="identifier">Unit</span></code><p>Performs an action on x.</p> +<code><span class="keyword">fun </span><span class="identifier">f</span><span class="symbol">(</span><span class="identifier">x</span><span class="symbol">:</span> <span class="identifier">Int</span><span class="symbol">)</span><span class="symbol">: </span><span class="identifier">Unit</span></code><br/> +<code><span class="keyword">fun </span><span class="identifier">f</span><span class="symbol">(</span><span class="identifier">x</span><span class="symbol">:</span> <span class="identifier">String</span><span class="symbol">)</span><span class="symbol">: </span><span class="identifier">Unit</span></code><p>Performs an action on x.</p> </td> </tr> </tbody> diff --git a/test/data/format/overloadsWithDescription.html b/test/data/format/overloadsWithDescription.html index db63b262..a0a27b8c 100644 --- a/test/data/format/overloadsWithDescription.html +++ b/test/data/format/overloadsWithDescription.html @@ -6,8 +6,8 @@ <a href="test/index">test</a> / <a href="test/f">f</a><br/> <br/> <h1>f</h1> -<code><span class="keyword">fun </span><span class="identifier">f</span><span class="symbol">(</span><span class="identifier">x</span><span class="symbol">: </span><span class="identifier">Int</span><span class="symbol">)</span><span class="symbol">: </span><span class="identifier">Unit</span></code><br/> -<code><span class="keyword">fun </span><span class="identifier">f</span><span class="symbol">(</span><span class="identifier">x</span><span class="symbol">: </span><span class="identifier">String</span><span class="symbol">)</span><span class="symbol">: </span><span class="identifier">Unit</span></code><br/> +<code><span class="keyword">fun </span><span class="identifier">f</span><span class="symbol">(</span><span class="identifier">x</span><span class="symbol">:</span> <span class="identifier">Int</span><span class="symbol">)</span><span class="symbol">: </span><span class="identifier">Unit</span></code><br/> +<code><span class="keyword">fun </span><span class="identifier">f</span><span class="symbol">(</span><span class="identifier">x</span><span class="symbol">:</span> <span class="identifier">String</span><span class="symbol">)</span><span class="symbol">: </span><span class="identifier">Unit</span></code><br/> <p>Performs an action on <a href="test/f#x">x</a>.</p> <h3>Description</h3> <p>This is a long description.</p> diff --git a/test/data/format/overloadsWithDifferentDescriptions.html b/test/data/format/overloadsWithDifferentDescriptions.html index 06431d15..a2cc21f4 100644 --- a/test/data/format/overloadsWithDifferentDescriptions.html +++ b/test/data/format/overloadsWithDifferentDescriptions.html @@ -6,7 +6,7 @@ <a href="test/index">test</a> / <a href="test/f">f</a><br/> <br/> <h1>f</h1> -<code><span class="keyword">fun </span><span class="identifier">f</span><span class="symbol">(</span><span class="identifier">x</span><span class="symbol">: </span><span class="identifier">Int</span><span class="symbol">)</span><span class="symbol">: </span><span class="identifier">Unit</span></code><br/> +<code><span class="keyword">fun </span><span class="identifier">f</span><span class="symbol">(</span><span class="identifier">x</span><span class="symbol">:</span> <span class="identifier">Int</span><span class="symbol">)</span><span class="symbol">: </span><span class="identifier">Unit</span></code><br/> <p>Performs an action on x.</p> <h3>Description</h3> <p>This is a long description.</p> @@ -17,7 +17,7 @@ <code>x</code> - the int value to perform the action on.<br/> <br/> <br/> -<code><span class="keyword">fun </span><span class="identifier">f</span><span class="symbol">(</span><span class="identifier">x</span><span class="symbol">: </span><span class="identifier">String</span><span class="symbol">)</span><span class="symbol">: </span><span class="identifier">Unit</span></code><br/> +<code><span class="keyword">fun </span><span class="identifier">f</span><span class="symbol">(</span><span class="identifier">x</span><span class="symbol">:</span> <span class="identifier">String</span><span class="symbol">)</span><span class="symbol">: </span><span class="identifier">Unit</span></code><br/> <p>Performs an action on x.</p> <h3>Description</h3> <p>This is a long description.</p> diff --git a/test/data/format/paramTag.md b/test/data/format/paramTag.md index aacda66f..882083fe 100644 --- a/test/data/format/paramTag.md +++ b/test/data/format/paramTag.md @@ -3,7 +3,7 @@ # f -`fun f(x: String, y: Int): Unit` +`fun f(x: String, y: Int): Unit` ### Parameters diff --git a/test/data/format/parameterAnchor.html b/test/data/format/parameterAnchor.html index 2b2fec08..445566e8 100644 --- a/test/data/format/parameterAnchor.html +++ b/test/data/format/parameterAnchor.html @@ -6,7 +6,7 @@ <a href="test/index">test</a> / <a href="test/process-files">processFiles</a><br/> <br/> <h1>processFiles</h1> -<code><span class="keyword">public</span> <span class="keyword">fun </span><span class="symbol"><</span><span class="identifier">T</span><span class="symbol">> </span><span class="identifier">processFiles</span><span class="symbol">(</span><span class="identifier">processor</span><span class="symbol">: </span><span class="symbol">(</span><span class="symbol">)</span> <span class="symbol">-></span> <span class="identifier">T</span><span class="symbol">)</span><span class="symbol">: </span><span class="identifier">List</span><span class="symbol"><</span><span class="identifier">T</span><span class="symbol">></span></code><br/> +<code><span class="keyword">public</span> <span class="keyword">fun </span><span class="symbol"><</span><span class="identifier">T</span><span class="symbol">> </span><span class="identifier">processFiles</span><span class="symbol">(</span><span class="identifier">processor</span><span class="symbol">:</span> <span class="symbol">(</span><span class="symbol">)</span> <span class="symbol">-></span> <span class="identifier">T</span><span class="symbol">)</span><span class="symbol">: </span><span class="identifier">List</span><span class="symbol"><</span><span class="identifier">T</span><span class="symbol">></span></code><br/> <p>Runs <a href="test/process-files#processor">processor</a> for each file and collects its results into single list</p> <h3>Parameters</h3> <a name="processor"></a> diff --git a/test/data/format/typeLink.html b/test/data/format/typeLink.html index 06c31454..9df615c8 100644 --- a/test/data/format/typeLink.html +++ b/test/data/format/typeLink.html @@ -6,7 +6,7 @@ <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><span class="symbol"> : </span><a href="test/-foo/index"><span class="identifier">Foo</span></a></code><br/> +<code><span class="keyword">class </span><span class="identifier">Bar</span> <span class="symbol">:</span> <a href="test/-foo/index"><span class="identifier">Foo</span></a></code><br/> <br/> <br/> <h3>Constructors</h3> diff --git a/test/data/format/typeParameterBounds.md b/test/data/format/typeParameterBounds.md index 91fd456a..3962f911 100644 --- a/test/data/format/typeParameterBounds.md +++ b/test/data/format/typeParameterBounds.md @@ -3,7 +3,7 @@ # generic -`public fun <T : R, R> generic(): Unit` +`public fun <T : R, R> generic(): Unit` generic function diff --git a/test/data/format/varargsFunction.md b/test/data/format/varargsFunction.md index 7a087428..723437aa 100644 --- a/test/data/format/varargsFunction.md +++ b/test/data/format/varargsFunction.md @@ -3,6 +3,6 @@ # f -`fun f(vararg s: String): Unit` +`fun f(vararg s: String): Unit` |