Fix auto generated header ids so they don't contain e.g. hyperlink destinations (note)

This makes the header ids match the newly added dt ids.

Also make sure newlines are preserved in hooks' `.PlainText`.

Fixes #13405
Fixes #13410
This commit is contained in:
Bjørn Erik Pedersen
2025-02-16 21:52:46 +01:00
parent a2ca95629a
commit 24cc25552f
6 changed files with 59 additions and 14 deletions

View File

@@ -1,4 +1,4 @@
// Copyright 2024 The Hugo Authors. All rights reserved.
// Copyright 2025 The Hugo Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@ import (
"sync"
bp "github.com/gohugoio/hugo/bufferpool"
east "github.com/yuin/goldmark-emoji/ast"
htext "github.com/gohugoio/hugo/common/text"
"github.com/gohugoio/hugo/tpl"
@@ -282,6 +283,7 @@ func textPlainTo(c ast.Node, source []byte, buf *bytes.Buffer) {
if c == nil {
return
}
switch c := c.(type) {
case *ast.RawHTML:
s := strings.TrimSpace(tpl.StripHTML(string(c.Segments.Value(source))))
@@ -290,6 +292,11 @@ func textPlainTo(c ast.Node, source []byte, buf *bytes.Buffer) {
buf.Write(c.Value)
case *ast.Text:
buf.Write(c.Segment.Value(source))
if c.HardLineBreak() || c.SoftLineBreak() {
buf.WriteByte('\n')
}
case *east.Emoji:
buf.WriteString(string(c.ShortName))
default:
textPlainTo(c.FirstChild(), source, buf)
}