- content_h1_to_h2 and generic_anchors on the settings row (migration
202610280001), Headings and links tab, config key
golem15.journal.content_h1_to_h2 used when no settings row exists
- classes.ConvertH1 on the x/net/html tokenizer; the Blog Editor types
convert while the setting is on and answer editor.h1_converted
- GET /posts/{slug} reports content_h1_to_h2 (additive key)
31 lines
1.0 KiB
Go
31 lines
1.0 KiB
Go
package classes
|
|
|
|
import "testing"
|
|
|
|
// TestConvertH1 pins ConvertH1's byte rule: only h1 tag names change.
|
|
func TestConvertH1(t *testing.T) {
|
|
cases := []struct {
|
|
in, want string
|
|
n int
|
|
}{
|
|
{"<h1>A</h1><p>x</p>", "<h2>A</h2><p>x</p>", 1},
|
|
{`<h1 class="x" id='y'>T</h1>`, `<h2 class="x" id='y'>T</h2>`, 1},
|
|
{"<H1>Up</H1>", "<h2>Up</h2>", 1},
|
|
{"<h1>a</h1>\n<h1>b</h1>", "<h2>a</h2>\n<h2>b</h2>", 2},
|
|
{"<p>no heading & text</p>", "<p>no heading & text</p>", 0},
|
|
{"<!-- <h1>c</h1> --><p>x</p>", "<!-- <h1>c</h1> --><p>x</p>", 0},
|
|
{"<script>var s = '<h1>';</script>", "<script>var s = '<h1>';</script>", 0},
|
|
{"<h10>x</h10><h1>y</h1>", "<h10>x</h10><h2>y</h2>", 1},
|
|
{"# Markdown <h1>raw</h1> a < b", "# Markdown <h2>raw</h2> a < b", 1},
|
|
{"<p>unterminated <h1>x", "<p>unterminated <h2>x", 1},
|
|
{"text <", "text <", 0},
|
|
{"", "", 0},
|
|
}
|
|
for _, c := range cases {
|
|
got, n := ConvertH1(c.in)
|
|
if got != c.want || n != c.n {
|
|
t.Errorf("ConvertH1(%q) = %q, %d; want %q, %d", c.in, got, n, c.want, c.n)
|
|
}
|
|
}
|
|
}
|