summaryrefslogtreecommitdiffhomepage
path: root/helpers
diff options
context:
space:
mode:
authorNiklas Fasching <[email protected]>2019-06-04 12:21:25 +0200
committerBjørn Erik Pedersen <[email protected]>2019-06-08 10:13:00 +0200
commitb6867bf8068fcaaddf1cb7478f4d52a9c1be1411 (patch)
tree2229d8788d26498cfd569904f442a0510e490b2c /helpers
parent9df57154ee3e3185d024bfe376101b404d8b7cc4 (diff)
downloadhugo-b6867bf8068fcaaddf1cb7478f4d52a9c1be1411.tar.gz
hugo-b6867bf8068fcaaddf1cb7478f4d52a9c1be1411.zip
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.
Diffstat (limited to 'helpers')
-rw-r--r--helpers/content.go24
1 files changed, 19 insertions, 5 deletions
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 {