Skip to content

Commit

Permalink
fix: escape characters
Browse files Browse the repository at this point in the history
closes #106
closes #274
closes #311
  • Loading branch information
caarlos0 committed Jul 16, 2024
1 parent 23f13a3 commit fb8db4a
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion ansi/baseelement.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,28 @@ func (e *BaseElement) doRender(w io.Writer, p termenv.Profile, st1, st2 StylePri
return err
}
}
renderText(w, p, st2, s)
renderText(w, p, st2, escapeReplacer.Replace(s))
return nil
}

// https://www.markdownguide.org/basic-syntax/#characters-you-can-escape
var escapeReplacer = strings.NewReplacer(
"\\\\", "\\",
"\\`", "`",
"\\*", "*",
"\\_", "_",
"\\{", "{",
"\\}", "}",
"\\[", "[",
"\\]", "]",
"\\<", "<",
"\\>", ">",
"\\(", "(",
"\\)", ")",
"\\#", "#",
"\\+", "+",
"\\-", "-",
"\\.", ".",
"\\!", "!",
"\\|", "|",
)

0 comments on commit fb8db4a

Please sign in to comment.