all repos — honk @ b30b460a2ecab7a77a7ce3a41ca92e36dadb5dee

my fork of honk

add basic support for tables
Ted Unangst tedu@tedunangst.com
Wed, 01 Jan 2020 17:45:06 -0500
commit

b30b460a2ecab7a77a7ce3a41ca92e36dadb5dee

parent

659e5fc38c5c816493d228039e8f265f6bdba00f

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

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

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

=== next ++ Tables + + Reduce retries talking to dumb servers. === 0.8.6 Sartorial Headpiece
M docs/honk.5docs/honk.5

@@ -51,6 +51,8 @@ Lists of items starting with either

.Sq + or .Sq - . +.It tables +Table cells separated by |. .It images Inline images with img tags. .Bd -literal
M markitzero.gomarkitzero.go

@@ -34,6 +34,7 @@ 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 re_tabler = regexp.MustCompile(`((^|\n)\|.*)+\n?`) var lighter = synlight.New(synlight.Options{Format: synlight.HTML})

@@ -92,6 +93,26 @@ }

r += "</ul><p>" return r }) + s = re_tabler.ReplaceAllStringFunc(s, func(m string) string { + m = strings.Trim(m, "\n") + rows := strings.Split(m, "\n") + var r strings.Builder + r.WriteString("<table>") + for _, row := range rows { + r.WriteString("<tr>") + cells := strings.Split(row, "|") + for i, cell := range cells { + cell = strings.TrimSpace(cell) + if cell == "" && (i == 0 || i == len(cells)-1) { + continue + } + r.WriteString("<td>") + r.WriteString(cell) + } + } + r.WriteString("</table><p>") + return r.String() + }) // restore images s = strings.Replace(s, "&lt;img x&gt;", "<img x>", -1)

@@ -122,6 +143,7 @@ s = strings.Replace(s, "<br><blockquote>", "<blockquote>", -1)

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

@@ -108,6 +108,18 @@ output := `hello<ul><li>a list<li>the list</ul><p>para<ul><li>singleton</ul><p>`

doonezerotest(t, input, output) } +func TestTables(t *testing.T) { + input := `hello + +| col1 | col 2 | +| row2 | cell4 | + +para +` + output := `hello<table><tr><td>col1<td>col 2<tr><td>row2<td>cell4</table><p>para` + doonezerotest(t, input, output) +} + var benchData, simpleData string func init() {