File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -10,10 +10,12 @@ import (
1010 "html"
1111 "strings"
1212
13+ "code.gitea.io/gitea/modules/highlight"
1314 "code.gitea.io/gitea/modules/log"
1415 "code.gitea.io/gitea/modules/markup"
1516 "code.gitea.io/gitea/modules/util"
1617
18+ "github.com/alecthomas/chroma/lexers"
1719 "github.com/niklasfasching/go-org/org"
1820)
1921
@@ -38,6 +40,28 @@ func (Parser) Extensions() []string {
3840// Render renders orgmode rawbytes to HTML
3941func Render (rawBytes []byte , urlPrefix string , metas map [string ]string , isWiki bool ) []byte {
4042 htmlWriter := org .NewHTMLWriter ()
43+ htmlWriter .HighlightCodeBlock = func (source , lang string , inline bool ) string {
44+ var w strings.Builder
45+ if _ , err := w .WriteString (`<pre>` ); err != nil {
46+ return ""
47+ }
48+
49+ // include language-x class as part of commonmark spec
50+ if _ , err := w .WriteString (`<code class="chroma language-` + string (lang ) + `">` ); err != nil {
51+ return ""
52+ }
53+
54+ lexer := lexers .Get (lang )
55+ if _ , err := w .WriteString (highlight .Code (lexer .Config ().Filenames [0 ], source )); err != nil {
56+ return ""
57+ }
58+
59+ if _ , err := w .WriteString ("</code></pre>" ); err != nil {
60+ return ""
61+ }
62+
63+ return w .String ()
64+ }
4165
4266 renderer := & Renderer {
4367 HTMLWriter : htmlWriter ,
You can’t perform that action at this time.
0 commit comments