tables are prettier with alignment
This commit is contained in:
parent
bd2b03a0b5
commit
6235bab4a0
6
go.mod
6
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
|
||||
|
|
4
go.sum
4
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=
|
||||
|
|
|
@ -98,15 +98,31 @@ func markitzero(s string) string {
|
|||
rows := strings.Split(m, "\n")
|
||||
var r strings.Builder
|
||||
r.WriteString("<table>")
|
||||
alignments := make(map[int]string)
|
||||
for _, row := range rows {
|
||||
r.WriteString("<tr>")
|
||||
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("<td>")
|
||||
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("<tr>")
|
||||
hastr = true
|
||||
}
|
||||
fmt.Fprintf(&r, "<td %s>", alignments[i])
|
||||
r.WriteString(cell)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue