diff --git a/extension/_test/typographer.txt b/extension/_test/typographer.txt index 556353c..cf5fea6 100644 --- a/extension/_test/typographer.txt +++ b/extension/_test/typographer.txt @@ -134,3 +134,10 @@ We're talking about the internet --- 'net for short. Let's rock 'n roll! //- - - - - - - - -//

We’re talking about the internet — ’net for short. Let’s rock ’n roll!

//= = = = = = = = = = = = = = = = = = = = = = = =// + +19: Quotes in alt text +//- - - - - - - - -// +![Nice & day, **isn't** it?](https://example.com/image.jpg) +//- - - - - - - - -// +

Nice & day, isn’t it?

+//= = = = = = = = = = = = = = = = = = = = = = = =// diff --git a/renderer/html/html.go b/renderer/html/html.go index 6dd2bbd..65ffc72 100644 --- a/renderer/html/html.go +++ b/renderer/html/html.go @@ -571,7 +571,7 @@ func (r *Renderer) renderImage(w util.BufWriter, source []byte, node ast.Node, e _, _ = w.Write(util.EscapeHTML(util.URLEscape(n.Destination, true))) } _, _ = w.WriteString(`" alt="`) - _, _ = w.Write(util.EscapeHTML(n.Text(source))) + _, _ = w.Write(nodeToHTMLText(n, source)) _ = w.WriteByte('"') if n.Title != nil { _, _ = w.WriteString(` title="`) @@ -840,3 +840,17 @@ func IsDangerousURL(url []byte) bool { return bytes.HasPrefix(url, bJs) || bytes.HasPrefix(url, bVb) || bytes.HasPrefix(url, bFile) || bytes.HasPrefix(url, bData) } + +func nodeToHTMLText(n ast.Node, source []byte) []byte { + var buf bytes.Buffer + for c := n.FirstChild(); c != nil; c = c.NextSibling() { + if s, ok := c.(*ast.String); ok && s.IsCode() { + buf.Write(s.Text(source)) + } else if !c.HasChildren() { + buf.Write(util.EscapeHTML(c.Text(source))) + } else { + buf.Write(nodeToHTMLText(c, source)) + } + } + return buf.Bytes() +}