diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-02-16 13:44:09 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-02-16 17:46:30 +0100 |
commit | b2a827c52c91d9219306b5c996074d2e1ced5342 (patch) | |
tree | 014c859f5a0ea31ea41d4a64d13398a974f2b4a1 /markup/goldmark/convert.go | |
parent | 77c7059ff832870c3920e87a87969b815e429a8a (diff) |
markup/goldmark: Fix mangling of headers/links in render hooks
```bash
name old time/op new time/op delta
SiteWithRenderHooks-10 11.9ms ± 1% 11.9ms ± 1% ~ (p=0.486 n=4+4)
name old alloc/op new alloc/op delta
SiteWithRenderHooks-10 11.2MB ± 0% 11.3MB ± 0% +0.16% (p=0.029 n=4+4)
name old allocs/op new allocs/op delta
SiteWithRenderHooks-10 145k ± 0% 145k ± 0% +0.14% (p=0.029 n=4+4)
```
Fixes #9504
Diffstat (limited to 'markup/goldmark/convert.go')
-rw-r--r-- | markup/goldmark/convert.go | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/markup/goldmark/convert.go b/markup/goldmark/convert.go index dcaf8d3e1..c547fe1e0 100644 --- a/markup/goldmark/convert.go +++ b/markup/goldmark/convert.go @@ -47,8 +47,7 @@ import ( // Provider is the package entry point. var Provider converter.ProviderProvider = provide{} -type provide struct { -} +type provide struct{} func (p provide) New(cfg converter.ProviderConfig) (converter.Provider, error) { md := newMarkdown(cfg) @@ -199,10 +198,21 @@ func (b *bufWriter) Flush() error { type renderContext struct { *bufWriter - pos int + positions []int renderContextData } +func (ctx *renderContext) pushPos(n int) { + ctx.positions = append(ctx.positions, n) +} + +func (ctx *renderContext) popPos() int { + i := len(ctx.positions) - 1 + p := ctx.positions[i] + ctx.positions = ctx.positions[:i] + return p +} + type renderContextData interface { RenderContext() converter.RenderContext DocumentContext() converter.DocumentContext |