From 520aa810f35bd1726ef58a8594cf127e0b450154 Mon Sep 17 00:00:00 2001 From: ayn2op Date: Thu, 17 Jul 2025 00:28:02 -0400 Subject: [PATCH] refactor(markdown): simplify renderInline --- internal/markdown/renderer.go | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/internal/markdown/renderer.go b/internal/markdown/renderer.go index 096ca97..3c173a8 100644 --- a/internal/markdown/renderer.go +++ b/internal/markdown/renderer.go @@ -161,32 +161,29 @@ func (r *renderer) renderText(w io.Writer, node *ast.Text, entering bool, source } func (r *renderer) renderInline(w io.Writer, node *discordmd.Inline, entering bool) { + var start, end string if entering { switch node.Attr { case discordmd.AttrBold: - io.WriteString(w, "[::b]") + start = "[::b]" + end = "[::B]" case discordmd.AttrItalics: - io.WriteString(w, "[::i]") + start = "[::i]" + end = "[::I]" case discordmd.AttrUnderline: - io.WriteString(w, "[::u]") + start = "[::u]" + end = "[::U]" case discordmd.AttrStrikethrough: - io.WriteString(w, "[::s]") + start = "[::s]" + end = "[::S]" case discordmd.AttrMonospace: - io.WriteString(w, "[::r]") + start = "[::r]" + end = "[::R]" } + + io.WriteString(w, start) } else { - switch node.Attr { - case discordmd.AttrBold: - io.WriteString(w, "[::B]") - case discordmd.AttrItalics: - io.WriteString(w, "[::I]") - case discordmd.AttrUnderline: - io.WriteString(w, "[::U]") - case discordmd.AttrStrikethrough: - io.WriteString(w, "[::S]") - case discordmd.AttrMonospace: - io.WriteString(w, "[::R]") - } + io.WriteString(w, end) } }