Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ae364aa
ListItem Render Hook
alexanderhansen Apr 26, 2022
acc3263
Update Tests
alexanderhansen May 2, 2022
4a659ee
Merge branch 'gohugoio:master' into listitem-render-hook
alexanderhansen May 2, 2022
106caac
ListItem Render Hook
alexanderhansen Apr 26, 2022
e751003
Update Tests
alexanderhansen May 2, 2022
b143fa6
Merge branch 'listitem-render-hook' of https://github.com/alexanderha…
alexanderhansen May 2, 2022
5e0eba9
List Render Hook
alexanderhansen May 2, 2022
5130a3d
With ordered parameter
alexanderhansen May 2, 2022
c025e3f
ListItem has no attributes
alexanderhansen May 2, 2022
156e671
Test for attributes
alexanderhansen May 2, 2022
5757d1d
First and Last sibling check for listitems
alexanderhansen May 5, 2022
1c954b9
Borrowed from Goldmark
alexanderhansen May 5, 2022
0de16a5
ListItem Render Hook
alexanderhansen Apr 26, 2022
b04f772
Update Tests
alexanderhansen May 2, 2022
595c696
List Render Hook
alexanderhansen May 2, 2022
9d3616a
With ordered parameter
alexanderhansen May 2, 2022
5e38325
ListItem has no attributes
alexanderhansen May 2, 2022
6ccad18
Test for attributes
alexanderhansen May 2, 2022
433d9cf
First and Last sibling check for listitems
alexanderhansen May 5, 2022
600e5a5
Borrowed from Goldmark
alexanderhansen May 5, 2022
4266674
Merge branch 'listitem-render-hook' of https://github.com/alexanderha…
alexanderhansen May 5, 2022
9199981
docs
alexanderhansen May 5, 2022
db2a4ca
Delete devcontainer.json
alexanderhansen May 5, 2022
3cb278b
Merge branch 'gohugoio:master' into listitem-render-hook
alexanderhansen Aug 3, 2022
c85708b
Merge branch 'gohugoio:master' into listitem-render-hook
alexanderhansen Dec 8, 2022
398be2d
Merge branch 'gohugoio:master' into listitem-render-hook
alexanderhansen Apr 6, 2023
3b2b6b1
Add Context to Renderer
alexanderhansen Apr 6, 2023
967447f
Merge branch 'gohugoio:master' into listitem-render-hook
alexanderhansen Apr 14, 2023
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
With ordered parameter
  • Loading branch information
alexanderhansen committed May 5, 2022
commit 9d3616a6f980fd684bd8a91cb81f78d68ef81fe1
13 changes: 12 additions & 1 deletion hugolib/content_render_hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Inner Block: {{ .Inner | .Page.RenderString (dict "display" "block" ) }}
b.WithTemplatesAdded("_default/_markup/render-image.html", `IMAGE: {{ .Page.Title }}||{{ .Destination | safeURL }}|Title: {{ .Title | safeHTML }}|Text: {{ .Text | safeHTML }}|END`)
b.WithTemplatesAdded("_default/_markup/render-heading.html", `HEADING: {{ .Page.Title }}||Level: {{ .Level }}|Anchor: {{ .Anchor | safeURL }}|Text: {{ .Text | safeHTML }}|Attributes: {{ .Attributes }}|END`)
b.WithTemplatesAdded("docs/_markup/render-heading.html", `Docs Level: {{ .Level }}|END`)
b.WithTemplatesAdded("_default/_markup/render-list.html", `LIST: {{ .Text | safeHTML }} {{ .Attributes }} {{ .IsOrdered }} `)
b.WithTemplatesAdded("_default/_markup/render-listitem.html", `LISTITEM: {{ .Text | safeHTML }} {{ .Attributes }}`)
b.WithContent("customview/p1.md", `---
title: Custom View
Expand Down Expand Up @@ -203,6 +204,14 @@ title: With List Items
- Cat
- Mouse **Fat**
- Bird{.parrot}
`, "blog/p10.md", `---
title: With Ordered List
---
1. Car
2. Boat
3. Plane
{.transportation}

`,
)

