From 85cd71ec7de4416a436d09315bb938f894ea9467 Mon Sep 17 00:00:00 2001 From: Benjamin Schoch Date: Wed, 31 Aug 2022 09:33:41 +0200 Subject: [PATCH] code style --- pkg/markdown/convert.go | 4 ++++ pkg/slug/generator.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/markdown/convert.go b/pkg/markdown/convert.go index 7459a54a..0a14f00d 100644 --- a/pkg/markdown/convert.go +++ b/pkg/markdown/convert.go @@ -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 } diff --git a/pkg/slug/generator.go b/pkg/slug/generator.go index bad979c1..8bafcf2f 100644 --- a/pkg/slug/generator.go +++ b/pkg/slug/generator.go @@ -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)) }