File tree 1 file changed +24
-0
lines changed
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -10,10 +10,12 @@ import (
10
10
"html"
11
11
"strings"
12
12
13
+ "code.gitea.io/gitea/modules/highlight"
13
14
"code.gitea.io/gitea/modules/log"
14
15
"code.gitea.io/gitea/modules/markup"
15
16
"code.gitea.io/gitea/modules/util"
16
17
18
+ "github.com/alecthomas/chroma/lexers"
17
19
"github.com/niklasfasching/go-org/org"
18
20
)
19
21
@@ -38,6 +40,28 @@ func (Parser) Extensions() []string {
38
40
// Render renders orgmode rawbytes to HTML
39
41
func Render (rawBytes []byte , urlPrefix string , metas map [string ]string , isWiki bool ) []byte {
40
42
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
+ }
41
65
42
66
renderer := & Renderer {
43
67
HTMLWriter : htmlWriter ,
You can’t perform that action at this time.
0 commit comments