From 5334c63923f47117e0d501b219784ee29a661c07 Mon Sep 17 00:00:00 2001 From: yuin Date: Mon, 2 Dec 2019 18:24:22 +0900 Subject: [PATCH] Change IDs argumnent --- _benchmark/go/benchmark_test.go | 2 +- extra_test.go | 3 ++- parser/atx_heading.go | 2 +- parser/parser.go | 8 ++++---- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/_benchmark/go/benchmark_test.go b/_benchmark/go/benchmark_test.go index e1854ab..a347ec1 100644 --- a/_benchmark/go/benchmark_test.go +++ b/_benchmark/go/benchmark_test.go @@ -13,7 +13,7 @@ import ( bf2 "gopkg.in/russross/blackfriday.v2" - "github.com/b3log/lute" + "github.com/88250/lute" ) func BenchmarkMarkdown(b *testing.B) { diff --git a/extra_test.go b/extra_test.go index 89482a3..bddfe3f 100644 --- a/extra_test.go +++ b/extra_test.go @@ -5,6 +5,7 @@ import ( "testing" . "github.com/yuin/goldmark" + "github.com/yuin/goldmark/ast" "github.com/yuin/goldmark/parser" "github.com/yuin/goldmark/renderer/html" "github.com/yuin/goldmark/testutil" @@ -62,7 +63,7 @@ func TestWindowsNewLine(t *testing.T) { type myIDs struct { } -func (s *myIDs) Generate(value, prefix []byte) []byte { +func (s *myIDs) Generate(value []byte, kind ast.NodeKind) []byte { return []byte("my-id") } diff --git a/parser/atx_heading.go b/parser/atx_heading.go index c9843e3..91dc005 100644 --- a/parser/atx_heading.go +++ b/parser/atx_heading.go @@ -195,7 +195,7 @@ func generateAutoHeadingID(node *ast.Heading, reader text.Reader, pc Context) { lastLine := node.Lines().At(lastIndex) line = lastLine.Value(reader.Source()) } - headingID := pc.IDs().Generate(line, attrAutoHeadingIDPrefix) + headingID := pc.IDs().Generate(line, ast.KindHeading) node.SetAttribute(attrNameID, headingID) } diff --git a/parser/parser.go b/parser/parser.go index b536fd5..2a5538a 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -56,7 +56,7 @@ func (r *reference) String() string { // An IDs interface is a collection of the element ids. type IDs interface { // Generate generates a new element id. - Generate(value, prefix []byte) []byte + Generate(value []byte, kind ast.NodeKind) []byte // Put puts a given element id to the used ids table. Put(value []byte) @@ -72,7 +72,7 @@ func newIDs() IDs { } } -func (s *ids) Generate(value, prefix []byte) []byte { +func (s *ids) Generate(value []byte, kind ast.NodeKind) []byte { value = util.TrimLeftSpace(value) value = util.TrimRightSpace(value) result := []byte{} @@ -93,8 +93,8 @@ func (s *ids) Generate(value, prefix []byte) []byte { } } if len(result) == 0 { - if prefix != nil { - result = append(make([]byte, 0, len(prefix)), prefix...) + if kind == ast.KindHeading { + result = []byte("heading") } else { result = []byte("id") }