aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Waters <awaters@nextfaze.com>2017-04-28 14:56:44 +0930
committerSimon Ogorodnik <sem-oro@yandex.ru>2017-05-02 15:48:38 +0300
commitacbe2f8c47a81c8e6046214f600ffdef24890fa6 (patch)
tree114626d3489c1eb74c78f7e36a3d95b3ef2ab62b
parent5d611906da72c6ceff3722d307cf663461c908e7 (diff)
downloaddokka-acbe2f8c47a81c8e6046214f600ffdef24890fa6.tar.gz
dokka-acbe2f8c47a81c8e6046214f600ffdef24890fa6.tar.bz2
dokka-acbe2f8c47a81c8e6046214f600ffdef24890fa6.zip
Fix missing whitespace around links and tokens in Markdown formatted text
-rw-r--r--core/src/main/kotlin/Kotlin/ContentBuilder.kt13
-rw-r--r--core/src/test/kotlin/format/MarkdownFormatTest.kt24
-rw-r--r--core/testdata/format/linksInEmphasis.kt13
-rw-r--r--core/testdata/format/linksInEmphasis.md23
-rw-r--r--core/testdata/format/linksInHeaders.kt24
-rw-r--r--core/testdata/format/linksInHeaders.md34
-rw-r--r--core/testdata/format/linksInStrong.kt13
-rw-r--r--core/testdata/format/linksInStrong.md23
-rw-r--r--core/testdata/format/markdownInLinks.html2
-rw-r--r--core/testdata/format/tokensInEmphasis.kt10
-rw-r--r--core/testdata/format/tokensInEmphasis.md20
-rw-r--r--core/testdata/format/tokensInHeaders.kt27
-rw-r--r--core/testdata/format/tokensInHeaders.md37
-rw-r--r--core/testdata/format/tokensInStrong.kt10
-rw-r--r--core/testdata/format/tokensInStrong.md20
15 files changed, 289 insertions, 4 deletions
diff --git a/core/src/main/kotlin/Kotlin/ContentBuilder.kt b/core/src/main/kotlin/Kotlin/ContentBuilder.kt
index 9c081d17..c124821e 100644
--- a/core/src/main/kotlin/Kotlin/ContentBuilder.kt
+++ b/core/src/main/kotlin/Kotlin/ContentBuilder.kt
@@ -87,9 +87,16 @@ fun buildContentTo(tree: MarkdownNode, target: ContentBlock, linkResolver: (Stri
parent.append(link)
}
}
- MarkdownTokenTypes.WHITE_SPACE,
+ MarkdownTokenTypes.WHITE_SPACE -> {
+ // Don't append first space if start of header (it is added during formatting later)
+ // v
+ // #### Some Heading
+ if (nodeStack.peek() !is ContentHeading || node.parent?.children?.first() != node) {
+ parent.append(ContentText(node.text))
+ }
+ }
MarkdownTokenTypes.EOL -> {
- if (keepWhitespace(nodeStack.peek()) && node.parent?.children?.last() != node) {
+ if (keepEol(nodeStack.peek()) && node.parent?.children?.last() != node) {
parent.append(ContentText(node.text))
}
}
@@ -148,7 +155,7 @@ fun buildContentTo(tree: MarkdownNode, target: ContentBlock, linkResolver: (Stri
private fun MarkdownNode.getLabelText() = children.filter { it.type == MarkdownTokenTypes.TEXT || it.type == MarkdownTokenTypes.EMPH }.joinToString("") { it.text }
-private fun keepWhitespace(node: ContentNode) = node is ContentParagraph || node is ContentSection || node is ContentBlockCode
+private fun keepEol(node: ContentNode) = node is ContentParagraph || node is ContentSection || node is ContentBlockCode
fun buildInlineContentTo(tree: MarkdownNode, target: ContentBlock, linkResolver: (String) -> ContentBlock) {
val inlineContent = tree.children.singleOrNull { it.type == MarkdownElementTypes.PARAGRAPH }?.children ?: listOf(tree)
diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt
index 16a81165..999d739b 100644
--- a/core/src/test/kotlin/format/MarkdownFormatTest.kt
+++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt
@@ -332,6 +332,30 @@ class MarkdownFormatTest {
}
}
+ @Test fun linksInEmphasis() {
+ verifyMarkdownNode("linksInEmphasis")
+ }
+
+ @Test fun linksInStrong() {
+ verifyMarkdownNode("linksInStrong")
+ }
+
+ @Test fun linksInHeaders() {
+ verifyMarkdownNode("linksInHeaders")
+ }
+
+ @Test fun tokensInEmphasis() {
+ verifyMarkdownNode("tokensInEmphasis")
+ }
+
+ @Test fun tokensInStrong() {
+ verifyMarkdownNode("tokensInStrong")
+ }
+
+ @Test fun tokensInHeaders() {
+ verifyMarkdownNode("tokensInHeaders")
+ }
+
private fun buildMultiplePlatforms(path: String): DocumentationModule {
val module = DocumentationModule("test")
val options = DocumentationOptions("", "html", generateIndexPages = false)
diff --git a/core/testdata/format/linksInEmphasis.kt b/core/testdata/format/linksInEmphasis.kt
new file mode 100644
index 00000000..3e2017d2
--- /dev/null
+++ b/core/testdata/format/linksInEmphasis.kt
@@ -0,0 +1,13 @@
+/**
+ * An emphasised class.
+ *
+ * _This class [Bar] is awesome._
+ *
+ * _Even more awesomer is the function [Bar.foo]_
+ *
+ * _[Bar.hello] is also OK_
+ */
+class Bar {
+ fun foo() {}
+ fun hello() {}
+}
diff --git a/core/testdata/format/linksInEmphasis.md b/core/testdata/format/linksInEmphasis.md
new file mode 100644
index 00000000..9441ef6a
--- /dev/null
+++ b/core/testdata/format/linksInEmphasis.md
@@ -0,0 +1,23 @@
+[test](test/index) / [Bar](test/-bar/index)
+
+# Bar
+
+`class Bar`
+
+An emphasised class.
+
+*This class [Bar](test/-bar/index) is awesome.*
+
+*Even more awesomer is the function [Bar.foo](test/-bar/foo)*
+
+*[Bar.hello](test/-bar/hello) is also OK*
+
+### Constructors
+
+| [&lt;init&gt;](test/-bar/-init-) | `Bar()`<br>An emphasised class. |
+
+### Functions
+
+| [foo](test/-bar/foo) | `fun foo(): Unit` |
+| [hello](test/-bar/hello) | `fun hello(): Unit` |
+
diff --git a/core/testdata/format/linksInHeaders.kt b/core/testdata/format/linksInHeaders.kt
new file mode 100644
index 00000000..18efd34b
--- /dev/null
+++ b/core/testdata/format/linksInHeaders.kt
@@ -0,0 +1,24 @@
+/**
+ * Some class with really useless documentation.
+ *
+ * # Beer o'clock - time to go to the [Bar]
+ *
+ * ## But __is [it](isitbeeroclock.com)__ really?
+ *
+ * ### [Bar.hello] to the [Bar.world]!
+ *
+ * #### _Kotlin is amazing, [Bar.none]_
+ *
+ * ##### We need to go [Bar.deeper]
+ *
+ * ###### End of the [Bar.line] - we need to go back!
+ */
+class Bar {
+ fun foo() {}
+ fun hello() {}
+ fun world() {}
+ fun kotlin() {}
+ fun none() {}
+ fun deeper() {}
+ fun line() {}
+}
diff --git a/core/testdata/format/linksInHeaders.md b/core/testdata/format/linksInHeaders.md
new file mode 100644
index 00000000..85d51356
--- /dev/null
+++ b/core/testdata/format/linksInHeaders.md
@@ -0,0 +1,34 @@
+[test](test/index) / [Bar](test/-bar/index)
+
+# Bar
+
+`class Bar`
+
+Some class with really useless documentation.
+
+# Beer o'clock - time to go to the [Bar](test/-bar/index)
+
+## But **is [it](isitbeeroclock.com)** really?
+
+### [Bar.hello](test/-bar/hello) to the [Bar.world](test/-bar/world)!
+
+#### *Kotlin is amazing, [Bar.none](test/-bar/none)*
+
+##### We need to go [Bar.deeper](test/-bar/deeper)
+
+###### End of the [Bar.line](test/-bar/line) - we need to go back!
+
+### Constructors
+
+| [&lt;init&gt;](test/-bar/-init-) | `Bar()`<br>Some class with really useless documentation. |
+
+### Functions
+
+| [deeper](test/-bar/deeper) | `fun deeper(): Unit` |
+| [foo](test/-bar/foo) | `fun foo(): Unit` |
+| [hello](test/-bar/hello) | `fun hello(): Unit` |
+| [kotlin](test/-bar/kotlin) | `fun kotlin(): Unit` |
+| [line](test/-bar/line) | `fun line(): Unit` |
+| [none](test/-bar/none) | `fun none(): Unit` |
+| [world](test/-bar/world) | `fun world(): Unit` |
+
diff --git a/core/testdata/format/linksInStrong.kt b/core/testdata/format/linksInStrong.kt
new file mode 100644
index 00000000..b9e295ec
--- /dev/null
+++ b/core/testdata/format/linksInStrong.kt
@@ -0,0 +1,13 @@
+/**
+ * A strong class.
+ *
+ * __This class [Bar] is awesome.__
+ *
+ * __Even more awesomer is the function [Bar.foo]__
+ *
+ * __[Bar.hello] is also OK__
+ */
+class Bar {
+ fun foo() {}
+ fun hello() {}
+}
diff --git a/core/testdata/format/linksInStrong.md b/core/testdata/format/linksInStrong.md
new file mode 100644
index 00000000..e98d31cc
--- /dev/null
+++ b/core/testdata/format/linksInStrong.md
@@ -0,0 +1,23 @@
+[test](test/index) / [Bar](test/-bar/index)
+
+# Bar
+
+`class Bar`
+
+A strong class.
+
+**This class [Bar](test/-bar/index) is awesome.**
+
+**Even more awesomer is the function [Bar.foo](test/-bar/foo)**
+
+**[Bar.hello](test/-bar/hello) is also OK**
+
+### Constructors
+
+| [&lt;init&gt;](test/-bar/-init-) | `Bar()`<br>A strong class. |
+
+### Functions
+
+| [foo](test/-bar/foo) | `fun foo(): Unit` |
+| [hello](test/-bar/hello) | `fun hello(): Unit` |
+
diff --git a/core/testdata/format/markdownInLinks.html b/core/testdata/format/markdownInLinks.html
index 9571f60f..6d2327be 100644
--- a/core/testdata/format/markdownInLinks.html
+++ b/core/testdata/format/markdownInLinks.html
@@ -9,6 +9,6 @@
<h1>foo</h1>
<a name="$foo()"></a>
<code><span class="keyword">fun </span><span class="identifier">foo</span><span class="symbol">(</span><span class="symbol">)</span><span class="symbol">: </span><span class="identifier">Unit</span></code>
-<p><a href="http://www.ibm.com">a<strong>b</strong><strong>d</strong>kas</a></p>
+<p><a href="http://www.ibm.com">a<strong>b</strong><strong>d</strong> kas </a></p>
</BODY>
</HTML>
diff --git a/core/testdata/format/tokensInEmphasis.kt b/core/testdata/format/tokensInEmphasis.kt
new file mode 100644
index 00000000..39362b37
--- /dev/null
+++ b/core/testdata/format/tokensInEmphasis.kt
@@ -0,0 +1,10 @@
+/**
+ * Another emphasised class.
+ *
+ * _This class, [Bar] is just meh._
+ *
+ * _For a semicolon; [Bar.foo] is for you!._
+ */
+class Bar {
+ fun foo() = ";"
+}
diff --git a/core/testdata/format/tokensInEmphasis.md b/core/testdata/format/tokensInEmphasis.md
new file mode 100644
index 00000000..79dde6f0
--- /dev/null
+++ b/core/testdata/format/tokensInEmphasis.md
@@ -0,0 +1,20 @@
+[test](test/index) / [Bar](test/-bar/index)
+
+# Bar
+
+`class Bar`
+
+Another emphasised class.
+
+*This class, [Bar](test/-bar/index) is just meh.*
+
+*For a semicolon; [Bar.foo](test/-bar/foo) is for you!.*
+
+### Constructors
+
+| [&lt;init&gt;](test/-bar/-init-) | `Bar()`<br>Another emphasised class. |
+
+### Functions
+
+| [foo](test/-bar/foo) | `fun foo(): String` |
+
diff --git a/core/testdata/format/tokensInHeaders.kt b/core/testdata/format/tokensInHeaders.kt
new file mode 100644
index 00000000..df62b024
--- /dev/null
+++ b/core/testdata/format/tokensInHeaders.kt
@@ -0,0 +1,27 @@
+/**
+ * Why did the token cross the road?
+ *
+ * # Because it was Beer o'clock @ [The.bar]
+ *
+ * ## But __waz *\[sic\]* [it](isitbeeroclock.com)__ really?
+ *
+ * ### [The.bar] has? [The.foo]est drinks ever!
+ *
+ * #### _[The.kotlinz] is [The.bestests], [Bar.none]_
+ *
+ * ##### So many lame code "puns" (in) [The.house]
+ *
+ * ###### End of the?? [Bar.line]! - we need to go back!
+ */
+class The {
+ object Bar {
+ fun none() {}
+ }
+
+ fun bar() {}
+ fun foo() {}
+ fun bestests() {}
+ fun kotlinz() {}
+ fun house() {}
+ fun line() {}
+}
diff --git a/core/testdata/format/tokensInHeaders.md b/core/testdata/format/tokensInHeaders.md
new file mode 100644
index 00000000..10c996cf
--- /dev/null
+++ b/core/testdata/format/tokensInHeaders.md
@@ -0,0 +1,37 @@
+[test](test/index) / [The](test/-the/index)
+
+# The
+
+`class The`
+
+Why did the token cross the road?
+
+# Because it was Beer o'clock @ [The.bar](test/-the/bar)
+
+## But **waz *\[sic\]* [it](isitbeeroclock.com)** really?
+
+### [The.bar](test/-the/bar) has? [The.foo](test/-the/foo)est drinks ever!
+
+#### *[The.kotlinz](test/-the/kotlinz) is [The.bestests](test/-the/bestests), [Bar.none](test/-the/-bar/none)*
+
+##### So many lame code "puns" (in) [The.house](test/-the/house)
+
+###### End of the?? [Bar.line](test/-the/line)! - we need to go back!
+
+### Types
+
+| [Bar](test/-the/-bar/index) | `object Bar` |
+
+### Constructors
+
+| [&lt;init&gt;](test/-the/-init-) | `The()`<br>Why did the token cross the road? |
+
+### Functions
+
+| [bar](test/-the/bar) | `fun bar(): Unit` |
+| [bestests](test/-the/bestests) | `fun bestests(): Unit` |
+| [foo](test/-the/foo) | `fun foo(): Unit` |
+| [house](test/-the/house) | `fun house(): Unit` |
+| [kotlinz](test/-the/kotlinz) | `fun kotlinz(): Unit` |
+| [line](test/-the/line) | `fun line(): Unit` |
+
diff --git a/core/testdata/format/tokensInStrong.kt b/core/testdata/format/tokensInStrong.kt
new file mode 100644
index 00000000..596a9ae8
--- /dev/null
+++ b/core/testdata/format/tokensInStrong.kt
@@ -0,0 +1,10 @@
+/**
+ * __YASC: [Yasc] Yet Another Strong Class__
+ *
+ * __This class, [Yasc] *is* just meh.__
+ *
+ * __For a semicolon; [Yasc.foo] is for you!.__
+ */
+class Yasc {
+ fun foo() = ";"
+}
diff --git a/core/testdata/format/tokensInStrong.md b/core/testdata/format/tokensInStrong.md
new file mode 100644
index 00000000..e1abe030
--- /dev/null
+++ b/core/testdata/format/tokensInStrong.md
@@ -0,0 +1,20 @@
+[test](test/index) / [Yasc](test/-yasc/index)
+
+# Yasc
+
+`class Yasc`
+
+**YASC: [Yasc](test/-yasc/index) Yet Another Strong Class**
+
+**This class, [Yasc](test/-yasc/index) *is* just meh.**
+
+**For a semicolon; [Yasc.foo](test/-yasc/foo) is for you!.**
+
+### Constructors
+
+| [&lt;init&gt;](test/-yasc/-init-) | `Yasc()`<br>**YASC: [Yasc](test/-yasc/index) Yet Another Strong Class** |
+
+### Functions
+
+| [foo](test/-yasc/foo) | `fun foo(): String` |
+