From: Lanius Trolling Date: Sat, 6 Apr 2024 12:47:07 +0000 (-0400) Subject: Rework plain-text tags X-Git-Url: https://gitweb.starshipfights.net/?a=commitdiff_plain;h=1edff7c16e00c706c1b6de869f7dce7523d5a856;p=factbooks Rework plain-text tags --- diff --git a/src/jvmMain/kotlin/info/mechyrdia/lore/parser_plain.kt b/src/jvmMain/kotlin/info/mechyrdia/lore/parser_plain.kt index f2376d2..093a91d 100644 --- a/src/jvmMain/kotlin/info/mechyrdia/lore/parser_plain.kt +++ b/src/jvmMain/kotlin/info/mechyrdia/lore/parser_plain.kt @@ -34,50 +34,49 @@ abstract class PlainTextFormattingProcessor : LexerTagFallback() +object PlainTextFormattingTag { + val asTags = LexerTags.empty() +} object PlainTextProcessor : PlainTextFormattingProcessor() { - private val inlineTags = setOf( - "b", - "i", - "u", - "s", - "color", - "ipa", - "code", - "h1", - "h2", - "h3", - "h4", - "h5", - "h6", - "align", - "aside", - "desc", - "link", - "extlink", - "lang", - ) - - private val blockTags = listOf( - "sup", - "sub", - "quote", - "blockquote", - "ul", - "ol", - "li", - "table", - "tr", - "td", - "th", + private val inlineTags = mapOf( + "b" to false, + "i" to false, + "u" to false, + "s" to false, + "color" to false, + "ipa" to false, + "code" to false, + "h1" to false, + "h2" to false, + "h3" to false, + "h4" to false, + "h5" to false, + "h6" to false, + "align" to false, + "aside" to false, + "desc" to false, + "link" to false, + "extlink" to false, + "lang" to false, + "sup" to true, + "sub" to true, + "quote" to true, + "blockquote" to true, + "ul" to true, + "ol" to true, + "li" to true, + "table" to true, + "tr" to true, + "td" to true, + "th" to true, ) override fun getTagBehavior(tag: String): PlainTextTagBehavior { - return when (tag) { - in inlineTags -> PlainTextTagBehavior.PASS_THROUGH - in blockTags -> PlainTextTagBehavior.PASS_THROUGH_SPACED - else -> PlainTextTagBehavior.ABSORB + return when (inlineTags[tag]) { + false -> PlainTextTagBehavior.PASS_THROUGH + true -> PlainTextTagBehavior.PASS_THROUGH_SPACED + null -> PlainTextTagBehavior.ABSORB } } } @@ -85,11 +84,7 @@ object PlainTextProcessor : PlainTextFormattingProcessor() { enum class CommentPlainTextFormattingTag(val type: LexerTagProcessor) { REPLY(LexerTagProcessor { env, _, subNodes -> val replyContent = env.processTree(subNodes) - val replyId = sanitizeId(replyContent) - if (replyId == null) - replyContent - else - ">>$replyId" + ">>$replyContent" }), ; @@ -101,7 +96,7 @@ enum class CommentPlainTextFormattingTag(val type: LexerTagProcessor