aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main
diff options
context:
space:
mode:
authorMarcin Aman <maman@virtuslab.com>2020-08-19 20:09:12 +0200
committerSebastian Sellmair <34319766+sellmair@users.noreply.github.com>2020-08-28 15:37:55 +0200
commitde809e8076b3cde06dc29328298112ed4a7026b3 (patch)
tree8773b5f9d0d148d366cd7f250c268716b156b55d /plugins/base/src/main
parente64cb9bfbef093bcc4046a5081393f3c9778b42a (diff)
downloaddokka-de809e8076b3cde06dc29328298112ed4a7026b3.tar.gz
dokka-de809e8076b3cde06dc29328298112ed4a7026b3.tar.bz2
dokka-de809e8076b3cde06dc29328298112ed4a7026b3.zip
Draft for improving code formatting #1346
Diffstat (limited to 'plugins/base/src/main')
-rw-r--r--plugins/base/src/main/kotlin/parsers/MarkdownParser.kt13
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt4
-rw-r--r--plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt11
-rw-r--r--plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt14
4 files changed, 17 insertions, 25 deletions
diff --git a/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt b/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt
index 8422d3be..53ab6bde 100644
--- a/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt
+++ b/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt
@@ -280,11 +280,13 @@ class MarkdownParser(
MarkdownElementTypes.IMAGE -> imagesHandler(node)
MarkdownTokenTypes.HARD_LINE_BREAK -> DocTagsFromIElementFactory.getInstance(node.type)
MarkdownTokenTypes.CODE_FENCE_CONTENT,
- MarkdownTokenTypes.CODE_LINE,
+ MarkdownTokenTypes.CODE_LINE -> DocTagsFromIElementFactory.getInstance(
+ MarkdownTokenTypes.TEXT,
+ body = text.substring(node.startOffset, node.endOffset)
+ )
MarkdownTokenTypes.TEXT -> DocTagsFromIElementFactory.getInstance(
MarkdownTokenTypes.TEXT,
- body = text
- .substring(node.startOffset, node.endOffset).transform()
+ body = text.substring(node.startOffset, node.endOffset).transform()
)
MarkdownElementTypes.MARKDOWN_FILE -> if (node.children.size == 1) visitNode(node.children.first()) else defaultHandler(
node
@@ -339,11 +341,12 @@ class MarkdownParser(
children += this[index]
} else {
val startOffset = this[index].startOffset
+ val type = this[index].type
while (index < this.lastIndex) {
if (this.isNotLeaf(index + 1) || this[index + 1].startOffset != this[index].endOffset) {
val endOffset = this[index].endOffset
if (text.substring(startOffset, endOffset).transform().trim().isNotEmpty())
- children += LeafASTNode(MarkdownTokenTypes.TEXT, startOffset, endOffset)
+ children += LeafASTNode(type, startOffset, endOffset)
break
}
index++
@@ -351,7 +354,7 @@ class MarkdownParser(
if (index == this.lastIndex) {
val endOffset = this[index].endOffset
if (text.substring(startOffset, endOffset).transform().trim().isNotEmpty())
- children += LeafASTNode(MarkdownTokenTypes.TEXT, startOffset, endOffset)
+ children += LeafASTNode(type, startOffset, endOffset)
}
}
index++
diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
index 0118dcfd..878432b4 100644
--- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
+++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
@@ -604,7 +604,9 @@ open class HtmlRenderer(
div("sample-container") {
code(code.style.joinToString(" ") { it.toString().toLowerCase() }) {
attributes["theme"] = "idea"
- code.children.forEach { buildContentNode(it, pageContext) }
+ pre {
+ code.children.forEach { buildContentNode(it, pageContext) }
+ }
}
}
}
diff --git a/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt b/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt
index 0c88b3c6..51ab0858 100644
--- a/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt
+++ b/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt
@@ -102,7 +102,7 @@ object DocTagToContentConverter : CommentsToContentConverter {
styles
)
)
- is BlockQuote -> listOf(
+ is BlockQuote, is Pre, is CodeBlock -> listOf(
ContentCodeBlock(
buildChildren(docTag),
"",
@@ -120,15 +120,6 @@ object DocTagToContentConverter : CommentsToContentConverter {
styles
)
)
- is CodeBlock -> listOf(
- ContentCodeBlock(
- buildChildren(docTag),
- "",
- dci,
- sourceSets.toDisplaySourceSets(),
- styles
- )
- )
is Img -> listOf(
ContentEmbeddedResource(
address = docTag.params["href"]!!,
diff --git a/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt b/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt
index 8262b3c6..b9c328dc 100644
--- a/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt
+++ b/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt
@@ -151,7 +151,7 @@ class JavadocParser(
is PsiInlineDocTag -> convertInlineDocTag(this)
is PsiDocParamRef -> toDocumentationLinkString()
is PsiDocTagValue,
- is LeafPsiElement -> (if ((prevSibling as? PsiDocToken)?.isLeadingAsterisk() == true) text?.trim() else text)?.takeUnless { it.isBlank() }
+ is LeafPsiElement -> text
else -> null
}
@@ -190,8 +190,8 @@ class JavadocParser(
}
}
- private fun createBlock(element: Element): DocTag? {
- val children = element.childNodes().mapNotNull { convertHtmlNode(it) }
+ private fun createBlock(element: Element, insidePre: Boolean = false): DocTag? {
+ val children = element.childNodes().mapNotNull { convertHtmlNode(it, insidePre = insidePre || element.tagName() == "pre") }
fun ifChildrenPresent(operation: () -> DocTag): DocTag? {
return if (children.isNotEmpty()) operation() else null
}
@@ -203,11 +203,7 @@ class JavadocParser(
"index" -> Index(children)
"i" -> ifChildrenPresent { I(children) }
"em" -> Em(children)
- "code" -> ifChildrenPresent {
- if (element.hasAttr("data-inline")) CodeInline(children) else CodeBlock(
- children
- )
- }
+ "code" -> ifChildrenPresent { CodeInline(children) }
"pre" -> Pre(children)
"ul" -> ifChildrenPresent { Ul(children) }
"ol" -> ifChildrenPresent { Ol(children) }
@@ -224,7 +220,7 @@ class JavadocParser(
}
override fun invoke(elements: Iterable<PsiElement>, asParagraph: Boolean): List<DocTag> =
- Jsoup.parseBodyFragment(elements.mapNotNull { it.stringify() }.joinToString(" ", prefix = if (asParagraph) "<p>" else ""))
+ Jsoup.parseBodyFragment(elements.mapNotNull { it.stringify() }.joinToString("\n", prefix = if (asParagraph) "<p>" else ""))
.body().childNodes().mapNotNull { convertHtmlNode(it) }
}