summaryrefslogtreecommitdiffstats
path: root/hugolib/page__per_output.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-08-16 15:55:03 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-11-06 19:09:08 +0100
commit5f6b6ec68936ebbbf590894c02a1a3ecad30735f (patch)
treef6c91e225a3f24f51af1bde5cfb5b88515d0665d /hugolib/page__per_output.go
parent366ee4d8da1c2b0c1751e9bf6d54638439735296 (diff)
Prepare for Goldmark
This commmit prepares for the addition of Goldmark as the new Markdown renderer in Hugo. This introduces a new `markup` package with some common interfaces and each implementation in its own package. See #5963
Diffstat (limited to 'hugolib/page__per_output.go')
-rw-r--r--hugolib/page__per_output.go39
1 files changed, 24 insertions, 15 deletions
diff --git a/hugolib/page__per_output.go b/hugolib/page__per_output.go
index 6a1262703..ef2419eca 100644
--- a/hugolib/page__per_output.go
+++ b/hugolib/page__per_output.go
@@ -23,6 +23,8 @@ import (
"sync"
"unicode/utf8"
+ "github.com/gohugoio/hugo/markup/converter"
+
"github.com/gohugoio/hugo/lazy"
bp "github.com/gohugoio/hugo/bufferpool"
@@ -97,7 +99,12 @@ func newPageContentOutput(p *pageState) func(f output.Format) (*pageContentOutpu
if p.renderable {
if !isHTML {
- cp.workContent = cp.renderContent(p, cp.workContent)
+ r, err := cp.renderContent(cp.workContent)
+ if err != nil {
+ return err
+ }
+ cp.workContent = r.Bytes()
+
tmpContent, tmpTableOfContents := helpers.ExtractTOC(cp.workContent)
cp.tableOfContents = helpers.BytesToHTML(tmpTableOfContents)
cp.workContent = tmpContent
@@ -140,13 +147,16 @@ func newPageContentOutput(p *pageState) func(f output.Format) (*pageContentOutpu
}
}
} else if cp.p.m.summary != "" {
- html := cp.p.s.ContentSpec.RenderBytes(&helpers.RenderingContext{
- Content: []byte(cp.p.m.summary), RenderTOC: false, PageFmt: cp.p.m.markup,
- Cfg: p.Language(),
- BaseFs: p.s.BaseFs,
- DocumentID: p.File().UniqueID(), DocumentName: p.File().Path(),
- Config: cp.p.getRenderingConfig()})
- html = cp.p.s.ContentSpec.TrimShortHTML(html)
+ b, err := cp.p.getContentConverter().Convert(
+ converter.RenderContext{
+ Src: []byte(cp.p.m.summary),
+ },
+ )
+
+ if err != nil {
+ return err
+ }
+ html := cp.p.s.ContentSpec.TrimShortHTML(b.Bytes())
cp.summary = helpers.BytesToHTML(html)
}
}
@@ -311,13 +321,12 @@ func (p *pageContentOutput) setAutoSummary() error {
}
-func (cp *pageContentOutput) renderContent(p page.Page, content []byte) []byte {
- return cp.p.s.ContentSpec.RenderBytes(&helpers.RenderingContext{
- Content: content, RenderTOC: true, PageFmt: cp.p.m.markup,
- Cfg: p.Language(),
- BaseFs: cp.p.s.BaseFs,
- DocumentID: p.File().UniqueID(), DocumentName: p.File().Path(),
- Config: cp.p.getRenderingConfig()})
+func (cp *pageContentOutput) renderContent(content []byte) (converter.Result, error) {
+ return cp.p.getContentConverter().Convert(
+ converter.RenderContext{
+ Src: content,
+ RenderTOC: true,
+ })
}
func (p *pageContentOutput) setWordCounts(isCJKLanguage bool) {