diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2024-11-04 18:59:50 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-04 10:59:50 +0000 |
commit | 61be51e56baf037aa7902e7cd066b895a10da244 (patch) | |
tree | 1cbf5fed4146977538975ea3d7ce4e302294cba0 /modules/markup/markdown | |
parent | af28ce59b8695a8412632c50cf96fdd420215719 (diff) | |
download | gitea-61be51e56baf037aa7902e7cd066b895a10da244.tar.gz gitea-61be51e56baf037aa7902e7cd066b895a10da244.zip |
Refactor markup package (#32399)
To make the markup package easier to maintain:
1. Split some go files into small files
2. Use a shared util.NopCloser, remove duplicate code
3. Remove unused functions
Diffstat (limited to 'modules/markup/markdown')
-rw-r--r-- | modules/markup/markdown/goldmark.go | 2 | ||||
-rw-r--r-- | modules/markup/markdown/toc.go | 10 | ||||
-rw-r--r-- | modules/markup/markdown/transform_heading.go | 4 |
3 files changed, 11 insertions, 5 deletions
diff --git a/modules/markup/markdown/goldmark.go b/modules/markup/markdown/goldmark.go index 515a79578d..0cd9dc5f30 100644 --- a/modules/markup/markdown/goldmark.go +++ b/modules/markup/markdown/goldmark.go @@ -45,7 +45,7 @@ func (g *ASTTransformer) Transform(node *ast.Document, reader text.Reader, pc pa ctx := pc.Get(renderContextKey).(*markup.RenderContext) rc := pc.Get(renderConfigKey).(*RenderConfig) - tocList := make([]markup.Header, 0, 20) + tocList := make([]Header, 0, 20) if rc.yamlNode != nil { metaNode := rc.toMetaNode() if metaNode != nil { diff --git a/modules/markup/markdown/toc.go b/modules/markup/markdown/toc.go index 38f744a25f..ea1af83a3e 100644 --- a/modules/markup/markdown/toc.go +++ b/modules/markup/markdown/toc.go @@ -7,13 +7,19 @@ import ( "fmt" "net/url" - "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/translation" "github.com/yuin/goldmark/ast" ) -func createTOCNode(toc []markup.Header, lang string, detailsAttrs map[string]string) ast.Node { +// Header holds the data about a header. +type Header struct { + Level int + Text string + ID string +} + +func createTOCNode(toc []Header, lang string, detailsAttrs map[string]string) ast.Node { details := NewDetails() summary := NewSummary() diff --git a/modules/markup/markdown/transform_heading.go b/modules/markup/markdown/transform_heading.go index b78720e16d..5f8a12794d 100644 --- a/modules/markup/markdown/transform_heading.go +++ b/modules/markup/markdown/transform_heading.go @@ -13,14 +13,14 @@ import ( "github.com/yuin/goldmark/text" ) -func (g *ASTTransformer) transformHeading(_ *markup.RenderContext, v *ast.Heading, reader text.Reader, tocList *[]markup.Header) { +func (g *ASTTransformer) transformHeading(_ *markup.RenderContext, v *ast.Heading, reader text.Reader, tocList *[]Header) { for _, attr := range v.Attributes() { if _, ok := attr.Value.([]byte); !ok { v.SetAttribute(attr.Name, []byte(fmt.Sprintf("%v", attr.Value))) } } txt := v.Text(reader.Source()) //nolint:staticcheck - header := markup.Header{ + header := Header{ Text: util.UnsafeBytesToString(txt), Level: v.Level, } |