From 8a7ea425e97fa9f2b5a4638046e8030978c5cdde Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Sat, 23 May 2020 19:58:06 -0400 Subject: [PATCH] ## headers for markdown --- markitzero.go | 6 ++++++ markitzero_test.go | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/markitzero.go b/markitzero.go index 36a50b8..dfe263d 100644 --- a/markitzero.go +++ b/markitzero.go @@ -35,6 +35,7 @@ var re_zerolink = regexp.MustCompile(`\[([^]]*)\]\(([^)]*\)?)\)`) var re_imgfix = regexp.MustCompile(`]*)>`) 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}) @@ -135,6 +136,11 @@ func markitzero(s string) string { r.WriteString("

") return r.String() }) + s = re_header.ReplaceAllStringFunc(s, func(s string) string { + m := re_header.FindStringSubmatch(s) + num := len(m[2]) + return fmt.Sprintf("%s

", num, m[3], num) + }) // restore images s = strings.Replace(s, "<img x>", "", -1) diff --git a/markitzero_test.go b/markitzero_test.go index 208e159..4d49ff6 100644 --- a/markitzero_test.go +++ b/markitzero_test.go @@ -120,6 +120,15 @@ para doonezerotest(t, input, output) } +func TestHeaders(t *testing.T) { + input := `hello +## fruits +Love 'em. Eat 'em. +` + output := `hello

fruits

Love 'em. Eat 'em.` + doonezerotest(t, input, output) +} + var benchData, simpleData string func init() {