Rework plain-text tags
authorLanius Trolling <lanius@laniustrolling.dev>
Sat, 6 Apr 2024 12:47:07 +0000 (08:47 -0400)
committerLanius Trolling <lanius@laniustrolling.dev>
Sat, 6 Apr 2024 12:48:07 +0000 (08:48 -0400)
src/jvmMain/kotlin/info/mechyrdia/lore/parser_plain.kt

index f2376d2688f6684bec96c3c8da3f552e69207e30..093a91d3dfa7797a855946690e39acb61fec54ca 100644 (file)
@@ -34,50 +34,49 @@ abstract class PlainTextFormattingProcessor : LexerTagFallback<PlainTextBuilderC
        }
 }
 
-val PlainTextFormattingTag = LexerTags.empty<PlainTextBuilderContext, PlainTextBuilderSubject>()
+object PlainTextFormattingTag {
+       val asTags = LexerTags.empty<PlainTextBuilderContext, PlainTextBuilderSubject>()
+}
 
 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<PlainTextBuilderContext, PlainTextBuilderSubject>) {
        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<PlainTextBu
 fun ParserTree.toFactbookPlainText(): String {
        return LexerTagEnvironment(
                Unit,
-               PlainTextFormattingTag,
+               PlainTextFormattingTag.asTags,
                PlainTextProcessor,
                PlainTextProcessor,
                PlainTextProcessor,