fix: H1 conversion leaves code alone in markdown that starts with HTML
ConvertContentH1 reads content as markdown on every path and converts it outside goldmark's code ranges only; a body opening with an HTML block keeps the h1 tags of its code samples, a raw h1 outside code is converted as in v0.3.1 (the 33-15 test pin for that case is reversed). quick-261104-xae, review WR-01.
This commit is contained in:
@@ -321,6 +321,35 @@ func TestHeadingConversion(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("markdown that starts with an HTML block keeps its h1 samples", func(t *testing.T) {
|
||||
setH1ToH2(t, env, true)
|
||||
md := "<p class=\"lead\">Intro</p>\n\n# Title\n\n```html\n<h1>Hello</h1>\n```"
|
||||
id := apiPostID(t, env.expect(t, http.StatusCreated, http.MethodPost, posts, token, map[string]any{"title": "HTML lead", "content": md}))
|
||||
p := storedPost(t, env, id)
|
||||
if p.Content != md || strings.Contains(p.ContentHTML, "<h1") || !strings.Contains(p.ContentHTML, "<h1>Hello</h1>") || !strings.Contains(p.ContentHTML, "<h2") {
|
||||
t.Fatalf("API save: content = %q, content_html = %q", p.Content, p.ContentHTML)
|
||||
}
|
||||
dir := t.TempDir()
|
||||
raw, err := json.Marshal(console.PostFile{Slug: "imported-html-lead", Title: "Imported HTML lead", Content: md})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(dir, "imported-html-lead.json"), raw, 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var buf strings.Builder
|
||||
if err := console.ImportPosts(env.app).Run(t.Context(), cmdInput{"path": dir}, bonfire.NewOutput(strings.NewReader(""), &buf, &buf)); err != nil {
|
||||
t.Fatalf("import: %v (%s)", err, buf.String())
|
||||
}
|
||||
var imported models.Post
|
||||
if err := env.gdb.Where("slug = ?", "imported-html-lead").Take(&imported).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if imported.Content != md || strings.Contains(imported.ContentHTML, "<h1") {
|
||||
t.Fatalf("import: content = %q, content_html = %q", imported.Content, imported.ContentHTML)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("category pillar text through the admin", func(t *testing.T) {
|
||||
catToken := env.admin(t, controllers.PermissionAccessCategories)
|
||||
save := func(t *testing.T, slug string) (*string, []adminNotice) {
|
||||
|
||||
Reference in New Issue
Block a user