pull in updates from flak
Ted Unangst tedu@tedunangst.com
Tue, 26 May 2020 01:42:34 -0400
2 files changed,
13 insertions(+),
5 deletions(-)
M
markitzero.go
→
markitzero.go
@@ -35,9 +35,11 @@ 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 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@@ -137,6 +139,7 @@ r.WriteString("</table><p>")
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("<h%d>%s</h%d><p>", num, m[3], num)@@ -149,6 +152,9 @@ img := images[0]
images = images[1:] return img }) + + s = strings.Replace(s, "\n\n", "<p>", -1) + s = strings.Replace(s, "\n", "<br>", -1) // now restore the code blocks s = re_coder.ReplaceAllStringFunc(s, func(string) string {@@ -158,6 +164,9 @@ if code == codeword && len(bigcodes) > 0 {
code := bigcodes[0] bigcodes = bigcodes[1:] m := re_bigcoder.FindStringSubmatch(code) + if allowInlineHtml && m[1] == "inlinehtml" { + return m[2] + } return "<pre><code>" + lighter.HighlightString(m[2], m[1]) + "</code></pre><p>" } code = html.EscapeString(code)@@ -167,7 +176,6 @@
s = re_coder.ReplaceAllString(s, "<code>$1</code>") // some final fixups - s = strings.Replace(s, "\n", "<br>", -1) s = strings.Replace(s, "<br><blockquote>", "<blockquote>", -1) s = strings.Replace(s, "<br><cite></cite>", "", -1) s = strings.Replace(s, "<br><pre>", "<pre>", -1)
M
markitzero_test.go
→
markitzero_test.go
@@ -32,19 +32,19 @@ }
func TestLinebreak2(t *testing.T) { input := "hello\n\n> a quote\n\na comment" - output := "hello<br><blockquote>a quote</blockquote><p>a comment" + output := "hello<p><blockquote>a quote</blockquote><p>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<br><pre><code>func(s string)</code></pre><p>does it go?" + output := "hello<p><pre><code>func(s string)</code></pre><p>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<br><pre><code><span class=kw>func</span><span class=op>(</span>s <span class=tp>string</span><span class=op>)</span></code></pre><p>does it go?" + output := "hello<p><pre><code><span class=kw>func</span><span class=op>(</span>s <span class=tp>string</span><span class=op>)</span></code></pre><p>does it go?" doonezerotest(t, input, output) }