[CHORE] Remove github.com/yuin/goldmark-meta

- Remove a unused dependency. This dependency was added to handle YAML
'frontmatter' meta, parsing them and converting them to a table or
details in the resulting HTML. As can be read in the issue that reported
the behavior of YAML frontmatter being rendered literally,
https://github.com/go-gitea/gitea/issues/5377.
- It's an unused dependency as the codebase since then moved on to do this YAML
parsing and rendering on their own, this was implemented in
812cfd0ad9.
- Adds unit tests that was related to this functionality, to proof the
codebase already handles this and to prevent regressions.
This commit is contained in:
Gusted 2024-07-07 03:04:45 +02:00
parent 3ff661fe9e
commit cf8f26d616
No known key found for this signature in database
GPG key ID: FD821B732837125F
6 changed files with 125 additions and 17 deletions

View file

@ -22,7 +22,6 @@ import (
chromahtml "github.com/alecthomas/chroma/v2/formatters/html"
"github.com/yuin/goldmark"
highlighting "github.com/yuin/goldmark-highlighting/v2"
meta "github.com/yuin/goldmark-meta"
"github.com/yuin/goldmark/extension"
"github.com/yuin/goldmark/parser"
"github.com/yuin/goldmark/renderer"
@ -121,7 +120,6 @@ func SpecializedMarkdown() goldmark.Markdown {
math.NewExtension(
math.Enabled(setting.Markdown.EnableMath),
),
meta.Meta,
),
goldmark.WithParserOptions(
parser.WithAttribute(),
@ -182,7 +180,7 @@ func actualRender(ctx *markup.RenderContext, input io.Reader, output io.Writer)
bufWithMetadataLength := len(buf)
rc := &RenderConfig{
Meta: renderMetaModeFromString(string(ctx.RenderMetaAs)),
Meta: markup.RenderMetaAsDetails,
Icon: "table",
Lang: "",
}

View file

@ -1210,3 +1210,127 @@ func TestCustomMarkdownURL(t *testing.T) {
test("[test](abp)",
`<p><a href="http://localhost:3000/gogits/gogs/src/branch/main/abp" rel="nofollow">test</a></p>`)
}
func TestYAMLMeta(t *testing.T) {
setting.AppURL = AppURL
test := func(input, expected string) {
buffer, err := markdown.RenderString(&markup.RenderContext{
Ctx: git.DefaultContext,
}, input)
assert.NoError(t, err)
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(buffer)))
}
test(`---
include_toc: true
---
## Header`,
`<details><summary><i class="icon table"></i></summary><table>
<thead>
<tr>
<th>include_toc</th>
</tr>
</thead>
<tbody>
<tr>
<td>true</td>
</tr>
</tbody>
</table>
</details><details><summary>toc</summary><ul>
<li>
<a href="#user-content-header" rel="nofollow">Header</a></li>
</ul>
</details><h2 id="user-content-header">Header</h2>`)
test(`---
key: value
---`,
`<details><summary><i class="icon table"></i></summary><table>
<thead>
<tr>
<th>key</th>
</tr>
</thead>
<tbody>
<tr>
<td>value</td>
</tr>
</tbody>
</table>
</details>`)
test("---\n---\n",
`<hr/>
<hr/>`)
test(`---
gitea:
details_icon: smiley
include_toc: true
---
# Another header`,
`<details><summary><i class="icon smiley"></i></summary><table>
<thead>
<tr>
<th>gitea</th>
</tr>
</thead>
<tbody>
<tr>
<td><table>
<thead>
<tr>
<th>details_icon</th>
<th>include_toc</th>
</tr>
</thead>
<tbody>
<tr>
<td>smiley</td>
<td>true</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</details><details><summary>toc</summary><ul>
<li>
<a href="#user-content-another-header" rel="nofollow">Another header</a></li>
</ul>
</details><h1 id="user-content-another-header">Another header</h1>`)
test(`---
gitea:
meta: table
key: value
---`, `<table>
<thead>
<tr>
<th>gitea</th>
<th>key</th>
</tr>
</thead>
<tbody>
<tr>
<td><table>
<thead>
<tr>
<th>meta</th>
</tr>
</thead>
<tbody>
<tr>
<td>table</td>
</tr>
</tbody>
</table>
</td>
<td>value</td>
</tr>
</tbody>
</table>`)
}

View file

@ -78,7 +78,6 @@ type RenderContext struct {
ShaExistCache map[string]bool
cancelFn func()
SidebarTocNode ast.Node
RenderMetaAs RenderMetaMode
InStandalonePage bool // used by external render. the router "/org/repo/render/..." will output the rendered content in a standalone page
}