From b6867bf8068fcaaddf1cb7478f4d52a9c1be1411 Mon Sep 17 00:00:00 2001 From: Niklas Fasching Date: Tue, 4 Jun 2019 12:21:25 +0200 Subject: 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. --- helpers/content.go | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'helpers') diff --git a/helpers/content.go b/helpers/content.go index 3892647bb..6d9f1ca08 100644 --- a/helpers/content.go +++ b/helpers/content.go @@ -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 { -- cgit v1.2.3