}
}
-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
}
}
}
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"
}),
;
fun ParserTree.toFactbookPlainText(): String {
return LexerTagEnvironment(
Unit,
- PlainTextFormattingTag,
+ PlainTextFormattingTag.asTags,
PlainTextProcessor,
PlainTextProcessor,
PlainTextProcessor,