fix(16.2): WR-04 serve content_html for markdown that starts with a tag
LooksLikeHTML decided by the first character alone, so a markdown post opening with a hero <img>, a <div> or a comment was served as raw markdown and its first edit stored ## and ** markers as HTML in both columns. Load now serves such a value as HTML only when content_html is empty or missing, or holds that same HTML (the value or SanitizeHTML of it, white space at the ends ignored); otherwise it serves content_html.
This commit is contained in:
@@ -202,15 +202,26 @@ func TestBlogEditorTracerSmoke(t *testing.T) {
|
||||
}
|
||||
return got
|
||||
}
|
||||
noRead := func(string) (string, bool, error) {
|
||||
t.Fatal("Translated read for an HTML value")
|
||||
return "", false, nil
|
||||
}
|
||||
|
||||
t.Run("load serves HTML content as it is", func(t *testing.T) {
|
||||
const html = " <!-- lead -->\n<p>Stored <em>HTML</em></p>"
|
||||
if got := load(t, html, noRead); got != html {
|
||||
t.Fatalf("Load(HTML) = %q", got)
|
||||
for _, stored := range []string{"", html, html + "\n"} {
|
||||
if got := load(t, html, func(string) (string, bool, error) { return stored, true, nil }); got != html {
|
||||
t.Fatalf("Load(HTML) with content_html %q = %q", stored, got)
|
||||
}
|
||||
}
|
||||
if got := load(t, html, nil); got != html {
|
||||
t.Fatalf("Load(HTML, no reader) = %q", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("load serves markdown that starts with a tag as content_html", func(t *testing.T) {
|
||||
const source = "<img src=\"/storage/hero.png\" alt=\"Hero\">\n\n## Heading\n\n**bold**"
|
||||
rendered, err := classes.FormatHTML(source)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := load(t, source, func(string) (string, bool, error) { return rendered, true, nil }); got != rendered {
|
||||
t.Fatalf("Load(markdown starting with <img>) = %q, want content_html %q", got, rendered)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user