mopac-pdf v0: markdown to beautiful PDFs via digest-pinned typst
Go CLI that turns the markdown currency of this stack (Redmine notes, Discourse posts, briefing output) into typeset PDFs: two embedded typst templates (report with title page/TOC/headers, dense brief), front-matter (title/subtitle/author/date/classification/template), GFM tables, and bar charts rendered in pure Go (go-chart) from fenced chart data blocks. Engine is a prebuilt typst 0.15.1 container pinned by digest and run --network none; PDF bytes to stdout or -o. Exit codes 0/1/2. All dev in docker (dev.sh/Makefile); unit tests + golden typst fixtures plus a host-side smoke against the real engine container. Generated with Crush Assisted-by: Crush:glm-5.2
This commit is contained in:
+57
@@ -0,0 +1,57 @@
|
||||
package chart
|
||||
|
||||
import "strings"
|
||||
|
||||
// SplitCSV splits a corpus by the `,`, dropping leading or trailing whitespace unless quoted.
|
||||
func SplitCSV(text string) (output []string) {
|
||||
if len(text) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
var state int
|
||||
var word []rune
|
||||
var opened rune
|
||||
for _, r := range text {
|
||||
switch state {
|
||||
case 0: // word
|
||||
if isQuote(r) {
|
||||
opened = r
|
||||
state = 1
|
||||
} else if isCSVDelim(r) {
|
||||
output = append(output, strings.TrimSpace(string(word)))
|
||||
word = nil
|
||||
} else {
|
||||
word = append(word, r)
|
||||
}
|
||||
case 1: // we're in a quoted section
|
||||
if matchesQuote(opened, r) {
|
||||
state = 0
|
||||
continue
|
||||
}
|
||||
word = append(word, r)
|
||||
}
|
||||
}
|
||||
|
||||
if len(word) > 0 {
|
||||
output = append(output, strings.TrimSpace(string(word)))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func isCSVDelim(r rune) bool {
|
||||
return r == rune(',')
|
||||
}
|
||||
|
||||
func isQuote(r rune) bool {
|
||||
return r == '"' || r == '\'' || r == '“' || r == '”' || r == '`'
|
||||
}
|
||||
|
||||
func matchesQuote(a, b rune) bool {
|
||||
if a == '“' && b == '”' {
|
||||
return true
|
||||
}
|
||||
if a == '”' && b == '“' {
|
||||
return true
|
||||
}
|
||||
return a == b
|
||||
}
|
||||
Reference in New Issue
Block a user