Expand All @@ -217,7 +226,7 @@ title: No Template
}
counters := &testCounters{}
b.Build(BuildCfg{testCounters: counters})
b.Assert(int(counters.contentRenderCounter), qt.Equals, 46)
b.Assert(int(counters.contentRenderCounter), qt.Equals, 47)

b.AssertFileContent("public/blog/p1/index.html", `
Cool Page|https://www.google.com|Title: Google's Homepage|Text: First Link|END
Expand Down Expand Up @@ -276,6 +285,8 @@ SHORT3|
b.AssertFileContent("public/blog/p9/index.html", "LISTITEM: Dog")
b.AssertFileContent("public/blog/p9/index.html", "LISTITEM: Cat")
b.AssertFileContent("public/blog/p9/index.html", "LISTITEM: Mouse <strong>Fat</strong>")

b.AssertFileContent("public/blog/p10/index.html", "LIST:")
}

func TestRenderHooksDeleteTemplate(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion hugolib/page__per_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ func (p *pageContentOutput) initRenderHooks() error {
case hooks.ListItemRendererType:
layoutDescriptor.Kind = "render-listitem"
case hooks.ListRendererType:
layoutDescriptor.Kind = "render-listitem"
layoutDescriptor.Kind = "render-list"
}

getHookTemplate := func(f output.Format) (tpl.Template, bool) {
Expand Down
2 changes: 1 addition & 1 deletion markup/converter/hooks/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ type ListContext interface {
Page() interface{}
Text() hstring.RenderedString
PlainText() string

IsOrdered() bool
Parent() interface{}

AttributesProvider
Expand Down
13 changes: 8 additions & 5 deletions markup/goldmark/render_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ type listContext struct {
page interface{}
text hstring.RenderedString
plainText string
isOrdered bool
parent interface{}
*attributes.AttributesHolder
}
Expand All @@ -162,6 +163,10 @@ func (ctx listContext) PlainText() string {
return ctx.plainText
}

func (ctx listContext) IsOrdered() bool {
return ctx.isOrdered
}

func (ctx listContext) Parent() interface{} {
return ctx.parent
}
Expand Down Expand Up @@ -473,7 +478,6 @@ func (r *hookedRenderer) renderHeadingDefault(w util.BufWriter, source []byte, n

func (r *hookedRenderer) renderListItem(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
n := node.(*ast.ListItem)
n.FirstChild()
var hli hooks.ListItemRenderer

ctx, ok := w.(*render.Context)
Expand Down Expand Up @@ -558,12 +562,11 @@ func (r *hookedRenderer) renderListDefault(w util.BufWriter, source []byte, node

func (r *hookedRenderer) renderList(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
n := node.(*ast.List)
n.FirstChild()
var hli hooks.ListRenderer

ctx, ok := w.(*render.Context)
if ok {
h := ctx.RenderContext().GetRenderer(hooks.ListItemRendererType, nil)
h := ctx.RenderContext().GetRenderer(hooks.ListRendererType, nil)
ok = h != nil
if ok {
hli = h.(hooks.ListRenderer)
Expand All @@ -586,10 +589,11 @@ func (r *hookedRenderer) renderList(w util.BufWriter, source []byte, node ast.No

err := hli.RenderList(
w,
listItemContext{
listContext{
page: ctx.DocumentContext().Document,
text: hstring.RenderedString(text),
plainText: string(n.Text(source)),
isOrdered: n.IsOrdered(),
parent: n.Parent(),
AttributesHolder: attributes.New(n.Attributes(), attributes.AttributesOwnerGeneral),
},
Expand All @@ -598,7 +602,6 @@ func (r *hookedRenderer) renderList(w util.BufWriter, source []byte, node ast.No
ctx.AddIdentity(hli)

return ast.WalkContinue, err
//return r.renderListDefault(w, source, node, entering)
}

type links struct {
Expand Down