Change IDs argumnent

This commit is contained in:
yuin 2019-12-02 18:24:22 +09:00
parent ac8e225cd3
commit 5334c63923
4 changed files with 8 additions and 7 deletions

View file

@ -13,7 +13,7 @@ import (
bf2 "gopkg.in/russross/blackfriday.v2"
"github.com/b3log/lute"
"github.com/88250/lute"
)
func BenchmarkMarkdown(b *testing.B) {

View file

@ -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")
}

View file

@ -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)
}

View file

@ -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")
}