diff --git a/_benchmark/cmark/Makefile b/_benchmark/cmark/Makefile
index 586a2b2..02947fb 100644
--- a/_benchmark/cmark/Makefile
+++ b/_benchmark/cmark/Makefile
@@ -19,7 +19,7 @@ run: $(CMARK_BIN)
GOOS=windows GOARCH=amd64 go build -o goldmark_benchmark.exe ./goldmark_benchmark.go && ./goldmark_benchmark.exe; \
fi
-./cmark-master/build/src/config.h:
+./cmark-master/Makefile:
wget -nc -O cmark.zip https://github.com/commonmark/cmark/archive/master.zip
unzip cmark.zip
rm -f cmark.zip
@@ -29,7 +29,7 @@ run: $(CMARK_BIN)
cd cmark-master && make mingw; \
fi
-$(CMARK_BIN): ./cmark-master/build/src/config.h
+$(CMARK_BIN): ./cmark-master/Makefile
@ if [ -z "$${WSL_INTEROP}" ]; then \
gcc -I./cmark-master/build/src -I./cmark-master/src cmark_benchmark.c -o $(CMARK_BIN) -L./cmark-master/build/src -lcmark; \
else \
diff --git a/extension/_test/footnote.txt b/extension/_test/footnote.txt
index 48e3a58..dcfc182 100644
--- a/extension/_test/footnote.txt
+++ b/extension/_test/footnote.txt
@@ -66,3 +66,26 @@ test![^1]
//= = = = = = = = = = = = = = = = = = = = = = = =//
+
+6: Multiple references to the same footnotes should have different ids
+//- - - - - - - - -//
+something[^fn:1]
+
+something[^fn:1]
+
+something[^fn:1]
+
+[^fn:1]: footnote text
+//- - - - - - - - -//
+
something
+something
+something
+
+//= = = = = = = = = = = = = = = = = = = = = = = =//
diff --git a/extension/ast/footnote.go b/extension/ast/footnote.go
index dedbab4..97fea44 100644
--- a/extension/ast/footnote.go
+++ b/extension/ast/footnote.go
@@ -12,6 +12,7 @@ type FootnoteLink struct {
gast.BaseInline
Index int
RefCount int
+ RefIndex int
}
// Dump implements Node.Dump.
@@ -19,6 +20,7 @@ func (n *FootnoteLink) Dump(source []byte, level int) {
m := map[string]string{}
m["Index"] = fmt.Sprintf("%v", n.Index)
m["RefCount"] = fmt.Sprintf("%v", n.RefCount)
+ m["RefIndex"] = fmt.Sprintf("%v", n.RefIndex)
gast.DumpHelper(n, source, level, m, nil)
}
@@ -35,6 +37,7 @@ func NewFootnoteLink(index int) *FootnoteLink {
return &FootnoteLink{
Index: index,
RefCount: 0,
+ RefIndex: 0,
}
}
@@ -44,6 +47,7 @@ type FootnoteBacklink struct {
gast.BaseInline
Index int
RefCount int
+ RefIndex int
}
// Dump implements Node.Dump.
@@ -51,6 +55,7 @@ func (n *FootnoteBacklink) Dump(source []byte, level int) {
m := map[string]string{}
m["Index"] = fmt.Sprintf("%v", n.Index)
m["RefCount"] = fmt.Sprintf("%v", n.RefCount)
+ m["RefIndex"] = fmt.Sprintf("%v", n.RefIndex)
gast.DumpHelper(n, source, level, m, nil)
}
@@ -67,6 +72,7 @@ func NewFootnoteBacklink(index int) *FootnoteBacklink {
return &FootnoteBacklink{
Index: index,
RefCount: 0,
+ RefIndex: 0,
}
}
diff --git a/extension/footnote.go b/extension/footnote.go
index d4552e5..2d33548 100644
--- a/extension/footnote.go
+++ b/extension/footnote.go
@@ -2,6 +2,7 @@ package extension
import (
"bytes"
+ "fmt"
"strconv"
"github.com/yuin/goldmark"
@@ -217,8 +218,14 @@ func (a *footnoteASTTransformer) Transform(node *gast.Document, reader text.Read
counter[fnlink.Index]++
}
}
+ refCounter := map[int]int{}
for _, fnlink := range fnlist {
fnlink.RefCount = counter[fnlink.Index]
+ if _, ok := refCounter[fnlink.Index]; !ok {
+ refCounter[fnlink.Index] = 0
+ }
+ fnlink.RefIndex = refCounter[fnlink.Index]
+ refCounter[fnlink.Index]++
}
}
for footnote := list.FirstChild(); footnote != nil; {
@@ -232,9 +239,19 @@ func (a *footnoteASTTransformer) Transform(node *gast.Document, reader text.Read
if index < 0 {
list.RemoveChild(list, footnote)
} else {
+ refCount := counter[index]
backLink := ast.NewFootnoteBacklink(index)
- backLink.RefCount = counter[index]
+ backLink.RefCount = refCount
+ backLink.RefIndex = 0
container.AppendChild(container, backLink)
+ if refCount > 1 {
+ for i := 1; i < refCount; i++ {
+ backLink := ast.NewFootnoteBacklink(index)
+ backLink.RefCount = refCount
+ backLink.RefIndex = i
+ container.AppendChild(container, backLink)
+ }
+ }
}
footnote = next
}
@@ -514,7 +531,11 @@ func (r *FootnoteHTMLRenderer) renderFootnoteLink(w util.BufWriter, source []byt
is := strconv.Itoa(n.Index)
_, _ = w.WriteString(` 0 {
+ _, _ = w.WriteString(fmt.Sprintf("%v", n.RefIndex))
+ }
+ _ = w.WriteByte(':')
_, _ = w.WriteString(is)
_, _ = w.WriteString(`" class="`)
_, _ = w.Write(applyFootnoteTemplate(r.FootnoteConfig.BacklinkClass, n.Index, n.RefCount))
diff --git a/extension/footnote_test.go b/extension/footnote_test.go
index c3f4770..4b5ea1d 100644
--- a/extension/footnote_test.go
+++ b/extension/footnote_test.go
@@ -63,20 +63,19 @@ Another one.[^2]
[^2]: Another footnote.
`,
Expected: `That's some text with a footnote.1
-Same footnote.1
+Same footnote.1
Another one.2
-`,
+`,
},
t,
)
@@ -123,20 +122,19 @@ Another one.[^2]
[^2]: Another footnote.
`,
Expected: `That's some text with a footnote.1
-Same footnote.1
+Same footnote.1
Another one.2
-`,
+`,
},
t,
)