all repos — honk @ 5531a8898f7c4531a18bb90e80c406cce4232e62

my fork of honk

rework markdown module, prepare for embetterment
Ted Unangst tedu@tedunangst.com
Sun, 06 Oct 2019 15:01:23 -0400
commit

5531a8898f7c4531a18bb90e80c406cce4232e62

parent

26c164b44f87e55d1eecd6a04e81e15798da5279

5 files changed, 18 insertions(+), 94 deletions(-)

jump to
M activity.goactivity.go

@@ -1153,7 +1153,7 @@ }

} func asjonker(user *WhatAbout) junk.Junk { - about := obfusbreak(user.About) + about := markitzero(user.About) j := junk.New() j["@context"] = itiswhatitis
M fun.gofun.go

@@ -172,7 +172,7 @@ honk.Precis = strings.TrimSpace(honk.Precis)

noise = strings.TrimSpace(noise) noise = quickrename(noise, honk.UserID) - noise = obfusbreak(noise) + noise = markitzero(noise) honk.Noise = noise honk.Onts = oneofakind(ontologies(honk.Noise))

@@ -314,82 +314,6 @@ honk.Donks = append(honk.Donks, &d)

return "" } honk.Noise = re_memes.ReplaceAllStringFunc(honk.Noise, repl) -} - -var re_bolder = regexp.MustCompile(`(^|\W)\*\*([\w\s,.!?':_-]+)\*\*($|\W)`) -var re_italicer = regexp.MustCompile(`(^|\W)\*([\w\s,.!?':_-]+)\*($|\W)`) -var re_bigcoder = regexp.MustCompile("```\n?((?s:.*?))\n?```\n?") -var re_coder = regexp.MustCompile("`([^`]*)`") -var re_quoter = regexp.MustCompile(`(?m:^&gt; (.*)\n?)`) - -func markitzero(s string) string { - var bigcodes []string - bigsaver := func(code string) string { - bigcodes = append(bigcodes, code) - return "``````" - } - s = re_bigcoder.ReplaceAllStringFunc(s, bigsaver) - var lilcodes []string - lilsaver := func(code string) string { - lilcodes = append(lilcodes, code) - return "`x`" - } - s = re_coder.ReplaceAllStringFunc(s, lilsaver) - s = re_bolder.ReplaceAllString(s, "$1<b>$2</b>$3") - s = re_italicer.ReplaceAllString(s, "$1<i>$2</i>$3") - s = re_quoter.ReplaceAllString(s, "<blockquote>$1</blockquote><p>") - lilun := func(s string) string { - code := lilcodes[0] - lilcodes = lilcodes[1:] - return code - } - s = re_coder.ReplaceAllStringFunc(s, lilun) - bigun := func(s string) string { - code := bigcodes[0] - bigcodes = bigcodes[1:] - return code - } - s = re_bigcoder.ReplaceAllStringFunc(s, bigun) - s = re_bigcoder.ReplaceAllString(s, "<pre><code>$1</code></pre><p>") - s = re_coder.ReplaceAllString(s, "<code>$1</code>") - return s -} - -func obfusbreak(s string) string { - s = strings.TrimSpace(s) - s = strings.Replace(s, "\r", "", -1) - s = html.EscapeString(s) - // dammit go - s = strings.Replace(s, "&#39;", "'", -1) - linkfn := func(url string) string { - if url[0] == '@' { - return url - } - addparen := false - adddot := false - if strings.HasSuffix(url, ")") && strings.IndexByte(url, '(') == -1 { - url = url[:len(url)-1] - addparen = true - } - if strings.HasSuffix(url, ".") { - url = url[:len(url)-1] - adddot = true - } - url = fmt.Sprintf(`<a class="mention u-url" href="%s">%s</a>`, url, url) - if adddot { - url += "." - } - if addparen { - url += ")" - } - return url - } - s = re_link.ReplaceAllStringFunc(s, linkfn) - - s = markitzero(s) - - s = strings.Replace(s, "\n", "<br>", -1) - return s } var re_quickmention = regexp.MustCompile("(^| )@[[:alnum:]]+ ")
D fun_test.go

@@ -1,15 +0,0 @@

-package main - -import ( - "testing" -) - -func TestObfusbreak(t *testing.T) { - input := `link to https://example.com/ with **bold** text` - output := `link to <a href="https://example.com/">https://example.com/</a> with <b>bold</b> text` - - tmp := obfusbreak(input) - if tmp != output { - t.Errorf("%s is not %s", tmp, output) - } -}
A markitzero_test.go

@@ -0,0 +1,15 @@

+package main + +import ( + "testing" +) + +func TestMarkitzero(t *testing.T) { + input := `link to https://example.com/ with **bold** text` + output := `link to <a class="mention u-url" href="https://example.com/">https://example.com/</a> with <b>bold</b> text` + + result := markitzero(input) + if result != output { + t.Errorf("\nexpected:\n%s\noutput:\n%s", output, result) + } +}
M web.goweb.go

@@ -527,7 +527,7 @@ templinfo := getInfo(r)

filt := htfilter.New() templinfo["Name"] = user.Name whatabout := user.About - whatabout = obfusbreak(user.About) + whatabout = markitzero(user.About) templinfo["WhatAbout"], _ = filt.String(whatabout) templinfo["ServerMessage"] = "" templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)