@@ -24,6 +24,7 @@ import (
2424 emojiAst "github.com/yuin/goldmark-emoji/ast"
2525
2626 "github.com/gohugoio/hugo-goldmark-extensions/extras"
27+ "github.com/gohugoio/hugo-goldmark-extensions/passthrough"
2728 "github.com/gohugoio/hugo/markup/tableofcontents"
2829
2930 "github.com/yuin/goldmark"
@@ -116,7 +117,9 @@ func (t *tocTransformer) Transform(n *ast.Document, reader text.Reader, pc parse
116117 ast .KindAutoLink ,
117118 ast .KindRawHTML ,
118119 ast .KindText ,
119- ast .KindString :
120+ ast .KindString ,
121+ passthrough .KindPassthroughInline ,
122+ passthrough .KindPassthroughBlock :
120123 err := t .r .Render (& headingText , reader .Source (), n )
121124 if err != nil {
122125 return s , err
@@ -171,6 +174,30 @@ func newTOCSanitizerPolicy() *bluemonday.Policy {
171174 return p
172175}
173176
177+ // tocPassthroughRenderer renders passthrough nodes as raw text for the TOC.
178+ type tocPassthroughRenderer struct {}
179+
180+ func (r * tocPassthroughRenderer ) RegisterFuncs (reg renderer.NodeRendererFuncRegisterer ) {
181+ reg .Register (passthrough .KindPassthroughInline , r .render )
182+ reg .Register (passthrough .KindPassthroughBlock , r .render )
183+ }
184+
185+ func (r * tocPassthroughRenderer ) render (w util.BufWriter , src []byte , node ast.Node , entering bool ) (ast.WalkStatus , error ) {
186+ if ! entering {
187+ return ast .WalkContinue , nil
188+ }
189+ switch nn := node .(type ) {
190+ case * passthrough.PassthroughInline :
191+ w .Write (nn .Segment .Value (src ))
192+ case * passthrough.PassthroughBlock :
193+ for i := range nn .Lines ().Len () {
194+ line := nn .Lines ().At (i )
195+ w .Write (line .Value (src ))
196+ }
197+ }
198+ return ast .WalkSkipChildren , nil
199+ }
200+
174201var whiteSpaceRe = regexp .MustCompile (`\s+` )
175202
176203// sanitizeTOCHeadingTitle sanitizes s for use as a TOC heading title.
0 commit comments