## headers for markdown
Ted Unangst tedu@tedunangst.com
Sat, 23 May 2020 19:58:06 -0400
2 files changed,
15 insertions(+),
0 deletions(-)
M
markitzero.go
→
markitzero.go
@@ -35,6 +35,7 @@ var re_zerolink = regexp.MustCompile(`\[([^]]*)\]\(([^)]*\)?)\)`)
var re_imgfix = regexp.MustCompile(`<img ([^>]*)>`) var re_lister = regexp.MustCompile(`((^|\n)(\+|-).*)+\n?`) var re_tabler = regexp.MustCompile(`((^|\n)\|.*)+\n?`) +var re_header = regexp.MustCompile(`(^|\n)(#+) (.*)`) var lighter = synlight.New(synlight.Options{Format: synlight.HTML})@@ -134,6 +135,11 @@ }
} r.WriteString("</table><p>") return r.String() + }) + s = re_header.ReplaceAllStringFunc(s, func(s string) string { + m := re_header.FindStringSubmatch(s) + num := len(m[2]) + return fmt.Sprintf("<h%d>%s</h%d><p>", num, m[3], num) }) // restore images
M
markitzero_test.go
→
markitzero_test.go
@@ -120,6 +120,15 @@ output := `hello<table><tr><td>col1<td>col 2<tr><td>row2<td>cell4</table><p>para`
doonezerotest(t, input, output) } +func TestHeaders(t *testing.T) { + input := `hello +## fruits +Love 'em. Eat 'em. +` + output := `hello<h2>fruits</h2><p>Love 'em. Eat 'em.` + doonezerotest(t, input, output) +} + var benchData, simpleData string func init() {