fix: H1 conversion leaves markdown and unfinished tags alone

ConvertContentH1 rewrites content only when it is HTML; a markdown
source, its code samples included, is kept byte for byte and only its
rendered content_html is converted, on API saves, imports,
journal:fix-headings and translations. ConvertH1 and SetImageAlt keep
the bytes of an unfinished tag at the end of the input.
This commit is contained in:
Jakub Zych
2026-11-04 23:14:42 +01:00
parent 45d66f6071
commit 0e739c882e
6 changed files with 123 additions and 11 deletions

View File

@@ -44,4 +44,13 @@ func TestSetImageAltEdges(t *testing.T) {
t.Errorf("SetImageAlt(%q, %q) = %q %d %v", tc.html, tc.src, out, n, old)
}
}
// L1 WR-03: the bytes of an unfinished tag at the end are kept.
for _, in := range []string{"p a <img", "x<y", `<img src="b.jpg"><p>a <b`} {
if out, n, _ := SetImageAlt(in, "a.jpg", "z"); out != in || n != 0 {
t.Errorf("SetImageAlt(%q) = %q %d", in, out, n)
}
}
if out, n, _ := SetImageAlt(`<img src="a.jpg"><p>a <b`, "a.jpg", "z"); out != `<img src="a.jpg" alt="z"><p>a <b` || n != 1 {
t.Errorf("match with an unfinished tail = %q %d", out, n)
}
}