refactor(markdown): extract to attrToTag to simply renderInline

This commit is contained in:
ayn2op 2025-07-25 16:40:56 -04:00
parent 112d215684
commit e2dbda7095

View file

@ -160,22 +160,8 @@ 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) {
if start, end := "", ""; entering {
switch node.Attr {
case discordmd.AttrBold:
start, end = "[::b]", "[::B]"
case discordmd.AttrItalics:
start, end = "[::i]", "[::I]"
case discordmd.AttrUnderline:
start, end = "[::u]", "[::U]"
case discordmd.AttrStrikethrough:
start, end = "[::s]", "[::S]"
case discordmd.AttrMonospace:
start, end = "[::r]", "[::R]"
}
if start, end := attrToTag(node.Attr); entering && start != "" {
io.WriteString(w, start)
} else {
io.WriteString(w, end)
@ -214,3 +200,20 @@ func (r *renderer) renderEmoji(w io.Writer, node *discordmd.Emoji, entering bool
io.WriteString(w, "[-:-]")
}
}
func attrToTag(attr discordmd.Attribute) (string, string) {
switch attr {
case discordmd.AttrBold:
return "[::b]", "[::B]"
case discordmd.AttrItalics:
return "[::i]", "[::I]"
case discordmd.AttrUnderline:
return "[::u]", "[::U]"
case discordmd.AttrStrikethrough:
return "[::s]", "[::S]"
case discordmd.AttrMonospace:
return "[::r]", "[::R]"
default:
return "", ""
}
}