MD text renderer: handle backslashes
Handles the same characters as the html renderer.
This commit is contained in:
parent
f8e7779b7d
commit
80f0e3b176
|
@ -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<char>[\\\\\\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
|
||||
}
|
||||
|
|
Reference in New Issue