diff --git a/markitzero.go b/markitzero.go index dfe263d..25da646 100644 --- a/markitzero.go +++ b/markitzero.go @@ -35,10 +35,12 @@ 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 re_header = regexp.MustCompile(`(^|\n)(#+) (.*)\n?`) var lighter = synlight.New(synlight.Options{Format: synlight.HTML}) +var allowInlineHtml = false + func markitzero(s string) string { // prepare the string s = strings.TrimSpace(s) @@ -137,6 +139,7 @@ func markitzero(s string) string { return r.String() }) s = re_header.ReplaceAllStringFunc(s, func(s string) string { + s = strings.TrimSpace(s) m := re_header.FindStringSubmatch(s) num := len(m[2]) return fmt.Sprintf("%s

", num, m[3], num) @@ -150,6 +153,9 @@ func markitzero(s string) string { return img }) + s = strings.Replace(s, "\n\n", "

", -1) + s = strings.Replace(s, "\n", "
", -1) + // now restore the code blocks s = re_coder.ReplaceAllStringFunc(s, func(string) string { code := lilcodes[0] @@ -158,6 +164,9 @@ func markitzero(s string) string { code := bigcodes[0] bigcodes = bigcodes[1:] m := re_bigcoder.FindStringSubmatch(code) + if allowInlineHtml && m[1] == "inlinehtml" { + return m[2] + } return "

" + lighter.HighlightString(m[2], m[1]) + "

" } code = html.EscapeString(code) @@ -167,7 +176,6 @@ func markitzero(s string) string { s = re_coder.ReplaceAllString(s, "$1") // some final fixups - s = strings.Replace(s, "\n", "
", -1) s = strings.Replace(s, "

", "
", -1) s = strings.Replace(s, "
", "", -1) s = strings.Replace(s, "
", "
", -1)
diff --git a/markitzero_test.go b/markitzero_test.go
index 4d49ff6..fcdf2f7 100644
--- a/markitzero_test.go
+++ b/markitzero_test.go
@@ -32,19 +32,19 @@ func TestLinebreak1(t *testing.T) {
 
 func TestLinebreak2(t *testing.T) {
 	input := "hello\n\n> a quote\n\na comment"
-	output := "hello
a quote

a comment" + output := "hello

a quote

a comment" doonezerotest(t, input, output) } func TestLinebreak3(t *testing.T) { input := "hello\n\n```\nfunc(s string)\n```\n\ndoes it go?" - output := "hello

func(s string)

does it go?" + output := "hello

func(s string)

does it go?" doonezerotest(t, input, output) } func TestCodeStyles(t *testing.T) { input := "hello\n\n```go\nfunc(s string)\n```\n\ndoes it go?" - output := "hello

func(s string)

does it go?" + output := "hello

func(s string)

does it go?" doonezerotest(t, input, output) }