Improve Org mode support: Replace goorgeous with go-org

Sadly, goorgeous has not been updated in over a year and still has a lot of
open issues (e.g. no support for nested lists).

go-org fixes most of those issues and supports a larger subset of Org mode
syntax.
This commit is contained in:
Niklas Fasching
2019-06-04 12:21:25 +02:00
committed by Bjørn Erik Pedersen
parent 9df57154ee
commit b6867bf806
6 changed files with 54 additions and 25 deletions

View File

@@ -27,8 +27,8 @@ import (
"unicode/utf8"
"github.com/gohugoio/hugo/common/maps"
"github.com/niklasfasching/go-org/org"
"github.com/chaseadamsio/goorgeous"
bp "github.com/gohugoio/hugo/bufferpool"
"github.com/gohugoio/hugo/config"
"github.com/miekg/mmark"
@@ -756,10 +756,24 @@ func getPandocContent(ctx *RenderingContext) []byte {
}
func orgRender(ctx *RenderingContext, c ContentSpec) []byte {
content := ctx.Content
cleanContent := bytes.Replace(content, []byte("# more"), []byte(""), 1)
return goorgeous.Org(cleanContent,
c.getHTMLRenderer(blackfriday.HTML_TOC, ctx))
config := org.New()
config.Log = jww.WARN
writer := org.NewHTMLWriter()
writer.HighlightCodeBlock = func(source, lang string) string {
highlightedSource, err := c.Highlight(source, lang, "")
if err != nil {
jww.ERROR.Printf("Could not highlight source as lang %s. Using raw source.", lang)
return source
}
return highlightedSource
}
html, err := config.Parse(bytes.NewReader(ctx.Content), ctx.DocumentName).Write(writer)
if err != nil {
jww.ERROR.Printf("Could not render org: %s. Using unrendered content.", err)
return ctx.Content
}
return []byte(html)
}
func externallyRenderContent(ctx *RenderingContext, path string, args []string) []byte {