From 6235bab4a042f8cff1258fec70e7bd5ff1bfc297 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Fri, 24 Jan 2020 03:22:13 -0500 Subject: [PATCH] tables are prettier with alignment --- go.mod | 6 +++--- go.sum | 4 ++-- markitzero.go | 20 ++++++++++++++++++-- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 558255a..004dd0d 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,7 @@ module humungus.tedunangst.com/r/honk +go 1.11 + require ( github.com/andybalholm/cascadia v1.1.0 github.com/gorilla/mux v1.7.3 @@ -7,7 +9,5 @@ require ( golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4 golang.org/x/net v0.0.0-20190620200207-3b0461eec859 humungus.tedunangst.com/r/go-sqlite3 v1.1.3 - humungus.tedunangst.com/r/webs v0.6.35 + humungus.tedunangst.com/r/webs v0.6.36 ) - -go 1.11 diff --git a/go.sum b/go.sum index e80e517..b763b21 100644 --- a/go.sum +++ b/go.sum @@ -22,5 +22,5 @@ golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= humungus.tedunangst.com/r/go-sqlite3 v1.1.3 h1:G2N4wzDS0NbuvrZtQJhh4F+3X+s7BF8b9ga8k38geUI= humungus.tedunangst.com/r/go-sqlite3 v1.1.3/go.mod h1:FtEEmQM7U2Ey1TuEEOyY1BmphTZnmiEjPsNLEAkpf/M= -humungus.tedunangst.com/r/webs v0.6.35 h1:+mevZFBQ6KjiGX9Z4A/vmvlsvJe8Lf8LpkQBdN2MbEU= -humungus.tedunangst.com/r/webs v0.6.35/go.mod h1:S9sXpVSbgAIa24yYhnMN0C94LKHG+2rioS+NsiDimps= +humungus.tedunangst.com/r/webs v0.6.36 h1:Y0V6sYwruiradsyP2Y4EzQ3T+kZxrtUfuC7Bwu0GRsY= +humungus.tedunangst.com/r/webs v0.6.36/go.mod h1:S9sXpVSbgAIa24yYhnMN0C94LKHG+2rioS+NsiDimps= diff --git a/markitzero.go b/markitzero.go index 0253a2f..7641587 100644 --- a/markitzero.go +++ b/markitzero.go @@ -98,15 +98,31 @@ func markitzero(s string) string { rows := strings.Split(m, "\n") var r strings.Builder r.WriteString("") + alignments := make(map[int]string) for _, row := range rows { - r.WriteString("") + hastr := false cells := strings.Split(row, "|") for i, cell := range cells { cell = strings.TrimSpace(cell) if cell == "" && (i == 0 || i == len(cells)-1) { continue } - r.WriteString("") + hastr = true + } + fmt.Fprintf(&r, "
") + switch cell { + case ":---": + alignments[i] = `style="text-align: left"` + continue + case ":---:": + alignments[i] = `style="text-align: center"` + continue + case "---:": + alignments[i] = `style="text-align: right"` + continue + } + if !hastr { + r.WriteString("
", alignments[i]) r.WriteString(cell) } }