From 2eac4625202c5be2d7332e5a7ad8c82082cce4d7 Mon Sep 17 00:00:00 2001 From: Lanius Trolling Date: Fri, 1 Mar 2024 15:34:46 -0500 Subject: [PATCH] Separate inline code and block code tags --- .../kotlin/info/mechyrdia/lore/parser.kt | 17 +++++++++++------ .../kotlin/info/mechyrdia/lore/parser_tags.kt | 11 +++++++++-- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/jvmMain/kotlin/info/mechyrdia/lore/parser.kt b/src/jvmMain/kotlin/info/mechyrdia/lore/parser.kt index 17230a0..d3379c1 100644 --- a/src/jvmMain/kotlin/info/mechyrdia/lore/parser.kt +++ b/src/jvmMain/kotlin/info/mechyrdia/lore/parser.kt @@ -60,13 +60,18 @@ sealed class TextParserState( appendTextRaw(newline) } + protected fun lastParagraph() { + if (!internalState.suppressEndParagraph) + appendTextRaw("

") + } + protected fun cancelEndParagraph() { internalState.suppressEndParagraph = true } protected fun cancelStartParagraph() { if (scope.write.endsWith("

")) - scope.write.deleteRange(scope.write.length - 3, scope.write.length) + scope.write.deleteRange(scope.write.length - "

".length, scope.write.length) } class Initial(scope: TextParserScope) : TextParserState(scope, listOf(), TextParserInternalState()) { @@ -102,7 +107,7 @@ sealed class TextParserState( override fun processEndOfText() { appendText(text.removeSuffix("\n")) if (text.isNotBlank()) - appendTextRaw("

") + lastParagraph() } } @@ -123,7 +128,7 @@ sealed class TextParserState( override fun processEndOfText() { appendText(text.removeSuffix("\n")) if (text.isNotBlank()) - appendTextRaw("

") + lastParagraph() } } @@ -158,7 +163,7 @@ sealed class TextParserState( override fun processEndOfText() { appendText("[$tag") - appendTextRaw("

") + lastParagraph() } } @@ -185,7 +190,7 @@ sealed class TextParserState( override fun processEndOfText() { appendText("[$tag=$param") - appendTextRaw("

") + lastParagraph() } } @@ -213,7 +218,7 @@ sealed class TextParserState( override fun processEndOfText() { appendText("[/$tag") - appendTextRaw("

") + lastParagraph() } } diff --git a/src/jvmMain/kotlin/info/mechyrdia/lore/parser_tags.kt b/src/jvmMain/kotlin/info/mechyrdia/lore/parser_tags.kt index a978416..22806f0 100644 --- a/src/jvmMain/kotlin/info/mechyrdia/lore/parser_tags.kt +++ b/src/jvmMain/kotlin/info/mechyrdia/lore/parser_tags.kt @@ -112,8 +112,15 @@ enum class TextParserFormattingTag(val type: TextParserTagType) { CODE( TextParserTagType.Direct( false, - { _, _ -> "
" },
-			{ _ -> "
" }, + { _, _ -> "" }, + { _ -> "" }, + ) + ), + CODE_BLOCK( + TextParserTagType.Direct( + true, + { _, _ -> "
" },
+			{ _ -> "
" }, ) ), H1( -- 2.25.1