[v10.0/forgejo] fix: render link in heading correctly in TOC (#6859)
**Backport:** https://codeberg.org/forgejo/forgejo/pulls/6853
- When you use a link in a heading such as `# [Text](link)` (instead of the conventional `# Text`) the TOC should only show `Text` and not `[Text](link)`.
- Use the `mdutil.Text` to only get the text from actual text nodes and not the text that was provided in the markdown input.
- Regression of e2fddcf681
- Resolves forgejo/forgejo#6847
- Added integration test.
Co-authored-by: Gusted <postmaster@gusted.xyz>
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6859
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
Co-committed-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
This commit is contained in:
parent
bdb78d42b6
commit
89c4c9c477
2 changed files with 26 additions and 1 deletions
|
@ -7,6 +7,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/modules/markup"
|
||||
mdutil "code.gitea.io/gitea/modules/markup/markdown/util"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"github.com/yuin/goldmark/ast"
|
||||
|
@ -19,7 +20,7 @@ func (g *ASTTransformer) transformHeading(_ *markup.RenderContext, v *ast.Headin
|
|||
v.SetAttribute(attr.Name, []byte(fmt.Sprintf("%v", attr.Value)))
|
||||
}
|
||||
}
|
||||
txt := v.Lines().Value(reader.Source())
|
||||
txt := mdutil.Text(v, reader.Source())
|
||||
header := markup.Header{
|
||||
Text: util.UnsafeBytesToString(txt),
|
||||
Level: v.Level,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue