From 3693c2f7e75822ad035007f98c8d55006d9eabbd Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Thu, 16 Mar 2017 21:07:29 +0300 Subject: Fix p tag closing in HTML format's --- core/src/main/kotlin/Formats/HtmlFormatService.kt | 6 ++-- .../Formats/KotlinWebsiteHtmlFormatService.kt | 30 ++++++-------------- .../main/kotlin/Formats/StructuredFormatService.kt | 32 ++++++++++++++-------- core/testdata/format/overloadsWithDescription.html | 3 +- .../format/overloadsWithDifferentDescriptions.html | 9 +++--- core/testdata/format/parameterAnchor.html | 3 +- 6 files changed, 37 insertions(+), 46 deletions(-) (limited to 'core') diff --git a/core/src/main/kotlin/Formats/HtmlFormatService.kt b/core/src/main/kotlin/Formats/HtmlFormatService.kt index 6819e652..12d39af3 100644 --- a/core/src/main/kotlin/Formats/HtmlFormatService.kt +++ b/core/src/main/kotlin/Formats/HtmlFormatService.kt @@ -46,6 +46,8 @@ open class HtmlOutputBuilder(to: StringBuilder, override fun appendParagraph(body: () -> Unit) = wrapInTag("p", body, newlineBeforeOpen = true, newlineAfterClose = true) + override fun appendSoftParagraph(body: () -> Unit) = appendParagraph(body) + override fun appendLine() { to.appendln("
") } @@ -89,9 +91,7 @@ open class HtmlOutputBuilder(to: StringBuilder, } override fun ensureParagraph() { - if (!to.endsWith("

") && !to.endsWith("

")) { - to.append("\n

") - } + } } diff --git a/core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt b/core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt index d2962911..7b9279b2 100644 --- a/core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt +++ b/core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt @@ -7,14 +7,10 @@ import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty import java.nio.file.Path -private object EmptyHtmlTemplateServie : HtmlTemplateService { - override fun appendFooter(to: StringBuilder) { +private object EmptyHtmlTemplateService : HtmlTemplateService { + override fun appendFooter(to: StringBuilder) {} - } - - override fun appendHeader(to: StringBuilder, title: String?, basePath: Path) { - - } + override fun appendHeader(to: StringBuilder, title: String?, basePath: Path) {} } @@ -24,13 +20,11 @@ open class KotlinWebsiteHtmlOutputBuilder(to: StringBuilder, languageService: LanguageService, extension: String, impliedPlatforms: List) - : HtmlOutputBuilder(to, location, locationService, languageService, extension, impliedPlatforms, EmptyHtmlTemplateServie) { + : HtmlOutputBuilder(to, location, locationService, languageService, extension, impliedPlatforms, EmptyHtmlTemplateService) { private var needHardLineBreaks = false private var insideDiv = 0 - override fun appendLine() { - - } + override fun appendLine() {} override fun appendBreadcrumbs(path: Iterable) { if (path.count() > 1) { @@ -42,8 +36,6 @@ open class KotlinWebsiteHtmlOutputBuilder(to: StringBuilder, override fun appendCode(body: () -> Unit) = wrapIfNotEmpty("", "", body) - override fun appendStrikethrough(body: () -> Unit) = wrapInTag("s", body) - protected fun div(to: StringBuilder, cssClass: String, otherAttributes: String = "", block: () -> Unit) { to.append("

