c.Assert(got, qt.Contains, "<p>A «quote» and ‘another quote’ and a «quote with a ’nested’ quote» and a ‘quote with a «nested» quote’ and an ellipsis…</p>\n")
}
+// Issue #11045
+func TestTypographerImageAltText(t *testing.T) {
+ c := qt.New(t)
+
+ content := `
+
+`
+
+ confStr := `
+[markup]
+[markup.goldmark]
+
+`
+
+ cfg := config.FromTOMLConfigString(confStr)
+ conf := testconfig.GetTestConfig(nil, cfg)
+
+ b := convert(c, conf, content)
+ got := string(b.Bytes())
+
+ c.Assert(got, qt.Contains, "“They didn’t even say ‘hello’!” I exclaimed.")
+}
+
func unsafeConf() config.AllProvider {
cfg := config.FromTOMLConfigString(`
[markup]
_, _ = 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="`)
util.Prioritized(newLinkRenderer(e.cfg), 100),
))
}
+
+// Borrowed from Goldmark.
+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()
+}