Skip to content

Commit

Permalink
Remove inlineMarkdown representation
Browse files Browse the repository at this point in the history
...to speed up parsing speed and GC load.

Standalone renderer works, but no markdown tests.
  • Loading branch information
Oleg Baskakov committed Mar 23, 2024
1 parent 247e136 commit 3df1ccc
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.jetbrains.jewel.markdown

import org.intellij.lang.annotations.Language
import org.commonmark.node.Node

public sealed interface MarkdownBlock {

Expand Down Expand Up @@ -80,4 +80,4 @@ public interface BlockWithInlineMarkdown {
* [block-level elements][MarkdownBlock].
*/
@JvmInline
public value class InlineMarkdown(@Language("Markdown") public val content: String)
public value class InlineMarkdown(public val content: Node)
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@ public class MarkdownProcessor(private val extensions: List<MarkdownProcessorExt
return MarkdownBlock.HtmlBlock(content = literal.trimEnd('\n'))
}

private fun Node.contentsAsInlineMarkdown() =
InlineMarkdown(buildString { appendInlineMarkdownFrom(this@contentsAsInlineMarkdown) })
private fun Node.contentsAsInlineMarkdown() = InlineMarkdown(this)

private fun StringBuilder.appendInlineMarkdownFrom(
node: Node,
Expand Down Expand Up @@ -341,7 +340,7 @@ public class MarkdownProcessor(private val extensions: List<MarkdownProcessorExt
return "$backticks$this$backticks"
}

private fun InlineMarkdown.isBlank(): Boolean = content.isBlank()
private fun InlineMarkdown.isBlank(): Boolean = content.firstChild == null

private fun plainTextContents(node: Node): String = textContentRenderer.render(node)
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ public open class DefaultInlineMarkdownRenderer(rendererExtensions: List<Markdow

public constructor(vararg extensions: MarkdownProcessorExtension) : this(extensions.toList())

private val commonMarkParser =
Parser.builder().extensions(rendererExtensions.map { it.parserExtension }).build()

private val plainTextRenderer =
TextContentRenderer.builder()
.extensions(rendererExtensions.map { it.textRendererExtension })
Expand All @@ -43,7 +40,7 @@ public open class DefaultInlineMarkdownRenderer(rendererExtensions: List<Markdow
styling: InlinesStyling,
): AnnotatedString =
buildAnnotatedString {
val node = commonMarkParser.parse(inlineMarkdown.content)
val node = inlineMarkdown.content
appendInlineMarkdownFrom(node, styling)
}

Expand Down

0 comments on commit 3df1ccc

Please sign in to comment.