") @@ -68,9 +60,7 @@ open class KotlinWebsiteHtmlOutputBuilder(to: StringBuilder, override fun appendAsOverloadGroup(to: StringBuilder, platforms: Set, block: () -> Unit) { div(to, "overload-group", calculateDataAttributes(platforms)) { - ensureParagraph() block() - ensureParagraph() } } @@ -158,9 +148,7 @@ open class KotlinWebsiteHtmlOutputBuilder(to: StringBuilder, appendTableRow(block) } - override fun appendPlatforms(platforms: Set) { - - } + override fun appendPlatforms(platforms: Set) {} override fun appendBreadcrumbSeparator() { to.append(" / ") @@ -181,11 +169,9 @@ open class KotlinWebsiteHtmlOutputBuilder(to: StringBuilder, class KotlinWebsiteHtmlFormatService @Inject constructor(locationService: LocationService, signatureGenerator: LanguageService, @Named(impliedPlatformsName) impliedPlatforms: List) - : HtmlFormatService(locationService, signatureGenerator, EmptyHtmlTemplateServie, impliedPlatforms) { + : HtmlFormatService(locationService, signatureGenerator, EmptyHtmlTemplateService, impliedPlatforms) { - override fun enumerateSupportFiles(callback: (String, String) -> Unit) { - - } + override fun enumerateSupportFiles(callback: (String, String) -> Unit) {} override fun createOutputBuilder(to: StringBuilder, location: Location) = KotlinWebsiteHtmlOutputBuilder(to, location, locationService, languageService, extension, impliedPlatforms) diff --git a/core/src/main/kotlin/Formats/StructuredFormatService.kt b/core/src/main/kotlin/Formats/StructuredFormatService.kt index 743a6ac8..961c2c26 100644 --- a/core/src/main/kotlin/Formats/StructuredFormatService.kt +++ b/core/src/main/kotlin/Formats/StructuredFormatService.kt @@ -50,6 +50,12 @@ abstract class StructuredOutputBuilder(val to: StringBuilder, abstract fun appendBlockCode(language: String, body: () -> Unit) abstract fun appendHeader(level: Int = 1, body: () -> Unit) abstract fun appendParagraph(body: () -> Unit) + + open fun appendSoftParagraph(body: () -> Unit) { + ensureParagraph() + body() + } + abstract fun appendLine() abstract fun appendAnchor(anchor: String) @@ -288,9 +294,10 @@ abstract class StructuredOutputBuilder(val to: StringBuilder, formatOverloadGroup(breakdownBySummary.values.single()) } else { for ((_, items) in breakdownBySummary) { - ensureParagraph() - appendAsOverloadGroup(to, platformsOfItems(items)) { - formatOverloadGroup(items) + appendSoftParagraph { + appendAsOverloadGroup(to, platformsOfItems(items)) { + formatOverloadGroup(items) + } } } } @@ -414,12 +421,12 @@ abstract class StructuredOutputBuilder(val to: StringBuilder, subjectSections.forEach { val subjectName = it.subjectName if (subjectName != null) { - ensureParagraph() - - appendAnchor(subjectName) - appendCode { to.append(subjectName) } - to.append(" - ") - appendContent(it) + appendSoftParagraph { + appendAnchor(subjectName) + appendCode { to.append(subjectName) } + to.append(" - ") + appendContent(it) + } } } } @@ -443,9 +450,10 @@ abstract class StructuredOutputBuilder(val to: StringBuilder, } for (member in node.members.sortedBy(DocumentationNode::priority)) { - ensureParagraph() - appendAsOverloadGroup(to, platformsOfItems(listOf(member))) { - formatSubNodeOfGroup(member) + appendSoftParagraph { + appendAsOverloadGroup(to, platformsOfItems(listOf(member))) { + formatSubNodeOfGroup(member) + } } } } diff --git a/core/testdata/format/overloadsWithDescription.html b/core/testdata/format/overloadsWithDescription.html index 09b92e66..fe98b8fe 100644 --- a/core/testdata/format/overloadsWithDescription.html +++ b/core/testdata/format/overloadsWithDescription.html @@ -14,8 +14,7 @@

Performs an action on x.

This is a long description.

Parameters

-

-x - the value to perform the action on. +x - the value to perform the action on.

diff --git a/core/testdata/format/overloadsWithDifferentDescriptions.html b/core/testdata/format/overloadsWithDifferentDescriptions.html index 4d621d33..947c72d6 100644 --- a/core/testdata/format/overloadsWithDifferentDescriptions.html +++ b/core/testdata/format/overloadsWithDifferentDescriptions.html @@ -7,22 +7,21 @@ test / f

f

-

fun f(x: Int): Unit

Performs an action on x.

This is a long description.

Parameters

-

-x - the int value to perform the action on. +x - the int value to perform the action on.

+

fun f(x: String): Unit

Performs an action on x.

This is a long description.

Parameters

-

-x - the string value to perform the action on. +x - the string value to perform the action on.

+

diff --git a/core/testdata/format/parameterAnchor.html b/core/testdata/format/parameterAnchor.html index 15532a6d..ecb89fe6 100644 --- a/core/testdata/format/parameterAnchor.html +++ b/core/testdata/format/parameterAnchor.html @@ -11,8 +11,7 @@ fun <T> processFiles(processor: () -> T): List<T>

Runs processor for each file and collects its results into single list

Parameters

-

-processor - function to receive context for symbol resolution and file for processing +processor - function to receive context for symbol resolution and file for processing

-- cgit