diff --git a/inline.go b/inline.go index c1f7475..eff1383 100644 --- a/inline.go +++ b/inline.go @@ -498,7 +498,7 @@ func link(p *parser, out *bytes.Buffer, data []byte, offset int) int { return 0 } - if t == linkDeferredFootnote { + if t == linkDeferredFootnote && !p.isFootnote(lr) { lr.noteId = len(p.notes) + 1 p.notes = append(p.notes, lr) } diff --git a/inline_test.go b/inline_test.go index bcaba09..4061cfb 100644 --- a/inline_test.go +++ b/inline_test.go @@ -1023,6 +1023,28 @@ what happens here +`, + `testing footnotes.[^a] + +test footnotes the second.[^b] + +[^a]: This is the first note[^a]. +[^b]: this is the second note.[^a] +`, + `
testing footnotes.1
+ +test footnotes the second.2
+ `, } @@ -1076,6 +1098,34 @@ func TestNestedFootnotes(t *testing.T) { +`, + `This uses footnote A.[^A] + +This uses footnote C.[^C] + +[^A]: + A note. use itself.[^A] +[^B]: + B note, uses A to test duplicate.[^A] +[^C]: + C note, uses B.[^B] +`, + `This uses footnote A.1
+ +This uses footnote C.2
+ `, } doTestsInlineParam(t, tests, Options{Extensions: EXTENSION_FOOTNOTES}, 0, diff --git a/markdown.go b/markdown.go index 6d842d3..c82be6b 100644 --- a/markdown.go +++ b/markdown.go @@ -241,6 +241,16 @@ func (p *parser) getRef(refid string) (ref *reference, found bool) { return ref, found } +func (p *parser) isFootnote(ref *reference) bool { + for _, v := range p.notes { + if string(ref.link) == string(v.link) { + return true + } + } + + return false +} + // // // Public interface