Merge pull request #64 from mmarkdown/index-idx

index: use idx-N for the ID
This commit is contained in:
Miek Gieben 2018-08-16 16:53:32 +01:00 committed by GitHub
commit 3e30f72fc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 6 deletions

View File

@ -373,7 +373,7 @@ type Index struct {
Primary bool
Item []byte
Subitem []byte
ID int // number of the index
ID string // ID of the index
}
func removeNodeFromArray(a []Node, node Node) []Node {

View File

@ -872,7 +872,7 @@ func (r *Renderer) callout(w io.Writer, node *ast.Callout) {
func (r *Renderer) index(w io.Writer, node *ast.Index) {
// there is no in-text representation.
attr := []string{`class="index"`, fmt.Sprintf(`id="%d"`, node.ID)}
attr := []string{`class="index"`, fmt.Sprintf(`id="%s"`, node.ID)}
r.outTag(w, "<span", attr)
r.outs(w, "</span>")
}

View File

@ -2,6 +2,7 @@ package parser
import (
"bytes"
"fmt"
"github.com/gomarkdown/markdown/ast"
)
@ -63,7 +64,7 @@ func maybeShortRefOrIndex(p *Parser, data []byte, offset int) (int, ast.Node) {
idx := &ast.Index{}
idx.ID = p.indexCnt
idx.ID = fmt.Sprintf("idx-%d", p.indexCnt)
p.indexCnt++
idx.Primary = data[start] == '!'

6
testdata/mmark.test vendored
View File

@ -87,9 +87,9 @@ code
---
<h1>Index</h1>
<p><span class="index" id="0"></span>
<span class="index" id="1"></span>
<span class="index" id="2"></span></p>
<p><span class="index" id="idx-0"></span>
<span class="index" id="idx-1"></span>
<span class="index" id="idx-2"></span></p>
---
# Cross ref
Look at (#basics)