## headers for markdown
This commit is contained in:
parent
f6a3e6934e
commit
8a7ea425e9
|
@ -35,6 +35,7 @@ var re_zerolink = regexp.MustCompile(`\[([^]]*)\]\(([^)]*\)?)\)`)
|
||||||
var re_imgfix = regexp.MustCompile(`<img ([^>]*)>`)
|
var re_imgfix = regexp.MustCompile(`<img ([^>]*)>`)
|
||||||
var re_lister = regexp.MustCompile(`((^|\n)(\+|-).*)+\n?`)
|
var re_lister = regexp.MustCompile(`((^|\n)(\+|-).*)+\n?`)
|
||||||
var re_tabler = 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})
|
var lighter = synlight.New(synlight.Options{Format: synlight.HTML})
|
||||||
|
|
||||||
|
@ -135,6 +136,11 @@ func markitzero(s string) string {
|
||||||
r.WriteString("</table><p>")
|
r.WriteString("</table><p>")
|
||||||
return r.String()
|
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
|
// restore images
|
||||||
s = strings.Replace(s, "<img x>", "<img x>", -1)
|
s = strings.Replace(s, "<img x>", "<img x>", -1)
|
||||||
|
|
|
@ -120,6 +120,15 @@ para
|
||||||
doonezerotest(t, input, output)
|
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
|
var benchData, simpleData string
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
Loading…
Reference in New Issue