Skip to content

Commit

Permalink
Improve how images are detected when serving Markdown only
Browse files Browse the repository at this point in the history
  • Loading branch information
xyproto committed Jun 27, 2024
1 parent 19a0082 commit 738b8c7
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions engine/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,8 @@ func (ac *Config) ServeStaticFile(filename, colonPort string) error {
mdParser := parser.NewWithExtensions(enabledMarkdownExtensions)
// Convert from Markdown to HTML
mdContent := markdownData.Bytes()
htmlData := markdown.ToHTML(mdContent, mdParser, nil)

// Add a script for rendering MathJax, but only if at least one mathematical formula is present
if containsFormula(mdContent) {
js := append([]byte(`<script id="MathJax-script">`), []byte(mathJaxScript)...)
htmlData = InsertScriptTag(htmlData, js) // also adds the closing </script> tag
}

localImages = utils.ExtractLocalImagePaths(string(htmlData))
tempHtmlData := markdown.ToHTML(mdContent, mdParser, nil)
localImages = utils.ExtractLocalImagePaths(string(tempHtmlData))
}

// Serve all local images mentioned in the Markdown document.
Expand Down

0 comments on commit 738b8c7

Please sign in to comment.