diff options
Diffstat (limited to 'markup/goldmark/render_hooks.go')
-rw-r--r-- | markup/goldmark/render_hooks.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/markup/goldmark/render_hooks.go b/markup/goldmark/render_hooks.go index 8dcdc39c3..c127a2c0e 100644 --- a/markup/goldmark/render_hooks.go +++ b/markup/goldmark/render_hooks.go @@ -49,6 +49,7 @@ func newLinks(cfg goldmark_config.Config) goldmark.Extender { type linkContext struct { page any + pageInner any destination string title string text hstring.RenderedString @@ -64,6 +65,10 @@ func (ctx linkContext) Page() any { return ctx.page } +func (ctx linkContext) PageInner() any { + return ctx.pageInner +} + func (ctx linkContext) Text() hstring.RenderedString { return ctx.text } @@ -92,6 +97,7 @@ func (ctx imageLinkContext) Ordinal() int { type headingContext struct { page any + pageInner any level int anchor string text hstring.RenderedString @@ -103,6 +109,10 @@ func (ctx headingContext) Page() any { return ctx.page } +func (ctx headingContext) PageInner() any { + return ctx.pageInner +} + func (ctx headingContext) Level() int { return ctx.level } @@ -186,6 +196,7 @@ func (r *hookedRenderer) renderImage(w util.BufWriter, source []byte, node ast.N imageLinkContext{ linkContext: linkContext{ page: ctx.DocumentContext().Document, + pageInner: r.getPageInner(ctx), destination: string(n.Destination), title: string(n.Title), text: hstring.RenderedString(text), @@ -200,6 +211,18 @@ func (r *hookedRenderer) renderImage(w util.BufWriter, source []byte, node ast.N return ast.WalkContinue, err } +func (r *hookedRenderer) getPageInner(rctx *render.Context) any { + pid := rctx.PeekPid() + if pid > 0 { + if lookup := rctx.DocumentContext().DocumentLookup; lookup != nil { + if v := rctx.DocumentContext().DocumentLookup(pid); v != nil { + return v + } + } + } + return rctx.DocumentContext().Document +} + func (r *hookedRenderer) filterInternalAttributes(attrs []ast.Attribute) []ast.Attribute { n := 0 for _, x := range attrs { @@ -274,6 +297,7 @@ func (r *hookedRenderer) renderLink(w util.BufWriter, source []byte, node ast.No w, linkContext{ page: ctx.DocumentContext().Document, + pageInner: r.getPageInner(ctx), destination: string(n.Destination), title: string(n.Title), text: hstring.RenderedString(text), @@ -339,6 +363,7 @@ func (r *hookedRenderer) renderAutoLink(w util.BufWriter, source []byte, node as w, linkContext{ page: ctx.DocumentContext().Document, + pageInner: r.getPageInner(ctx), destination: url, text: hstring.RenderedString(label), plainText: label, @@ -423,6 +448,7 @@ func (r *hookedRenderer) renderHeading(w util.BufWriter, source []byte, node ast w, headingContext{ page: ctx.DocumentContext().Document, + pageInner: r.getPageInner(ctx), level: n.Level, anchor: string(anchor), text: hstring.RenderedString(text), |