From 47634fecc59a1e6154f8c199f474d8242847deb3 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Thu, 5 May 2022 21:50:42 +0300 Subject: [PATCH] Fix MD parser lazy evaluation --- .../space/kscience/snark/SnarkMarkdownParser.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/space/kscience/snark/SnarkMarkdownParser.kt b/src/main/kotlin/space/kscience/snark/SnarkMarkdownParser.kt index 279dd07..436666b 100644 --- a/src/main/kotlin/space/kscience/snark/SnarkMarkdownParser.kt +++ b/src/main/kotlin/space/kscience/snark/SnarkMarkdownParser.kt @@ -18,13 +18,16 @@ object SnarkMarkdownParser:SnarkParser { private val markdownFlavor = CommonMarkFlavourDescriptor() private val markdownParser = MarkdownParser(markdownFlavor) - override suspend fun parse(bytes: ByteArray, meta: Meta): HtmlFragment = { + override suspend fun parse(bytes: ByteArray, meta: Meta): HtmlFragment { val src = bytes.decodeToString() - div{ - val parsedTree = markdownParser.buildMarkdownTreeFromString(src) + val parsedTree = markdownParser.buildMarkdownTreeFromString(src) + val htmlString = HtmlGenerator(src, parsedTree, markdownFlavor).generateHtml() - unsafe { - +HtmlGenerator(src, parsedTree, markdownFlavor).generateHtml() + return { + div{ + unsafe { + +htmlString + } } } }