mirror of
https://github.com/yuin/goldmark
synced 2025-03-04 23:04:52 +00:00
Change IDs argumnent
This commit is contained in:
parent
ac8e225cd3
commit
5334c63923
4 changed files with 8 additions and 7 deletions
|
|
@ -13,7 +13,7 @@ import (
|
||||||
|
|
||||||
bf2 "gopkg.in/russross/blackfriday.v2"
|
bf2 "gopkg.in/russross/blackfriday.v2"
|
||||||
|
|
||||||
"github.com/b3log/lute"
|
"github.com/88250/lute"
|
||||||
)
|
)
|
||||||
|
|
||||||
func BenchmarkMarkdown(b *testing.B) {
|
func BenchmarkMarkdown(b *testing.B) {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "github.com/yuin/goldmark"
|
. "github.com/yuin/goldmark"
|
||||||
|
"github.com/yuin/goldmark/ast"
|
||||||
"github.com/yuin/goldmark/parser"
|
"github.com/yuin/goldmark/parser"
|
||||||
"github.com/yuin/goldmark/renderer/html"
|
"github.com/yuin/goldmark/renderer/html"
|
||||||
"github.com/yuin/goldmark/testutil"
|
"github.com/yuin/goldmark/testutil"
|
||||||
|
|
@ -62,7 +63,7 @@ func TestWindowsNewLine(t *testing.T) {
|
||||||
type myIDs struct {
|
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")
|
return []byte("my-id")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -195,7 +195,7 @@ func generateAutoHeadingID(node *ast.Heading, reader text.Reader, pc Context) {
|
||||||
lastLine := node.Lines().At(lastIndex)
|
lastLine := node.Lines().At(lastIndex)
|
||||||
line = lastLine.Value(reader.Source())
|
line = lastLine.Value(reader.Source())
|
||||||
}
|
}
|
||||||
headingID := pc.IDs().Generate(line, attrAutoHeadingIDPrefix)
|
headingID := pc.IDs().Generate(line, ast.KindHeading)
|
||||||
node.SetAttribute(attrNameID, headingID)
|
node.SetAttribute(attrNameID, headingID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ func (r *reference) String() string {
|
||||||
// An IDs interface is a collection of the element ids.
|
// An IDs interface is a collection of the element ids.
|
||||||
type IDs interface {
|
type IDs interface {
|
||||||
// Generate generates a new element id.
|
// 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 puts a given element id to the used ids table.
|
||||||
Put(value []byte)
|
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.TrimLeftSpace(value)
|
||||||
value = util.TrimRightSpace(value)
|
value = util.TrimRightSpace(value)
|
||||||
result := []byte{}
|
result := []byte{}
|
||||||
|
|
@ -93,8 +93,8 @@ func (s *ids) Generate(value, prefix []byte) []byte {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(result) == 0 {
|
if len(result) == 0 {
|
||||||
if prefix != nil {
|
if kind == ast.KindHeading {
|
||||||
result = append(make([]byte, 0, len(prefix)), prefix...)
|
result = []byte("heading")
|
||||||
} else {
|
} else {
|
||||||
result = []byte("id")
|
result = []byte("id")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue