diff --git a/helpers/content_renderer_test.go b/helpers/content_renderer_test.go index 90b4c4939..1c84818a2 100644 --- a/helpers/content_renderer_test.go +++ b/helpers/content_renderer_test.go @@ -38,7 +38,7 @@ func TestCodeFence(t *testing.T) { input, expected string } data := []test{ - {true, "", "
<html></html>\n<html></html>\n<html></html>\n"},
}
diff --git a/helpers/pygments.go b/helpers/pygments.go
index 29a5ec54f..17c30ee0a 100644
--- a/helpers/pygments.go
+++ b/helpers/pygments.go
@@ -111,14 +111,23 @@ func Highlight(code, lang, optsStr string) string {
return code
}
+ str := out.String()
+
+ // inject code tag into Pygments output
+ if lang != "" && strings.Contains(str, "") {
+ codeTag := fmt.Sprintf(``, lang, lang)
+ str = strings.Replace(str, "", codeTag, 1)
+ str = strings.Replace(str, "
", "
", 1)
+ }
+
if cachefile != "" {
// Write cache file
- if err := WriteToDisk(cachefile, bytes.NewReader(out.Bytes()), fs); err != nil {
+ if err := WriteToDisk(cachefile, strings.NewReader(str), fs); err != nil {
jww.ERROR.Print(stderr.String())
}
}
- return out.String()
+ return str
}
var pygmentsKeywords = make(map[string]bool)