Skip to content

Improve .Position for included content rendered with RenderShortcodes #14670

@bep

Description

@bep

While the work in #14664 certainly significantly improves this situation, the failing test below illustrates a potential improvement. I think most people would expect the output below (useful for "Edit this title" links). Note that if you replace RenderShortcodes with Content the test passes, but that has other unwanted side effects.

With Goldmark now having source positions for all nodes, I think it should be possible to calculate offsets in nested structures similar to the below. Not trivial, but possible. I think.

func TestRenderHooksPositionNested(t *testing.T) {
	t.Parallel()

	files := `
-- hugo.toml --
-- layouts/_markup/render-heading.html --
{{ $pos := .Position }}
{{ $pos.Filename }}|{{ printf "%d:%d" $pos.LineNumber $pos.ColumnNumber }}|{{ $.Ordinal }}|
-- layouts/_shortcodes/include.html --
{{ $p := site.GetPage (.Get 0) }}
{{ $p.RenderShortcodes }}
-- layouts/all.html --
{{ .Content }}
-- content/p1.md --
---
title: "p1"
---

## My Heading 2
{{% include "headings" %}}
-- content/headings.md --
## My Heading 3
## My Heading 4

`

	b := hugolib.Test(t, files)
	b.AssertFileContent("public/p1/index.html", `
 content/p1.md|5:1|
 content/headings.md|1:1|
 content/headings.md|2:1|
	`)
}

/cc @jmooring

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions