all repos — honk @ 4480af84ad857db9404e9e3b164181fb3db89100

my fork of honk

fix some bugs involving multiple code blocks
Ted Unangst tedu@tedunangst.com
Sat, 28 Mar 2020 22:49:34 -0400
commit

4480af84ad857db9404e9e3b164181fb3db89100

parent

5e559adf184ebaf4d41a546e2a6a93877a39db57

1 files changed, 10 insertions(+), 7 deletions(-)

jump to
M markitzero.gomarkitzero.go

@@ -43,11 +43,13 @@ // prepare the string

s = strings.TrimSpace(s) s = strings.Replace(s, "\r", "", -1) + codeword := "`elided big code`" + // save away the code blocks so we don't mess them up further var bigcodes, lilcodes, images []string s = re_bigcoder.ReplaceAllStringFunc(s, func(code string) string { bigcodes = append(bigcodes, code) - return "``````" + return codeword }) s = re_coder.ReplaceAllStringFunc(s, func(code string) string { lilcodes = append(lilcodes, code)

@@ -146,15 +148,16 @@ // now restore the code blocks

s = re_coder.ReplaceAllStringFunc(s, func(string) string { code := lilcodes[0] lilcodes = lilcodes[1:] + if code == codeword && len(bigcodes) > 0 { + code := bigcodes[0] + bigcodes = bigcodes[1:] + m := re_bigcoder.FindStringSubmatch(code) + return "<pre><code>" + lighter.HighlightString(m[2], m[1]) + "</code></pre><p>" + } code = html.EscapeString(code) return code }) - s = re_bigcoder.ReplaceAllStringFunc(s, func(string) string { - code := bigcodes[0] - bigcodes = bigcodes[1:] - m := re_bigcoder.FindStringSubmatch(code) - return "<pre><code>" + lighter.HighlightString(m[2], m[1]) + "</code></pre><p>" - }) + s = re_coder.ReplaceAllString(s, "<code>$1</code>") // some final fixups