diff --git a/src/parsing/renderer.go b/src/parsing/renderer.go index 63404577..c42df28f 100644 --- a/src/parsing/renderer.go +++ b/src/parsing/renderer.go @@ -2,6 +2,7 @@ package parsing import ( "io" + "regexp" "github.com/yuin/goldmark/ast" "github.com/yuin/goldmark/renderer" @@ -11,6 +12,8 @@ type plaintextRenderer struct{} var _ renderer.Renderer = plaintextRenderer{} +var backslashRegex = regexp.MustCompile("\\\\(?P[\\\\\\x60!\"#$%&'()*+,-./:;<=>?@\\[\\]^_{|}~])") + func (r plaintextRenderer) Render(w io.Writer, source []byte, n ast.Node) error { return ast.Walk(n, func(n ast.Node, entering bool) (ast.WalkStatus, error) { if !entering { @@ -20,8 +23,7 @@ func (r plaintextRenderer) Render(w io.Writer, source []byte, n ast.Node) error switch n.Kind() { case ast.KindText: n := n.(*ast.Text) - - _, err := w.Write(n.Text(source)) + _, err := w.Write(backslashRegex.ReplaceAll(n.Text(source), []byte("$1"))) if err != nil { return ast.WalkContinue, err }