CreateCitation adds a footnote with the specified text and returns the string that should be used to refer to it (e.g., "[2]"). If there is already a footnote with the exact same text, reuse its number.
(footnote string)
| 23 | // there is already a footnote with the exact same text, reuse its |
| 24 | // number. |
| 25 | func (f *Footnotes) CreateCitation(footnote string) string { |
| 26 | if footnote == "" { |
| 27 | return "" |
| 28 | } |
| 29 | |
| 30 | index, ok := f.indexes[footnote] |
| 31 | if !ok { |
| 32 | index = len(f.indexes) + 1 |
| 33 | f.footnotes = append(f.footnotes, footnote) |
| 34 | f.indexes[footnote] = index |
| 35 | } |
| 36 | return fmt.Sprintf("[%d]", index) |
| 37 | } |
| 38 | |
| 39 | // String returns a string representation of the footnote, including a |
| 40 | // trailing LF. |