diff --git a/docs/changelog.txt b/docs/changelog.txt index 31fc77f..5acd20d 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -2,6 +2,8 @@ changelog === next ++ Tables + + Reduce retries talking to dumb servers. === 0.8.6 Sartorial Headpiece diff --git a/docs/honk.5 b/docs/honk.5 index 0f0cf8e..f0dc1de 100644 --- a/docs/honk.5 +++ b/docs/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 diff --git a/markitzero.go b/markitzero.go index 464de15..0253a2f 100644 --- a/markitzero.go +++ b/markitzero.go @@ -34,6 +34,7 @@ var re_link = regexp.MustCompile(`.?.?https?://[^\s"]+[\w/)!]`) var re_zerolink = regexp.MustCompile(`\[([^]]*)\]\(([^)]*\)?)\)`) var re_imgfix = regexp.MustCompile(`]*)>`) 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 @@ func markitzero(s string) string { r += "

" 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("") + for _, row := range rows { + r.WriteString("") + cells := strings.Split(row, "|") + for i, cell := range cells { + cell = strings.TrimSpace(cell) + if cell == "" && (i == 0 || i == len(cells)-1) { + continue + } + r.WriteString("
") + r.WriteString(cell) + } + } + r.WriteString("

") + return r.String() + }) // restore images s = strings.Replace(s, "<img x>", "", -1) @@ -122,6 +143,7 @@ func markitzero(s string) string { s = strings.Replace(s, "
", "", -1) s = strings.Replace(s, "

", "
", -1)
 	s = strings.Replace(s, "