@peaceroad/markdown-it-figure-with-p-caption 0.11.0 → 0.12.0

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.
@@ -1,49 +1,36 @@
1
1
  import { markReg } from 'p7d-markdown-it-p-captions'
2
2
 
3
- const imgReg = /^( *!\[)(.*?)\]\( *?((.*?)(?: +?\"(.*?)\")?) *?\)( *?\{.*?\})? *$/
3
+ const imgReg = /^( *!\[)(.*?)\]\( *?((.*?)(?: +?"(.*?)")?) *?\)( *?\{.*?\})? *$/
4
4
 
5
5
  const imgAttrToPCaption = (state, startLine, opt) => {
6
+ const imgMarkReg = markReg['img']
6
7
  let pos = state.bMarks[startLine] + state.tShift[startLine]
7
8
  let max = state.eMarks[startLine]
8
- //console.log('init inline: ' + state.src.slice(pos, max))
9
9
  let inline = state.src.slice(pos, max)
10
10
  const img = inline.match(imgReg)
11
11
  if (!img) return
12
12
 
13
- let alt = img[2] === undefined ? '' : img[2]
14
- let title = img[5] === undefined ? '' : img[5]
15
- //console.log('alt: ' + alt + ', title: ' + title)
16
-
17
- let caption = ''
18
- if (opt.imgAltCaption) caption = alt
19
- if (opt.imgTitleCaption) caption = title
20
-
21
- const hasMarkLabel = caption.match(markReg['img'])
13
+ let alt = img[2] ?? ''
14
+ let title = img[5] ?? ''
15
+ const caption = opt.imgTitleCaption ? title : (opt.imgAltCaption ? alt : '')
16
+ const altCap = typeof opt.imgAltCaption === 'string' ? opt.imgAltCaption : ''
17
+ const titleCap = typeof opt.imgTitleCaption === 'string' ? opt.imgTitleCaption : ''
22
18
 
19
+ const hasMarkLabel = caption.match(imgMarkReg)
23
20
  let modCaption = ''
24
21
  if (hasMarkLabel) {
25
22
  modCaption = caption
26
23
  } else {
27
- if (typeof opt.imgAltCaption === 'string' || typeof opt.imgTitleCaption === 'string') {
28
- if (/[a-zA-Z]/.test(opt.imgAltCaption)) {
29
- if (caption === '') {
30
- modCaption = (opt.imgAltCaption ? opt.imgAltCaption : opt.imgTitleCaption) + '.'
31
- } else {
32
- modCaption = (opt.imgAltCaption ? opt.imgAltCaption : opt.imgTitleCaption) + '. ' + caption
33
- }
34
- } else {
35
- if (caption === '') {
36
- modCaption = (opt.imgAltCaption ? opt.imgAltCaption : opt.imgTitleCaption) + ' '
37
- } else {
38
- modCaption = (opt.imgAltCaption ? opt.imgAltCaption : opt.imgTitleCaption) + ' ' + caption
39
- }
40
- }
24
+ const prefix = altCap || titleCap || ''
25
+ if (prefix && /[a-zA-Z]/.test(prefix)) {
26
+ modCaption = caption === '' ? prefix + '.' : prefix + '. ' + caption
41
27
  } else {
42
- modCaption = 'Figure.'
43
- if (caption !== '') modCaption += ' ' + caption
28
+ modCaption = caption === '' ? prefix + ' ' : prefix + ' ' + caption
29
+ }
30
+ if (!prefix) {
31
+ modCaption = 'Figure.' + (caption !== '' ? ' ' + caption : '')
44
32
  }
45
33
  }
46
- //console.log('modCaption: ' + modCaption)
47
34
  let token = state.push('paragraph_open', 'p', 1)
48
35
  token.map = [startLine, startLine + 1]
49
36
  token = state.push('inline', '', 0)
@@ -58,46 +45,37 @@ const imgAttrToPCaption = (state, startLine, opt) => {
58
45
 
59
46
  const setAltToLabel = (state, n) => {
60
47
  if (n < 2) return false
61
- if (state.tokens[n+1].children[0].type !== 'image' || !state.tokens[n-2].children) return false
48
+ const imageToken = state.tokens[n+1].children[0]
49
+ if (imageToken.type !== 'image' || !state.tokens[n-2].children) return false
50
+ const prevTokenChild = state.tokens[n-2].children[0]
62
51
  if (state.tokens[n-2].children) {
63
- state.tokens[n+1].content = state.tokens[n+1].content.replace(/^!\[.*?\]/, '![' + state.tokens[n-2].children[0].content + ']')
64
- if (!state.tokens[n+1].children[0].children[0]) {
52
+ state.tokens[n+1].content = state.tokens[n+1].content.replace(/^!\[.*?\]/, '![' + prevTokenChild.content + ']')
53
+ if (!imageToken.children[0]) {
65
54
  const textToken = new state.Token('text', '', 0)
66
- state.tokens[n+1].children[0].children.push(textToken)
55
+ imageToken.children.push(textToken)
67
56
  }
68
- // Set figure label:
69
- //state.tokens[n+1].children[0].children[0].content = state.tokens[n-2].children[2].content
70
- // Set img alt to empty value:
71
- state.tokens[n+1].children[0].children[0].content = ''
57
+ imageToken.children[0].content = ''
72
58
  }
73
- // Set figure label:
74
- //state.tokens[n+1].children[0].content = state.tokens[n-2].children[2].content
75
- // Set img alt to empty value:
76
- state.tokens[n+1].children[0].content = ''
77
- //console.log(state.tokens[n+1].children[0])
59
+ imageToken.content = ''
78
60
  return true
79
61
  }
80
62
 
81
63
  const setTitleToLabel = (state, n) => {
82
64
  if (n < 2) return false
83
- if (state.tokens[n+1].children[0].type !== 'image') return false
65
+ const imageToken = state.tokens[n+1].children[0]
66
+ if (imageToken.type !== 'image') return false
84
67
  if (!state.tokens[n-2].children[0]) return false
85
- state.tokens[n+1].children[0].attrSet('alt', state.tokens[n+1].children[0].content)
86
- if (!state.tokens[n+1].children[0].children[0]) {
68
+ imageToken.attrSet('alt', imageToken.content)
69
+ if (!imageToken.children[0]) {
87
70
  const textToken = new state.Token('text', '', 0)
88
- state.tokens[n+1].children[0].children.push(textToken)
71
+ imageToken.children.push(textToken)
89
72
  }
90
- let i = 0
91
- while (0 < state.tokens[n+1].children[0].attrs.length) {
92
- if (state.tokens[n+1].children[0].attrs[i][0] === 'title') {
93
- state.tokens[n+1].children[0].attrs.splice(i, i + 1)
73
+ for (let i = 0; i < imageToken.attrs.length; i++) {
74
+ if (imageToken.attrs[i][0] === 'title') {
75
+ imageToken.attrs.splice(i, 1)
94
76
  break
95
- } else {
96
- state.tokens[n+1].children[0].attrJoin('title', '')
97
77
  }
98
- i++
99
78
  }
100
- //console.log(state.tokens[n+1].children[0])
101
79
  return true
102
80
  }
103
81
 
package/index.js CHANGED
@@ -1,29 +1,70 @@
1
1
  import { setCaptionParagraph } from 'p7d-markdown-it-p-captions'
2
2
  import { imgAttrToPCaption, setAltToLabel, setTitleToLabel } from './imgAttrToPCaption.js'
3
3
 
4
+ const htmlRegCache = {}
5
+ const classReg = /^f-(.+)$/
6
+ const blueskyEmbedReg = /^<blockquote class="bluesky-embed"[^]*?>[\s\S]*?$/
7
+
8
+ const getHtmlReg = (tag) => {
9
+ if (htmlRegCache[tag]) return htmlRegCache[tag]
10
+ let regexStr = '^<' + tag + ' ?[^>]*?>[\\s\\S]*?<\\/' + tag + '>(\\n| *?)(<script [^>]*?>(?:<\\/script>)?)? *(\\n|$)'
11
+ const reg = new RegExp(regexStr)
12
+ htmlRegCache[tag] = reg
13
+ return reg
14
+ }
15
+
16
+ const getCaptionName = (token) => {
17
+ if (!token.attrs) return ''
18
+ const attrs = token.attrs
19
+ for (let i = 0, len = attrs.length; i < len; i++) {
20
+ const attr = attrs[i]
21
+ if (attr[0] === 'class') {
22
+ const match = attr[1].match(classReg)
23
+ if (match) return match[1]
24
+ }
25
+ }
26
+ return ''
27
+ }
28
+
4
29
  const checkPrevCaption = (state, n, caption, fNum, sp, opt) => {
5
30
  if(n < 3) return caption
6
31
  const captionStartToken = state.tokens[n-3]
7
32
  const captionEndToken = state.tokens[n-1]
8
33
  if (captionStartToken === undefined || captionEndToken === undefined) return
9
-
10
34
  if (captionStartToken.type !== 'paragraph_open' && captionEndToken.type !== 'paragraph_close') return
11
-
12
35
  setCaptionParagraph(n-3, state, caption, fNum, sp, opt)
13
-
14
- let captionName = ''
15
- if (captionStartToken.attrs) {
16
- captionStartToken.attrs.forEach(attr => {
17
- let hasCaptionName = attr[1].match(/^f-(.+)$/)
18
- if (attr[0] === 'class' && hasCaptionName) captionName = hasCaptionName[1]
19
- })
20
- }
36
+ const captionName = getCaptionName(captionStartToken)
21
37
  if(!captionName) return
22
38
  caption.name = captionName
23
39
  caption.isPrev = true
24
40
  return
25
41
  }
26
42
 
43
+ const checkNextCaption = (state, en, caption, fNum, sp, opt) => {
44
+ if (en + 2 > state.tokens.length) return
45
+ const captionStartToken = state.tokens[en+1]
46
+ const captionEndToken = state.tokens[en+3]
47
+ if (captionStartToken === undefined || captionEndToken === undefined) return
48
+ if (captionStartToken.type !== 'paragraph_open' && captionEndToken.type !== 'paragraph_close') return
49
+ setCaptionParagraph(en+1, state, caption, fNum, sp, opt)
50
+ const captionName = getCaptionName(captionStartToken)
51
+ if(!captionName) return
52
+ caption.name = captionName
53
+ caption.isNext = true
54
+ return
55
+ }
56
+
57
+ const cleanCaptionTokenAttrs = (token, captionName) => {
58
+ const reg = new RegExp(' *?f-' + captionName)
59
+ if (!token.attrs) return
60
+ for (let i = token.attrs.length - 1; i >= 0; i--) {
61
+ if (token.attrs[i][0] === 'class') {
62
+ token.attrs[i][1] = token.attrs[i][1].replace(reg, '').trim()
63
+ if (token.attrs[i][1] === '') token.attrs.splice(i, 1)
64
+ }
65
+ }
66
+ }
67
+
27
68
  const changePrevCaptionPosition = (state, n, caption, opt) => {
28
69
  const captionStartToken = state.tokens[n-3]
29
70
  const captionInlineToken = state.tokens[n-2]
@@ -32,8 +73,13 @@ const changePrevCaptionPosition = (state, n, caption, opt) => {
32
73
  if (opt.imgAltCaption || opt.imgTitleCaption) {
33
74
  let isNoCaption = false
34
75
  if (captionInlineToken.attrs) {
35
- for (let attr of captionInlineToken.attrs) {
36
- if (attr[0] === 'class' && attr[1] === 'nocaption') isNoCaption = true
76
+ const attrs = captionInlineToken.attrs, len = attrs.length
77
+ for (let i = 0; i < len; i++) {
78
+ const attr = attrs[i]
79
+ if (attr[0] === 'class' && attr[1] === 'nocaption') {
80
+ isNoCaption = true
81
+ break
82
+ }
37
83
  }
38
84
  }
39
85
  if (isNoCaption) {
@@ -42,15 +88,7 @@ const changePrevCaptionPosition = (state, n, caption, opt) => {
42
88
  }
43
89
  }
44
90
 
45
- const attrReplaceReg = new RegExp(' *?f-' + caption.name)
46
- captionStartToken.attrs.forEach(attr => {
47
- if (attr[0] === 'class') {
48
- attr[1] = attr[1].replace(attrReplaceReg, '').trim()
49
- if(attr[1] === '') {
50
- captionStartToken.attrs.splice(captionStartToken.attrIndex('class'), 1)
51
- }
52
- }
53
- })
91
+ cleanCaptionTokenAttrs(captionStartToken, caption.name)
54
92
  captionStartToken.type = 'figcaption_open'
55
93
  captionStartToken.tag = 'figcaption'
56
94
  captionEndToken.type = 'figcaption_close'
@@ -60,40 +98,11 @@ const changePrevCaptionPosition = (state, n, caption, opt) => {
60
98
  return true
61
99
  }
62
100
 
63
- const checkNextCaption = (state, en, caption, fNum, sp, opt) => {
64
- if (en + 2 > state.tokens.length) return
65
- const captionStartToken = state.tokens[en+1]
66
- const captionEndToken = state.tokens[en+3]
67
- if (captionStartToken === undefined || captionEndToken === undefined) return
68
- if (captionStartToken.type !== 'paragraph_open' && captionEndToken.type !== 'paragraph_close') return
69
-
70
- setCaptionParagraph(en+1, state, caption, fNum, sp, opt)
71
-
72
- let captionName = ''
73
- if (captionStartToken.attrs) {
74
- captionStartToken.attrs.forEach(attr => {
75
- let hasCaptionName = attr[1].match(/^f-(.+)$/)
76
- if (attr[0] === 'class' && hasCaptionName) captionName = hasCaptionName[1]
77
- })
78
- }
79
- if(!captionName) return
80
- caption.name = captionName
81
- caption.isNext = true
82
- return
83
- }
84
-
85
101
  const changeNextCaptionPosition = (state, en, caption) => {
86
102
  const captionStartToken = state.tokens[en+2] // +1: text node for figure.
87
103
  const captionInlineToken = state.tokens[en+3]
88
104
  const captionEndToken = state.tokens[en+4]
89
- captionStartToken.attrs.forEach(attr => {
90
- if (attr[0] === 'class') {
91
- attr[1] = attr[1].replace(new RegExp(' *?f-' + caption.name), '').trim()
92
- if(attr[1] === '') {
93
- captionStartToken.attrs.splice(captionStartToken.attrIndex('class'), 1)
94
- }
95
- }
96
- })
105
+ cleanCaptionTokenAttrs(captionStartToken, caption.name)
97
106
  captionStartToken.type = 'figcaption_open'
98
107
  captionStartToken.tag = 'figcaption'
99
108
  captionEndToken.type = 'figcaption_close'
@@ -143,7 +152,6 @@ const wrapWithFigure = (state, range, checkTokenTagName, caption, replaceInstead
143
152
  }
144
153
  }
145
154
  // For vsce
146
- //console.log(caption)
147
155
  if(state.tokens[n].attrs && caption.name === 'img') {
148
156
  for (let attr of state.tokens[n].attrs) {
149
157
  figureStartToken.attrJoin(attr[0], attr[1])
@@ -153,12 +161,10 @@ const wrapWithFigure = (state, range, checkTokenTagName, caption, replaceInstead
153
161
  state.tokens.splice(en, 1, breakToken, figureEndToken, breakToken)
154
162
  state.tokens.splice(n, 1, figureStartToken, breakToken)
155
163
  en = en + 2
156
- //console.log(state.tokens[n].type, state.tokens[en].type)
157
164
  } else {
158
165
  state.tokens.splice(en+1, 0, figureEndToken, breakToken)
159
166
  state.tokens.splice(n, 0, figureStartToken, breakToken)
160
167
  en = en + 3
161
- //console.log(state.tokens[n].type, state.tokens[en].type)
162
168
  }
163
169
  range.start = n
164
170
  range.end = en
@@ -173,14 +179,18 @@ const checkCaption = (state, n, en, caption, fNum, sp, opt) => {
173
179
  }
174
180
 
175
181
  const figureWithCaption = (state, opt) => {
182
+ const tokens = state.tokens
183
+ const checkTypes = ['table', 'pre', 'blockquote']
184
+ const htmlTags = ['video', 'audio', 'iframe', 'blockquote', 'div']
185
+
176
186
  let n = 0
177
187
  let fNum = {
178
188
  img: 0,
179
189
  table: 0,
180
190
  }
181
- while (n < state.tokens.length) {
182
- const token = state.tokens[n]
183
- const nextToken = state.tokens[n+1]
191
+ while (n < tokens.length) {
192
+ const token = tokens[n]
193
+ const nextToken = tokens[n+1]
184
194
  let en = n
185
195
  let range = {
186
196
  start: n,
@@ -194,7 +204,7 @@ const figureWithCaption = (state, opt) => {
194
204
  nameSuffix: '',
195
205
  isPrev: false,
196
206
  isNext: false,
197
- };
207
+ }
198
208
  const sp = {
199
209
  attrs: [],
200
210
  isVideoIframe: false,
@@ -202,25 +212,23 @@ const figureWithCaption = (state, opt) => {
202
212
  hasImgCaption: false,
203
213
  }
204
214
 
205
- const checkTypes = ['table', 'pre', 'blockquote']
206
215
  let cti = 0
207
- //console.log(state.tokens[n].type, state.tokens[n].tag)
208
216
  while (cti < checkTypes.length) {
209
217
  if (token.type === checkTypes[cti] + '_open') {
210
218
  // for n-1 token is line-break
211
- if (n > 1 && state.tokens[n-2].type === 'figure_open') {
219
+ if (n > 1 && tokens[n-2].type === 'figure_open') {
212
220
  cti++; continue
213
221
  }
214
222
  checkToken = true
215
223
  checkTokenTagName = token.tag
216
224
  caption.name = checkTypes[cti]
217
225
  if (checkTypes[cti] === 'pre') {
218
- if (state.tokens[n+1].tag === 'code') caption.mark = 'pre-code'
219
- if (state.tokens[n+1].tag === 'samp') caption.mark = 'pre-samp'
226
+ if (tokens[n+1].tag === 'code') caption.mark = 'pre-code'
227
+ if (tokens[n+1].tag === 'samp') caption.mark = 'pre-samp'
220
228
  caption.name = caption.mark
221
229
  }
222
- while (en < state.tokens.length) {
223
- if(state.tokens[en].type === checkTokenTagName + '_close') {
230
+ while (en < tokens.length) {
231
+ if(tokens[en].type === checkTokenTagName + '_close') {
224
232
  break
225
233
  }
226
234
  en++
@@ -260,20 +268,19 @@ const figureWithCaption = (state, opt) => {
260
268
  }
261
269
 
262
270
  if (token.type === 'html_block') {
263
- const tags = ['video', 'audio', 'iframe', 'blockquote', 'div']
264
271
  let ctj = 0
265
272
  let hasTag
266
- while (ctj < tags.length) {
267
- if (tags[ctj] === 'div') {
273
+ while (ctj < htmlTags.length) {
274
+ if (htmlTags[ctj] === 'div') {
268
275
  // for vimeo
269
- hasTag = token.content.match(new RegExp('^<'+ tags[ctj] + ' ?[^>]*?><iframe[^>]*?>[\\s\\S]*?<\\/iframe><\\/' + tags[ctj] + '>(\\n| *?)(<script [^>]*?>(?:<\\/script>)?)? *(\\n|$)'))
270
- tags[ctj] = 'iframe'
276
+ hasTag = token.content.match(getHtmlReg('div'))
277
+ htmlTags[ctj] = 'iframe'
271
278
  sp.isVideoIframe = true
272
279
  } else {
273
- hasTag = token.content.match(new RegExp('^<'+ tags[ctj] + ' ?[^>]*?>[\\s\\S]*?<\\/' + tags[ctj] + '>(\\n| *?)(<script [^>]*?>(?:<\\/script>)?)? *(\\n|$)'))
280
+ hasTag = token.content.match(getHtmlReg(htmlTags[ctj]))
274
281
  }
275
- const blueskyContMatch = token.content.match(new RegExp('^<blockquote class="bluesky-embed"[^]*?>[\\s\\S]*$'))
276
- if (!(hasTag || (blueskyContMatch && tags[ctj] === 'blockquote'))) {
282
+ const blueskyContMatch = token.content.match(blueskyEmbedReg)
283
+ if (!(hasTag || (blueskyContMatch && htmlTags[ctj] === 'blockquote'))) {
277
284
  ctj++
278
285
  continue
279
286
  }
@@ -282,43 +289,44 @@ const figureWithCaption = (state, opt) => {
282
289
  token.content += '\n'
283
290
  }
284
291
  } else if (blueskyContMatch) {
285
- let addedCont = '';
292
+ let addedCont = ''
293
+ const tokensChildren = tokens
294
+ const tokensLength = tokensChildren.length
286
295
  let j = n + 1
287
296
  let hasEndBlockquote = true
288
- while (j < state.tokens.length) {
289
- const nextToken = state.tokens[j]
297
+ while (j < tokensLength) {
298
+ const nextToken = tokens[j]
290
299
  if (nextToken.type === 'inline' && /<\/blockquote> *<script[^>]*?><\/script>$/.test(nextToken.content)) {
291
300
  addedCont += nextToken.content + '\n'
292
- if (state.tokens[j + 1] && state.tokens[j + 1].type === 'paragraph_close') {
293
- state.tokens.splice(j + 1, 1)
301
+ if (tokens[j + 1] && tokens[j + 1].type === 'paragraph_close') {
302
+ tokens.splice(j + 1, 1)
294
303
  }
295
- state.tokens[j].content = ''
296
- state.tokens[j].children.forEach((child, i) => {
304
+ nextToken.content = ''
305
+ nextToken.children.forEach((child) => {
297
306
  child.content = ''
298
307
  })
299
308
  break
300
309
  }
301
310
  if (nextToken.type === 'paragraph_open') {
302
311
  addedCont += '\n'
303
- state.tokens.splice(j, 1)
312
+ tokens.splice(j, 1)
304
313
  continue
305
314
  }
306
- j++;
315
+ j++
307
316
  }
308
- token.content += addedCont;
317
+ token.content += addedCont
309
318
  if (!hasEndBlockquote) {
310
319
  ctj++
311
320
  continue
312
321
  }
313
322
  }
314
323
 
315
- checkTokenTagName = tags[ctj]
316
- caption.name = tags[ctj]
324
+ checkTokenTagName = htmlTags[ctj]
325
+ caption.name = htmlTags[ctj]
317
326
  checkToken = true
318
327
  if (checkTokenTagName === 'blockquote') {
319
328
  const classNameReg = /^<[^>]*? class="(twitter-tweet|instagram-media|text-post-media|bluesky-embed|mastodon-embed)"/
320
329
  const isIframeTypeBlockquote = token.content.match(classNameReg)
321
- //console.log(isIframeTypeBlockquote)
322
330
  if(isIframeTypeBlockquote) {
323
331
  sp.isIframeTypeBlockquote = true
324
332
  } else {
@@ -354,19 +362,22 @@ const figureWithCaption = (state, opt) => {
354
362
  let isMultipleImagesVertical = true
355
363
  checkToken = true
356
364
  caption.name = 'img'
357
- while (ntChildTokenIndex < nextToken.children.length) {
358
- const ntChildToken = nextToken.children[ntChildTokenIndex]
359
- if (ntChildTokenIndex === nextToken.children.length - 1) {
365
+ const children = nextToken.children
366
+ const childrenLength = children.length
367
+ while (ntChildTokenIndex < childrenLength) {
368
+ const ntChildToken = children[ntChildTokenIndex]
369
+ if (ntChildTokenIndex === childrenLength - 1) {
360
370
  let imageAttrs = ntChildToken.content.match(/^ *\{(.*?)\} *$/)
361
371
  if(ntChildToken.type === 'text' && imageAttrs) {
362
372
  imageAttrs = imageAttrs[1].split(/ +/)
363
373
  let iai = 0
364
- while (iai < imageAttrs.length) {
374
+ const attrsLength = imageAttrs.length
375
+ while (iai < attrsLength) {
365
376
  if (/^\./.test(imageAttrs[iai])) {
366
377
  imageAttrs[iai] = imageAttrs[iai].replace(/^\./, "class=")
367
378
  }
368
379
  if (/^#/.test(imageAttrs[iai])) {
369
- imageAttrs[iai] = imageAttrs[iai].replace(/^\#/, "id=")
380
+ imageAttrs[iai] = imageAttrs[iai].replace(/^#/, "id=")
370
381
  }
371
382
  let imageAttr = imageAttrs[iai].match(/^(.*?)="?(.*)"?$/)
372
383
  if (!imageAttr || !imageAttr[1]) {
@@ -411,8 +422,8 @@ const figureWithCaption = (state, opt) => {
411
422
  caption.nameSuffix = '-multiple'
412
423
  }
413
424
  ntChildTokenIndex = 0
414
- while (ntChildTokenIndex < nextToken.children.length) {
415
- const ccToken = nextToken.children[ntChildTokenIndex]
425
+ while (ntChildTokenIndex < childrenLength) {
426
+ const ccToken = children[ntChildTokenIndex]
416
427
  if (ccToken.type === 'text' && /^ *$/.test(ccToken.content)) {
417
428
  ccToken.content = ''
418
429
  }
@@ -428,8 +439,8 @@ const figureWithCaption = (state, opt) => {
428
439
  if (opt.imgTitleCaption) setTitleToLabel(state, n)
429
440
  checkCaption(state, n, en, caption, fNum, sp, opt)
430
441
 
431
- if (opt.oneImageWithoutCaption && state.tokens[n-1]) {
432
- if (state.tokens[n-1].type === 'list_item_open') checkToken = false
442
+ if (opt.oneImageWithoutCaption && tokens[n-1]) {
443
+ if (tokens[n-1].type === 'list_item_open') checkToken = false
433
444
  }
434
445
  if (checkToken && (opt.oneImageWithoutCaption || caption.isPrev || caption.isNext)) {
435
446
  if (caption.nameSuffix) checkTokenTagName += caption.nameSuffix
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peaceroad/markdown-it-figure-with-p-caption",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "A markdown-it plugin. For a paragraph with only one image, a table or code block or blockquote, and by writing a caption paragraph immediately before or after, they are converted into the figure element with the figcaption element.",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -17,12 +17,12 @@
17
17
  "url": "https://github.com/peaceroad/p7d-markdown-it-figure-with-p-caption/issues"
18
18
  },
19
19
  "devDependencies": {
20
- "@peaceroad/markdown-it-renderer-fence": "^0.1.1",
21
- "highlight.js": "^11.10.0",
20
+ "@peaceroad/markdown-it-renderer-fence": "^0.1.2",
21
+ "highlight.js": "^11.11.1",
22
22
  "markdown-it": "^14.1.0",
23
- "markdown-it-attrs": "^4.2.0"
23
+ "markdown-it-attrs": "^4.3.1"
24
24
  },
25
25
  "dependencies": {
26
- "p7d-markdown-it-p-captions": "^0.16.0"
26
+ "p7d-markdown-it-p-captions": "^0.17.0"
27
27
  }
28
28
  }