Compare commits
2 Commits
39a1fe7762
...
973abc8a81
Author | SHA1 | Date | |
---|---|---|---|
973abc8a81 | |||
98af3c6b4e |
@ -21,7 +21,7 @@ func ConvertToMarkdown(c *Config, filename string) ([]byte, error) {
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
articleFileName := filepath.Join(os.TempDir(), fmt.Sprint(uuid.New(), ".md"))
|
||||
cmd := exec.Command("pandoc", "-s", "-L", filepath.Join("scripts", "create_toc.lua"), "-f", "docx", "-t", "commonmark_x", "-o", articleFileName, "--extract-media", tmpDir, filename) // TODO: Is writing to a file necessary?
|
||||
cmd := exec.Command("pandoc", "-s", "-L", filepath.Join("scripts", "create_toc.lua"), "-f", "docx", "-t", "gfm", "-o", articleFileName, "--extract-media", tmpDir, filename) // TODO: Is writing to a file necessary?
|
||||
cmd.Stderr = &stderr
|
||||
if err = cmd.Run(); err != nil {
|
||||
return nil, fmt.Errorf("error converting docx to markdown: %v: %v", err, stderr.String())
|
||||
|
@ -14,7 +14,6 @@ import (
|
||||
func ConvertToHTML(md string) (string, error) {
|
||||
var buf bytes.Buffer
|
||||
|
||||
// Goldmark-Instanz mit GFM und aktivierter Attribute-Unterstützung initialisieren.
|
||||
gm := goldmark.New(
|
||||
goldmark.WithExtensions(
|
||||
extension.GFM,
|
||||
@ -23,18 +22,15 @@ func ConvertToHTML(md string) (string, error) {
|
||||
parser.WithAttribute(),
|
||||
),
|
||||
goldmark.WithRendererOptions(
|
||||
html.WithUnsafe(), // Falls du HTML-Inhalte erlauben möchtest
|
||||
html.WithUnsafe(), // HTML-Inhalte erlauben
|
||||
),
|
||||
)
|
||||
|
||||
// Markdown in HTML konvertieren.
|
||||
if err := gm.Convert([]byte(md), &buf); err != nil {
|
||||
return "", fmt.Errorf("error converting markdown to html: %v", err)
|
||||
}
|
||||
|
||||
// Bluemonday-Policy anpassen, sodass id-Attribute auf h1-h6 erlaubt sind.
|
||||
p := bluemonday.UGCPolicy()
|
||||
p.AllowAttrs("id").OnElements("h1", "h2", "h3", "h4", "h5", "h6")
|
||||
html := p.Sanitize(buf.String())
|
||||
|
||||
return html, nil
|
||||
|
Reference in New Issue
Block a user