diff options
| author | ivar <i@oiee.no> | 2026-04-04 16:34:46 +0200 |
|---|---|---|
| committer | ivar <i@oiee.no> | 2026-04-04 16:34:46 +0200 |
| commit | a6355e7a6530af3335c4cd8af05f1e9c8b978169 (patch) | |
| tree | c9d920d1e996ef1c42d3455825731598df6b56c2 /internal/builder/markdown.go | |
| parent | 8a093aacd162d3fd9f142b53aab9edfa061fd66a (diff) | |
| download | nebbet.no-a6355e7a6530af3335c4cd8af05f1e9c8b978169.tar.xz nebbet.no-a6355e7a6530af3335c4cd8af05f1e9c8b978169.zip | |
.
Diffstat (limited to 'internal/builder/markdown.go')
| -rw-r--r-- | internal/builder/markdown.go | 49 |
1 files changed, 0 insertions, 49 deletions
diff --git a/internal/builder/markdown.go b/internal/builder/markdown.go deleted file mode 100644 index 4e00ca3..0000000 --- a/internal/builder/markdown.go +++ /dev/null @@ -1,49 +0,0 @@ -package builder - -import ( - "bytes" - "regexp" - "strings" - - "github.com/yuin/goldmark" - "github.com/yuin/goldmark/extension" - "github.com/yuin/goldmark/parser" - "github.com/yuin/goldmark/renderer/html" -) - -var md = goldmark.New( - goldmark.WithExtensions( - extension.GFM, - extension.Table, - extension.Strikethrough, - extension.TaskList, - ), - goldmark.WithParserOptions( - parser.WithAutoHeadingID(), - ), - goldmark.WithRendererOptions( - // Allow raw HTML pass-through so component tags survive round-trip. - html.WithUnsafe(), - ), -) - -// MarkdownToHTML converts a markdown string to an HTML fragment. -func MarkdownToHTML(body string) (string, error) { - var buf bytes.Buffer - if err := md.Convert([]byte(body), &buf); err != nil { - return "", err - } - return buf.String(), nil -} - -var ( - htmlTagRe = regexp.MustCompile(`<[^>]+>`) - multiSpaceRe = regexp.MustCompile(`\s+`) -) - -// StripHTML removes HTML tags and normalises whitespace for search indexing. -func StripHTML(h string) string { - plain := htmlTagRe.ReplaceAllString(h, " ") - plain = multiSpaceRe.ReplaceAllString(plain, " ") - return strings.TrimSpace(plain) -} |
