Skip to content

Commit

Permalink
Fix missed orgmode code block hightlight
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny committed Jan 3, 2021
1 parent 7576e37 commit 3a4fcf1
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions modules/markup/orgmode/orgmode.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import (
"html"
"strings"

"code.gitea.io/gitea/modules/highlight"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/util"

"github.com/alecthomas/chroma/lexers"
"github.com/niklasfasching/go-org/org"
)

Expand All @@ -38,6 +40,28 @@ func (Parser) Extensions() []string {
// Render renders orgmode rawbytes to HTML
func Render(rawBytes []byte, urlPrefix string, metas map[string]string, isWiki bool) []byte {
htmlWriter := org.NewHTMLWriter()
htmlWriter.HighlightCodeBlock = func(source, lang string, inline bool) string {
var w strings.Builder
if _, err := w.WriteString(`<pre>`); err != nil {
return ""
}

// include language-x class as part of commonmark spec
if _, err := w.WriteString(`<code class="chroma language-` + string(lang) + `">`); err != nil {
return ""
}

lexer := lexers.Get(lang)
if _, err := w.WriteString(highlight.Code(lexer.Config().Filenames[0], source)); err != nil {
return ""
}

if _, err := w.WriteString("</code></pre>"); err != nil {
return ""
}

return w.String()
}

renderer := &Renderer{
HTMLWriter: htmlWriter,
Expand Down

0 comments on commit 3a4fcf1

Please sign in to comment.