From 2df463c5dc4de6b0d0f3df2e5f3e48af1d46f76b Mon Sep 17 00:00:00 2001 From: Sacha Al Himdani Date: Mon, 21 Jul 2025 12:40:09 +0200 Subject: [PATCH] Fix tables in pdf export Signed-off-by: Sacha Al Himdani --- pkg/docgen/generator.go | 9 ++++++++- pkg/docgen/template.html | 32 +++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/pkg/docgen/generator.go b/pkg/docgen/generator.go index a57c772d7..0bd731ca5 100644 --- a/pkg/docgen/generator.go +++ b/pkg/docgen/generator.go @@ -25,6 +25,8 @@ import ( "github.com/getprobo/probo/pkg/coredata" "github.com/yuin/goldmark" + "github.com/yuin/goldmark/extension" + gmhtml "github.com/yuin/goldmark/renderer/html" ) var ( @@ -38,7 +40,12 @@ var ( "lower": func(s string) string { return strings.ToLower(s) }, "classificationString": func(c Classification) string { return string(c) }, "formatContent": func(content string) template.HTML { - md := goldmark.New() + md := goldmark.New( + goldmark.WithExtensions(extension.Table), + goldmark.WithRendererOptions( + gmhtml.WithUnsafe(), + ), + ) var buf bytes.Buffer if err := md.Convert([]byte(content), &buf); err != nil { diff --git a/pkg/docgen/template.html b/pkg/docgen/template.html index d7bca2ef7..6fa587716 100644 --- a/pkg/docgen/template.html +++ b/pkg/docgen/template.html @@ -276,6 +276,36 @@ margin: 0 auto; } } + + .document-content table { + width: 100%; + border-collapse: collapse; + margin: 12px 0; + font-size: 10pt; + page-break-inside: avoid; + table-layout: auto; + word-wrap: break-word; + } + + .document-content table th, + .document-content table td { + padding: 6px 8px; + text-align: left; + border: 1px solid #ddd; + vertical-align: top; + word-wrap: break-word; + overflow-wrap: break-word; + } + + .document-content table th { + background: #f5f5f5; + font-weight: bold; + color: #333; + } + + .document-content table tr { + page-break-inside: avoid; + } @@ -364,4 +394,4 @@ - \ No newline at end of file +