all repos — honk @ 02131ecae096d341b6d51584aa05b0af7a7a45cd

my fork of honk

add lists support to markdown
Ted Unangst tedu@tedunangst.com
Tue, 12 Nov 2019 14:45:39 -0500
commit

02131ecae096d341b6d51584aa05b0af7a7a45cd

parent

c73cedfe49b41428737f428a50241cfc72337a6e

4 files changed, 32 insertions(+), 0 deletions(-)

jump to
M docs/changelog.txtdocs/changelog.txt

@@ -2,6 +2,8 @@ changelog

-- next ++ Lists supported in markdown. + + Rewrite admin console to avoid large dependencies. + "Bug" fixes.
M docs/honk.5docs/honk.5

@@ -46,6 +46,11 @@ /* triple tick code blocks support syntax highlighting */

int main() { return 0; } ``` .Ed +.It lists +Lists of items starting with either +.Sq + +or +.Sq - . .It images Inline images with img tags. .Bd -literal
M markitzero.gomarkitzero.go

@@ -32,6 +32,7 @@ var re_quoter = regexp.MustCompile(`(?m:^> (.*)\n?)`)

var re_link = regexp.MustCompile(`.?.?https?://[^\s"]+[\w/)!]`) var re_zerolink = regexp.MustCompile(`\[([^]]*)\]\(([^)]*\)?)\)`) var re_imgfix = regexp.MustCompile(`<img ([^>]*)>`) +var re_lister = regexp.MustCompile(`((^|\n)(\+|-).*)+\n?`) var lighter = synlight.New(synlight.Options{Format: synlight.HTML})

@@ -78,6 +79,17 @@ 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>") + s = re_lister.ReplaceAllStringFunc(s, func(m string) string { + m = strings.Trim(m, "\n") + items := strings.Split(m, "\n") + r := "<ul>" + for _, item := range items { + r += "<li>" + strings.Trim(item[1:], " ") + } + r += "</ul><p>" + return r + }) + // restore images s = strings.Replace(s, "&lt;img x&gt;", "<img x>", -1) s = re_imgfix.ReplaceAllStringFunc(s, func(string) string {

@@ -105,6 +117,7 @@ // some final fixups

s = strings.Replace(s, "\n", "<br>", -1) s = strings.Replace(s, "<br><blockquote>", "<blockquote>", -1) s = strings.Replace(s, "<br><pre>", "<pre>", -1) + s = strings.Replace(s, "<br><ul>", "<ul>", -1) s = strings.Replace(s, "<p><br>", "<p>", -1) return s }
M markitzero_test.gomarkitzero_test.go

@@ -94,3 +94,15 @@ input := `an image <img alt="caption" src="https://example.com/wherever"> and linked [<img src="there">](example.com)`

output := `an image <img alt="caption" src="https://example.com/wherever"> and linked <a href="example.com"><img src="there"></a>` doonezerotest(t, input, output) } + +func TestLists(t *testing.T) { + input := `hello ++ a list ++ the list + +para + +- singleton` + output := `hello<ul><li>a list<li>the list</ul><p>para<ul><li>singleton</ul><p>` + doonezerotest(t, input, output) +}