@peaceroad/markdown-it-footnote-here 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +25 -11
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -194,14 +194,24 @@ const footnote_plugin = (md, option) =>{
194
194
 
195
195
  const isEndnote = isEndnoteLabel(label, opt)
196
196
  const fn = ensureNotesEnv(state.env, isEndnote ? 'endnotes' : 'footnotes')
197
- const id = fn.length++
198
- fn.refs[':' + label] = id
197
+ const refKey = ':' + label
198
+ const existingId = fn.refs[refKey]
199
+ const isDuplicate = isEndnote && existingId !== undefined
200
+ const id = isDuplicate ? existingId : fn.length++
201
+ if (!isDuplicate) {
202
+ fn.refs[refKey] = id
203
+ }
199
204
 
200
- const token = new state.Token('footnote_open', '', 1)
201
- token.meta = { id, isEndnote }
202
- token.level = state.level++
203
- state.tokens.push(token)
204
- fn.positions.push(state.tokens.length - 1)
205
+ let tokenStart = 0
206
+ if (!isDuplicate) {
207
+ const token = new state.Token('footnote_open', '', 1)
208
+ token.meta = { id, isEndnote }
209
+ token.level = state.level++
210
+ state.tokens.push(token)
211
+ fn.positions.push(state.tokens.length - 1)
212
+ } else {
213
+ tokenStart = state.tokens.length
214
+ }
205
215
 
206
216
  const oldBMark = bMarks[startLine]
207
217
  const oldTShift = tShift[startLine]
@@ -246,10 +256,14 @@ const footnote_plugin = (md, option) =>{
246
256
  state.sCount[startLine] = oldSCount
247
257
  state.bMarks[startLine] = oldBMark
248
258
 
249
- const closeToken = new state.Token('footnote_close', '', -1)
250
- closeToken.level = --state.level
251
- closeToken.meta = { isEndnote }
252
- state.tokens.push(closeToken)
259
+ if (!isDuplicate) {
260
+ const closeToken = new state.Token('footnote_close', '', -1)
261
+ closeToken.level = --state.level
262
+ closeToken.meta = { isEndnote }
263
+ state.tokens.push(closeToken)
264
+ } else {
265
+ state.tokens.length = tokenStart
266
+ }
253
267
 
254
268
  return true
255
269
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peaceroad/markdown-it-footnote-here",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "A markdown-it plugin. This generate aside[role|doc-footnote] element just below the footnote reference paragraph.",
5
5
  "main": "index.js",
6
6
  "type":"module",