code style

This commit is contained in:
Benjamin Schoch 2022-08-31 09:33:41 +02:00 committed by Avelino
parent 4b54315c48
commit 85cd71ec7d
2 changed files with 5 additions and 1 deletions

View File

@ -12,6 +12,7 @@ import (
"github.com/yuin/goldmark/util"
)
// ConvertMarkdownToHTML converts markdown byte slice to a HTML byte slice
func ConvertMarkdownToHTML(markdown []byte) ([]byte, error) {
md := goldmark.New(
goldmark.WithExtensions(extension.GFM),
@ -36,14 +37,17 @@ func ConvertMarkdownToHTML(markdown []byte) ([]byte, error) {
return buf.Bytes(), nil
}
// IDGenerator for goldmark to provide IDs more similar to GitHub's IDs on markdown parsing
type IDGenerator struct {
used map[string]bool
}
// Generate an ID
func (g *IDGenerator) Generate(value []byte, _ ast.NodeKind) []byte {
return []byte(slug.Generate(string(value)))
}
// Put an ID to the list of already used IDs
func (g *IDGenerator) Put(value []byte) {
g.used[util.BytesToReadOnlyString(value)] = true
}

View File

@ -6,8 +6,8 @@ import (
"github.com/avelino/slugify"
)
// Generate slugs similar to GitHub's slugs on markdown parsing
func Generate(text string) string {
// remove slashes to create slugs similar to GitHub's slugs on markdown parsing
s := strings.ReplaceAll(text, "/", "")
return slugify.Slugify(strings.TrimSpace(s))
}