feat(invoice): add send route

This commit is contained in:
2025-08-26 20:30:48 +02:00
parent 958979c62b
commit 788571162d
35 changed files with 451 additions and 193 deletions

View File

@@ -0,0 +1,49 @@
package report
import (
"fmt"
"html/template"
"regexp"
"strings"
"github.com/gomarkdown/markdown"
"github.com/gomarkdown/markdown/html"
"github.com/gomarkdown/markdown/parser"
)
func mdToHTML(md string) template.HTML {
md = markdownCheckboxesToHTML(md)
// create markdown parser with extensions
extensions := parser.CommonExtensions | parser.AutoHeadingIDs | parser.NoEmptyLineBeforeBlock
p := parser.NewWithExtensions(extensions)
doc := p.Parse([]byte(md))
// create HTML renderer with extensions
htmlFlags := html.CommonFlags | html.HrefTargetBlank
opts := html.RendererOptions{Flags: htmlFlags}
renderer := html.NewRenderer(opts)
return template.HTML(markdown.Render(doc, renderer))
}
// markdownCheckboxesToHTML keeps a Markdown list but replaces checkboxes with <input>.
func markdownCheckboxesToHTML(markdown string) string {
lines := strings.Split(markdown, "\n")
checkboxPattern := regexp.MustCompile(`^(\s*[-*]\s+)\[( |x|X)\][\p{Zs}\s]*(.*)$`)
for i, line := range lines {
if matches := checkboxPattern.FindStringSubmatch(line); matches != nil {
prefix := matches[1] // "- " or "* "
checked := strings.ToLower(matches[2]) == "x"
content := matches[3] // task text
if checked {
lines[i] = fmt.Sprintf(`%s<input type="checkbox" checked disabled> %s`, prefix, content)
} else {
lines[i] = fmt.Sprintf(`%s<input type="checkbox" disabled> %s`, prefix, content)
}
}
}
return strings.Join(lines, "\n")
}