@peaceroad/markdown-it-figure-with-p-caption 0.9.1 → 0.10.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.
@@ -0,0 +1,5 @@
1
+ {
2
+ "cSpell.ignoreWords": [
3
+ "figcaption"
4
+ ]
5
+ }
package/index.js CHANGED
@@ -1,12 +1,15 @@
1
- import mditPCaption from 'p7d-markdown-it-p-captions'
1
+ import {setCaptionParagraph} from 'p7d-markdown-it-p-captions'
2
2
 
3
- const checkPrevCaption = (state, n, caption) => {
3
+ const checkPrevCaption = (state, n, caption, sp, opt) => {
4
4
  if(n < 3) return caption
5
5
  const captionStartToken = state.tokens[n-3]
6
6
  const captionEndToken = state.tokens[n-1]
7
7
  if (captionStartToken === undefined || captionEndToken === undefined) return caption
8
8
 
9
9
  if (captionStartToken.type !== 'paragraph_open' && captionEndToken.type !== 'paragraph_close') return caption
10
+
11
+ caption = setCaptionParagraph(n-3, state, caption, sp, opt)
12
+
10
13
  let captionName = ''
11
14
  if (captionStartToken.attrs) {
12
15
  captionStartToken.attrs.forEach(attr => {
@@ -16,7 +19,7 @@ const checkPrevCaption = (state, n, caption) => {
16
19
  }
17
20
  if(!captionName) return caption
18
21
  caption.name = captionName
19
- caption.hasPrev = true
22
+ caption.isPrev = true
20
23
  return caption
21
24
  }
22
25
 
@@ -52,13 +55,15 @@ const changePrevCaptionPosition = (state, n, caption) => {
52
55
  return true
53
56
  }
54
57
 
55
- const checkNextCaption = (state, en, caption) => {
58
+ const checkNextCaption = (state, en, caption, sp, opt) => {
56
59
  if (en + 2 > state.tokens.length) return caption
57
60
  const captionStartToken = state.tokens[en+1]
58
61
  const captionEndToken = state.tokens[en+3]
59
62
  if (captionStartToken === undefined || captionEndToken === undefined) return caption
60
63
  if (captionStartToken.type !== 'paragraph_open' && captionEndToken.type !== 'paragraph_close') return caption
61
64
 
65
+ caption = setCaptionParagraph(en+1, state, caption, sp, opt)
66
+
62
67
  let captionName = ''
63
68
  if (captionStartToken.attrs) {
64
69
  captionStartToken.attrs.forEach(attr => {
@@ -68,7 +73,7 @@ const checkNextCaption = (state, en, caption) => {
68
73
  }
69
74
  if(!captionName) return caption
70
75
  caption.name = captionName
71
- caption.hasNext = true
76
+ caption.isNext = true
72
77
  return caption
73
78
  }
74
79
 
@@ -93,18 +98,18 @@ const changeNextCaptionPosition = (state, en, caption) => {
93
98
  return true
94
99
  }
95
100
 
96
- const wrapWithFigure = (state, range, tagName, caption, replaceInsteadOfWrap, sp, opt) => {
101
+ const wrapWithFigure = (state, range, checkTokenTagName, caption, replaceInsteadOfWrap, sp, opt) => {
97
102
  let n = range.start
98
103
  let en = range.end
99
104
  const figureStartToken = new state.Token('figure_open', 'figure', 1)
100
- figureStartToken.attrSet('class', 'f-' + tagName)
105
+ figureStartToken.attrSet('class', 'f-' + checkTokenTagName)
101
106
  if (sp.isVideoIframe) {
102
107
  figureStartToken.attrSet('class', 'f-video')
103
108
  }
104
- if (sp.isIframeTypeBlockQuote) {
109
+ if (sp.isIframeTypeBlockquote) {
105
110
  let figureClassThatWrapsIframeTypeBlockquote = 'i-frame'
106
- if (caption.prev || caption.next) {
107
- if (caption.name === 'img') {
111
+ if (caption.isPrev || caption.isNext) {
112
+ if (caption.name === 'blockquote' || caption.name === 'img') {
108
113
  figureClassThatWrapsIframeTypeBlockquote = 'f-img'
109
114
  }
110
115
  figureStartToken.attrSet('class', figureClassThatWrapsIframeTypeBlockquote)
@@ -113,13 +118,15 @@ const wrapWithFigure = (state, range, tagName, caption, replaceInsteadOfWrap, sp
113
118
  figureStartToken.attrSet('class', figureClassThatWrapsIframeTypeBlockquote)
114
119
  }
115
120
  }
116
- if(/pre-(?:code|samp)/.test(tagName) && opt.roleDocExample) {
121
+
122
+
123
+ if(/pre-(?:code|samp)/.test(checkTokenTagName) && opt.roleDocExample) {
117
124
  figureStartToken.attrSet('role', 'doc-example')
118
125
  }
119
126
  const figureEndToken = new state.Token('figure_close', 'figure', -1)
120
127
  const breakToken = new state.Token('text', '', 0)
121
128
  breakToken.content = '\n'
122
- if (opt.styleProcess && caption.hasNext && sp.attrs.length > 0) {
129
+ if (opt.styleProcess && caption.isNext && sp.attrs.length > 0) {
123
130
  for (let attr of sp.attrs) {
124
131
  figureStartToken.attrJoin(attr[0], attr[1])
125
132
  }
@@ -147,10 +154,10 @@ const wrapWithFigure = (state, range, tagName, caption, replaceInsteadOfWrap, sp
147
154
  return range
148
155
  }
149
156
 
150
- const checkCaption = (state, n, en, caption) => {
151
- caption = checkPrevCaption(state, n, caption)
152
- if (caption.hasPrev) return caption
153
- caption = checkNextCaption(state, en, caption)
157
+ const checkCaption = (state, n, en, caption, sp, opt) => {
158
+ caption = checkPrevCaption(state, n, caption, sp, opt)
159
+ if (caption.isPrev) return caption
160
+ caption = checkNextCaption(state, en, caption, sp, opt)
154
161
  return caption
155
162
  }
156
163
 
@@ -166,63 +173,71 @@ const figureWithCaption = (state, opt) => {
166
173
  }
167
174
  let checkToken = false
168
175
  let hasCloseTag = false
169
- let tagName = ''
176
+ let checkTokenTagName = ''
170
177
  let caption = {
178
+ mark: '',
171
179
  name: '',
172
180
  nameSuffix: '',
173
- hasPrev: false,
174
- hasNext: false,
181
+ isPrev: false,
182
+ isNext: false,
175
183
  };
176
184
  const sp = {
177
185
  attrs: [],
178
186
  isVideoIframe: false,
179
- isIframeTypeBlockQuote: false,
187
+ isIframeTypeBlockquote: false,
180
188
  hasImgCaption: false,
181
189
  }
182
190
 
183
- const checkTags = ['table', 'pre', 'blockquote']
191
+ const checkTypes = ['table', 'pre', 'blockquote']
184
192
  let cti = 0
185
- while (cti < checkTags.length) {
186
- if (token.type === checkTags[cti] + '_open') {
187
- if (n > 1) {
188
- if (state.tokens[n-2].type === 'figure_open') { // +linebreak
189
- cti++; continue;
190
- }
193
+ //console.log(state.tokens[n].type, state.tokens[n].tag)
194
+ while (cti < checkTypes.length) {
195
+ if (token.type === checkTypes[cti] + '_open') {
196
+ // for n-1 token is line-break
197
+ if (n > 1 && state.tokens[n-2].type === 'figure_open') {
198
+ cti++; continue
191
199
  }
192
200
  checkToken = true
193
- caption.name = checkTags[cti]
194
- tagName = token.tag
201
+ checkTokenTagName = token.tag
202
+ caption.name = checkTypes[cti]
203
+ if (checkTypes[cti] === 'pre') {
204
+ if (state.tokens[n+1].tag === 'code') caption.mark = 'pre-code'
205
+ if (state.tokens[n+1].tag === 'samp') caption.mark = 'pre-samp'
206
+ caption.name = caption.mark
207
+ }
195
208
  while (en < state.tokens.length) {
196
- if(state.tokens[en].type === tagName + '_close') {
209
+ if(state.tokens[en].type === checkTokenTagName + '_close') {
197
210
  hasCloseTag = true
198
211
  break
199
212
  }
200
213
  en++
201
214
  }
202
215
  range.end = en
203
- caption = checkCaption(state, n, en, caption)
204
- if (caption.hasPrev || caption.hasNext) {
205
- range = wrapWithFigure(state, range, tagName, caption, false, sp, opt)
216
+ caption = checkCaption(state, n, en, caption, sp, opt)
217
+ if (caption.isPrev || caption.isNext) {
218
+ range = wrapWithFigure(state, range, checkTokenTagName, caption, false, sp, opt)
206
219
  }
207
220
  break
208
221
  }
209
222
 
210
- if(token.type === 'fence') {
223
+ if (token.type === 'fence') {
211
224
  if (token.tag === 'code' && token.block) {
212
225
  checkToken = true
213
- let isSampInfo = false
226
+ let isSamp = false
214
227
  if (/^ *(?:samp|shell|console)(?:(?= )|$)/.test(token.info)) {
215
228
  token.tag = 'samp'
216
- isSampInfo = true
229
+ isSamp = true
217
230
  }
218
- if (isSampInfo) {
219
- tagName = 'pre-samp'
231
+ if (isSamp) {
232
+ checkTokenTagName = 'pre-samp'
233
+ caption.name = 'pre-samp'
220
234
  } else {
221
- tagName = 'pre-code'
235
+ checkTokenTagName = 'pre-code'
236
+ caption.name = 'pre-code'
222
237
  }
223
- caption = checkCaption(state, n, en, caption)
224
- if (caption.hasPrev || caption.hasNext) {
225
- range = wrapWithFigure(state, range, tagName, caption, false, sp, opt)
238
+ caption = checkCaption(state, n, en, caption, sp, opt)
239
+ if (caption.isPrev || caption.isNext) {
240
+ range = wrapWithFigure(state, range, checkTokenTagName, caption, false, sp, opt)
226
241
  break
227
242
  }
228
243
  }
@@ -243,13 +258,13 @@ const figureWithCaption = (state, opt) => {
243
258
  if ((hasTag[2] && hasTag[3] !== '\n') || (hasTag[1] !== '\n' && hasTag[2] === undefined)) {
244
259
  token.content += '\n'
245
260
  }
246
- tagName = tags[ctj]
261
+ checkTokenTagName = tags[ctj]
247
262
  caption.name = tags[ctj]
248
263
  checkToken = true
249
- if (tagName === 'blockquote') {
264
+ if (checkTokenTagName === 'blockquote') {
250
265
  //text-post-media: threads
251
266
  if(/^<[^>]*? class="(?:twitter-tweet|instagram-media|text-post-media|bluesky-embed)"/.test(token.content)) {
252
- sp.isIframeTypeBlockQuote = true
267
+ sp.isIframeTypeBlockquote = true
253
268
  } else {
254
269
  ctj++
255
270
  continue
@@ -258,47 +273,20 @@ const figureWithCaption = (state, opt) => {
258
273
  break
259
274
  }
260
275
  if (!checkToken) {n++; continue;}
261
- if (tagName === 'iframe') {
276
+ if (checkTokenTagName === 'iframe') {
262
277
  if(/^<[^>]*? src="https:\/\/(?:www.youtube-nocookie.com|player.vimeo.com)\//i.test(token.content)) {
263
278
  sp.isVideoIframe = true
264
279
  }
265
280
  }
266
- if(sp.isIframeTypeBlockQuote) {
267
- if(n > 2) {
268
- if (state.tokens[n-2].children) {
269
- if (state.tokens[n-2].children.length > 1) {
270
- if (state.tokens[n-2].children[1].attrs) {
271
- if (state.tokens[n-2].children[1].attrs[0][0] === 'class') {
272
- if (state.tokens[n-2].children[1].attrs[0][1] === 'f-img-label') {
273
- sp.hasImgCaption = true
274
- /* For now, I think I should use figure instead of blockquoe for caption. */
275
- }
276
- }
277
- }
278
- }
279
- }
280
- }
281
- if (n + 2 < state.tokens.length) {
282
- if (state.tokens[n+2].children) {
283
- if (state.tokens[n+2].children.length > 1) {
284
- if (state.tokens[n+2].children[1].attrs) {
285
- if (state.tokens[n+2].children[1].attrs[0][0] === 'class' &&
286
- state.tokens[n+2].children[1].attrs[0][1] === 'f-img-label') {
287
- sp.hasImgCaption = true
288
- }
289
- }
290
- }
291
- }
292
- }
293
- }
294
- caption = checkCaption(state, n, en, caption)
295
- if (caption.hasPrev || caption.hasNext) {
296
- range = wrapWithFigure(state, range, tagName, caption, false, sp, opt)
281
+
282
+ caption = checkCaption(state, n, en, caption, sp, opt)
283
+ if (caption.isPrev || caption.isNext) {
284
+ range = wrapWithFigure(state, range, checkTokenTagName, caption, false, sp, opt)
297
285
  n = en + 2
298
- } else if ((opt.iframeWithoutCaption && (tagName === 'iframe')) ||
299
- (opt.videoWithoutCaption && (tagName === 'video')) ||
300
- (opt.iframeTypeBlockquoteWithoutCaption && (tagName === 'blockquote'))) {
301
- range = wrapWithFigure(state, range, tagName, caption, false, sp, opt)
286
+ } else if ((opt.iframeWithoutCaption && (checkTokenTagName === 'iframe')) ||
287
+ (opt.videoWithoutCaption && (checkTokenTagName === 'video')) ||
288
+ (opt.iframeTypeBlockquoteWithoutCaption && (checkTokenTagName === 'blockquote'))) {
289
+ range = wrapWithFigure(state, range, checkTokenTagName, caption, false, sp, opt)
302
290
  n = en + 2
303
291
  }
304
292
  }
@@ -348,7 +336,7 @@ const figureWithCaption = (state, opt) => {
348
336
  isMultipleImagesHorizontal = false
349
337
  }
350
338
  } else if (ntChildToken.type === 'softbreak') {
351
- isMultipleImagesHorizontal = false
339
+ isMultipleImagesHorizontal = false
352
340
  if (isMultipleImagesHorizontal) {
353
341
  isMultipleImagesVertical = false
354
342
  }
@@ -370,26 +358,26 @@ const figureWithCaption = (state, opt) => {
370
358
  while (ntChildTokenIndex < nextToken.children.length) {
371
359
  const ccToken = nextToken.children[ntChildTokenIndex]
372
360
  if (ccToken.type === 'text' && /^ *$/.test(ccToken.content)) {
373
- ccToken.content = ''
361
+ ccToken.content = ''
374
362
  }
375
363
  ntChildTokenIndex++
376
364
  }
377
365
  }
378
366
  en = n + 2
379
367
  range.end = en
380
- tagName = 'img'
368
+ checkTokenTagName = 'img'
381
369
  nextToken.children[0].type = 'image'
382
370
 
383
- if (opt.imgAltCaption) setAltToLabel(state, n, en, tagName, caption, opt)
384
- if (opt.imgTitleCaption) setTitleToLabel(state, n, en, tagName, caption, opt)
385
- caption = checkCaption(state, n, en, caption)
371
+ if (opt.imgAltCaption) setAltToLabel(state, n)
372
+ if (opt.imgTitleCaption) setTitleToLabel(state, n, en, checkTokenTagName, caption, opt)
373
+ caption = checkCaption(state, n, en, caption, sp, opt)
386
374
 
387
375
  if (opt.oneImageWithoutCaption && state.tokens[n-1]) {
388
376
  if (state.tokens[n-1].type === 'list_item_open') checkToken = false
389
377
  }
390
- if (checkToken && (opt.oneImageWithoutCaption || caption.hasPrev || caption.hasNext)) {
391
- if (caption.nameSuffix) tagName += caption.nameSuffix
392
- range = wrapWithFigure(state, range, tagName, caption, true, sp, opt)
378
+ if (checkToken && (opt.oneImageWithoutCaption || caption.isPrev || caption.isNext)) {
379
+ if (caption.nameSuffix) checkTokenTagName += caption.nameSuffix
380
+ range = wrapWithFigure(state, range, checkTokenTagName, caption, true, sp, opt)
393
381
  }
394
382
  }
395
383
 
@@ -397,12 +385,12 @@ const figureWithCaption = (state, opt) => {
397
385
 
398
386
  n = range.start
399
387
  en = range.end
400
- if (caption.hasPrev) {
388
+ if (caption.isPrev) {
401
389
  changePrevCaptionPosition(state, n, caption)
402
390
  n = en + 1
403
391
  continue
404
392
  }
405
- if (caption.hasNext) {
393
+ if (caption.isNext) {
406
394
  changeNextCaptionPosition(state, en, caption)
407
395
  n = en + 4
408
396
  continue
@@ -412,11 +400,11 @@ const figureWithCaption = (state, opt) => {
412
400
  return
413
401
  }
414
402
 
415
- const setAltToLabel = (state, n, en, tagName, caption, opt) => {
403
+ const setAltToLabel = (state, n) => {
416
404
  if (n < 2) return false
417
405
  if (state.tokens[n+1].children[0].type !== 'image' || !state.tokens[n-2].children) return false
418
- if (state.tokens[n-2].children[2]) {
419
- state.tokens[n+1].content = state.tokens[n+1].content.replace(/^!\[.*?\]/, '![' + state.tokens[n-2].children[2].content + ']')
406
+ if (state.tokens[n-2].children) {
407
+ state.tokens[n+1].content = state.tokens[n+1].content.replace(/^!\[.*?\]/, '![' + state.tokens[n-2].children[0].content + ']')
420
408
  if (!state.tokens[n+1].children[0].children[0]) {
421
409
  const textToken = new state.Token('text', '', 0)
422
410
  state.tokens[n+1].children[0].children.push(textToken)
@@ -434,7 +422,7 @@ const setAltToLabel = (state, n, en, tagName, caption, opt) => {
434
422
  return true
435
423
  }
436
424
 
437
- const setTitleToLabel = (state, n, en, tagName, caption, opt) => {
425
+ const setTitleToLabel = (state, n, en, checkTokenTagName, caption, opt) => {
438
426
  if (n < 2) return false
439
427
  if (state.tokens[n+1].children[0].type !== 'image') return false
440
428
  if (!state.tokens[n-2].children[0]) return false
@@ -547,21 +535,11 @@ const mditFigureWithPCaption = (md, option) => {
547
535
  }
548
536
 
549
537
  if (opt.imgAltCaption || opt.imgTitleCaption) {
538
+ opt.oneImageWithoutCaption = false
550
539
  md.block.ruler.before('paragraph', 'img_attr_caption', (state) => {
551
540
  imgAttrToPCaption(state, state.line, opt)
552
541
  })
553
542
  }
554
- md.use(mditPCaption, {
555
- classPrefix: opt.classPrefix,
556
- dquoteFilename: opt.dquoteFilename,
557
- strongFilename: opt.strongFilename,
558
- hasNumClass: opt.hasNumClass,
559
- bLabel: opt.bLabel,
560
- strongLabel: opt.strongLabel,
561
- jointSpaceUseHalfWidth: opt.jointSpaceUseHalfWidth,
562
- removeUnnumberedLabel: opt.removeUnnumberedLabel,
563
- removeUnnumberedLabelExceptMarks: opt.removeUnnumberedLabelExceptMarks,
564
- })
565
543
 
566
544
  //If nextCaption has `{}` style and `f-img-multipleImages`, when upgraded to markdown-it-attrs@4.2.0, the existing script will have `{}` style on nextCaption. Therefore, since markdown-it-attrs is md.core.ruler.before('linkify'), figure_with_caption will be processed after it.
567
545
  md.core.ruler.before('replacements', 'figure_with_caption', (state) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peaceroad/markdown-it-figure-with-p-caption",
3
- "version": "0.9.1",
3
+ "version": "0.10.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",
@@ -20,6 +20,6 @@
20
20
  "markdown-it-attrs": "^4.2.0"
21
21
  },
22
22
  "dependencies": {
23
- "p7d-markdown-it-p-captions": "^0.14.0"
23
+ "p7d-markdown-it-p-captions": "^0.15.1"
24
24
  }
25
25
  }
@@ -0,0 +1,51 @@
1
+ [Markdown]
2
+ ![A caption.](cat.jpg)
3
+
4
+ [HTML]
5
+ <figure class="f-img">
6
+ <figcaption><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> A caption.</figcaption>
7
+ <img src="cat.jpg" alt="">
8
+ </figure>
9
+
10
+
11
+ [Markdown]
12
+ ![Figure. A caption.](cat.jpg)
13
+
14
+ [HTML]
15
+ <figure class="f-img">
16
+ <figcaption><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> A caption.</figcaption>
17
+ <img src="cat.jpg" alt="">
18
+ </figure>
19
+
20
+
21
+ [Markdown]
22
+ ![](cat.jpg)
23
+
24
+ [HTML]
25
+ <figure class="f-img">
26
+ <img src="cat.jpg" alt="">
27
+ </figure>
28
+
29
+
30
+ [Markdown]
31
+ Figure. A caption.
32
+
33
+ ![](cat.jpg)
34
+
35
+ [HTML]
36
+ <p>Figure. A caption.</p>
37
+ <figure class="f-img">
38
+ <img src="cat.jpg" alt="">
39
+ </figure>
40
+
41
+
42
+ [Markdown]
43
+ ![Figure 12. A caption.](cat.jpg)
44
+
45
+ [HTML]
46
+ <figure class="f-img">
47
+ <figcaption><span class="f-img-label">Figure 12<span class="f-img-label-joint">.</span></span> A caption.</figcaption>
48
+ <img src="cat.jpg" alt="">
49
+ </figure>
50
+
51
+
@@ -1,89 +1,84 @@
1
1
  [Markdown]
2
- ![A caption.](cat.jpg)
2
+ ![図1 キャプション](cat.jpg)
3
3
 
4
4
  [HTML]
5
5
  <figure class="f-img">
6
- <figcaption><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> A caption.</figcaption>
6
+ <figcaption><span class="f-img-label">図1<span class="f-img-label-joint"> </span></span>キャプション</figcaption>
7
7
  <img src="cat.jpg" alt="">
8
8
  </figure>
9
9
 
10
10
 
11
11
  [Markdown]
12
- ![Figure. A caption.](cat.jpg)
13
-
14
- [HTML]
15
- <figure class="f-img">
16
- <figcaption><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> A caption.</figcaption>
17
- <img src="cat.jpg" alt="">
18
- </figure>
19
-
12
+ キャプション
20
13
 
21
- [Markdown]
22
- ![](cat.jpg)
14
+ ![図1 キャプション](cat.jpg)
23
15
 
24
16
  [HTML]
17
+ <p>図 キャプション</p>
25
18
  <figure class="f-img">
19
+ <figcaption><span class="f-img-label">図1<span class="f-img-label-joint"> </span></span>キャプション</figcaption>
26
20
  <img src="cat.jpg" alt="">
27
21
  </figure>
28
22
 
29
23
 
30
24
  [Markdown]
31
- Figure. A caption.
25
+ ![A caption.](cat.jpg)
32
26
 
33
- ![](cat.jpg)
27
+ ![図 A caption.](cat.jpg)
34
28
 
35
29
  [HTML]
36
- <p class="f-img"><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> A caption.</p>
37
30
  <figure class="f-img">
31
+ <figcaption><span class="f-img-label">図<span class="f-img-label-joint"> </span></span>A caption.</figcaption>
38
32
  <img src="cat.jpg" alt="">
39
33
  </figure>
40
-
41
-
42
- [Markdown]
43
- ![Figure 12. A caption.](cat.jpg)
44
-
45
- [HTML]
46
34
  <figure class="f-img">
47
- <figcaption><span class="f-img-label">Figure 12<span class="f-img-label-joint">.</span></span> A caption.</figcaption>
35
+ <figcaption><span class="f-img-label">図</span> A caption.</figcaption>
48
36
  <img src="cat.jpg" alt="">
49
37
  </figure>
50
38
 
51
39
 
52
40
  [Markdown]
53
- ![図1 キャプション](cat.jpg)
54
41
 
55
- [HTML]
56
- <figure class="f-img">
57
- <figcaption><span class="f-img-label">図1<span class="f-img-label-joint"> </span></span>キャプション</figcaption>
58
- <img src="cat.jpg" alt="">
59
- </figure>
42
+ ```
43
+ code
44
+ ```
60
45
 
61
-
62
- [Markdown]
63
- 図 キャプション
64
-
65
- ![図1 キャプション](cat.jpg)
46
+ ![A caption.](cat.jpg)
66
47
 
67
48
  [HTML]
68
- <p class="f-img"><span class="f-img-label">図</span> キャプション</p>
49
+ <pre><code>code
50
+ </code></pre>
69
51
  <figure class="f-img">
70
- <figcaption><span class="f-img-label">図1<span class="f-img-label-joint"> </span></span>キャプション</figcaption>
52
+ <figcaption><span class="f-img-label">図<span class="f-img-label-joint"> </span></span>A caption.</figcaption>
71
53
  <img src="cat.jpg" alt="">
72
54
  </figure>
73
55
 
74
56
 
75
57
  [Markdown]
76
- ![A caption.](cat.jpg)
77
58
 
78
- ![図 A caption.](cat.jpg)
59
+ | h1 | h2 |
60
+ |----|----|
61
+ | 11 | 12 |
62
+
63
+ ![A caption.](cat.jpg)
79
64
 
80
65
  [HTML]
66
+ <table>
67
+ <thead>
68
+ <tr>
69
+ <th>h1</th>
70
+ <th>h2</th>
71
+ </tr>
72
+ </thead>
73
+ <tbody>
74
+ <tr>
75
+ <td>11</td>
76
+ <td>12</td>
77
+ </tr>
78
+ </tbody>
79
+ </table>
81
80
  <figure class="f-img">
82
81
  <figcaption><span class="f-img-label">図<span class="f-img-label-joint"> </span></span>A caption.</figcaption>
83
82
  <img src="cat.jpg" alt="">
84
83
  </figure>
85
- <figure class="f-img">
86
- <figcaption><span class="f-img-label">図</span> A caption.</figcaption>
87
- <img src="cat.jpg" alt="">
88
- </figure>
89
84
 
@@ -42,7 +42,7 @@ Figure. A caption.
42
42
  ![](cat.jpg)
43
43
 
44
44
  [HTML]
45
- <p class="f-img"><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> A caption.</p>
45
+ <p>Figure. A caption.</p>
46
46
  <figure class="f-img">
47
47
  <img src="cat.jpg" alt="">
48
48
  </figure>
@@ -58,33 +58,3 @@ Figure. A caption.
58
58
  </figure>
59
59
 
60
60
 
61
- [Markdown]
62
- ![猫](cat.jpg "図1 キャプション")
63
-
64
- [HTML]
65
- <figure class="f-img">
66
- <figcaption><span class="f-img-label">図1<span class="f-img-label-joint"> </span></span>キャプション</figcaption>
67
- <img src="cat.jpg" alt="猫">
68
- </figure>
69
-
70
- [Markdown]
71
- ![](cat.jpg "図 キャプション")
72
-
73
- [HTML]
74
- <figure class="f-img">
75
- <figcaption><span class="f-img-label">図</span> キャプション</figcaption>
76
- <img src="cat.jpg" alt="">
77
- </figure>
78
-
79
-
80
- [Markdown]
81
- 図 キャプション
82
-
83
- ![猫](cat.jpg "図23 Caption")
84
-
85
- [HTML]
86
- <p class="f-img"><span class="f-img-label">図</span> キャプション</p>
87
- <figure class="f-img">
88
- <figcaption><span class="f-img-label">図23</span> Caption</figcaption>
89
- <img src="cat.jpg" alt="猫">
90
- </figure>
@@ -0,0 +1,30 @@
1
+ [Markdown]
2
+ ![猫](cat.jpg "図1 キャプション")
3
+
4
+ [HTML]
5
+ <figure class="f-img">
6
+ <figcaption><span class="f-img-label">図1<span class="f-img-label-joint"> </span></span>キャプション</figcaption>
7
+ <img src="cat.jpg" alt="猫">
8
+ </figure>
9
+
10
+ [Markdown]
11
+ ![](cat.jpg "図 キャプション")
12
+
13
+ [HTML]
14
+ <figure class="f-img">
15
+ <figcaption><span class="f-img-label">図</span> キャプション</figcaption>
16
+ <img src="cat.jpg" alt="">
17
+ </figure>
18
+
19
+
20
+ [Markdown]
21
+ 図 キャプション
22
+
23
+ ![猫](cat.jpg "図23 Caption")
24
+
25
+ [HTML]
26
+ <p>図 キャプション</p>
27
+ <figure class="f-img">
28
+ <figcaption><span class="f-img-label">図23</span> Caption</figcaption>
29
+ <img src="cat.jpg" alt="猫">
30
+ </figure>
@@ -700,3 +700,16 @@ console.log('Hello world')
700
700
  <figcaption><span class="f-pre-code-label">コード</span> Hello world</figcaption>
701
701
  </figure>
702
702
 
703
+
704
+ [Markdown]
705
+
706
+ ```
707
+ code
708
+ ```
709
+
710
+ ![A caption.](cat.jpg)
711
+
712
+ [HTML]
713
+ <pre><code>code
714
+ </code></pre>
715
+ <p><img src="cat.jpg" alt="A caption."></p>
@@ -43,3 +43,17 @@ Figure. A Caption.
43
43
  </figure>
44
44
 
45
45
 
46
+ [Markdown]
47
+
48
+ ```
49
+ code
50
+ ```
51
+
52
+ ![A caption.](cat.jpg)
53
+
54
+ [HTML]
55
+ <pre><code>code
56
+ </code></pre>
57
+ <figure class="f-img">
58
+ <img src="cat.jpg" alt="A caption.">
59
+ </figure>
package/test/test.js CHANGED
@@ -50,11 +50,10 @@ const mdConsole = mdit({
50
50
  return highlightjs.highlight(str, { language: lang }).value
51
51
  } catch (__) {}
52
52
  }
53
- return ''
53
+ return str
54
54
  }
55
55
  }).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
56
56
 
57
-
58
57
  let __dirname = path.dirname(new URL(import.meta.url).pathname)
59
58
  const isWindows = (process.platform === 'win32')
60
59
  if (isWindows) {
@@ -126,7 +125,7 @@ const runTest = (process, pat, pass, testId) => {
126
125
  while(n <= end) {
127
126
 
128
127
  if (!ms[n]
129
- // || n != 3
128
+ //|| n != 24
130
129
  ) {
131
130
  n++
132
131
  continue
@@ -135,6 +134,7 @@ const runTest = (process, pat, pass, testId) => {
135
134
  const m = ms[n].markdown;
136
135
  const h = process.render(m)
137
136
  console.log('Test: ' + n + ' >>>');
137
+ //console.log(ms[n].markdown);
138
138
  try {
139
139
  assert.strictEqual(h, ms[n].html);
140
140
  } catch(e) {
@@ -161,22 +161,20 @@ pass = runTest(mdVideoWithoutCaption, testData.videoWithoutCaption, pass)
161
161
  pass = runTest(mdConsole, testData.console, pass)
162
162
 
163
163
 
164
- opt.oneImageWithoutCaption = false
165
-
166
164
  opt.imgAltCaption = 'Figure'
167
165
  const mdImgAltCaption = mdit({html: true}).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
168
- pass = runTest(mdImgAltCaption, testData.imgAltCaption, pass, [1, 5])
166
+ pass = runTest(mdImgAltCaption, testData.imgAltCaption.replace(/\.txt$/, '.en.txt'), pass)
169
167
  opt.imgAltCaption = '図'
170
168
  const mdImgAltCaptionJa = mdit({html: true}).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
171
- pass = runTest(mdImgAltCaptionJa, testData.imgAltCaption, pass, [6 , 99])
169
+ pass = runTest(mdImgAltCaptionJa, testData.imgAltCaption.replace(/\.txt$/, '.ja.txt'), pass)
172
170
 
173
171
  opt.imgAltCaption = false
174
172
 
175
173
  opt.imgTitleCaption = 'Figure'
176
174
  const mdImgTitleCaption = mdit({html: true}).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
177
- pass = runTest(mdImgTitleCaption, testData.imgTitleCaption, pass, [1, 6])
175
+ pass = runTest(mdImgTitleCaption, testData.imgTitleCaption.replace(/\.txt$/, '.en.txt'), pass)
178
176
  opt.imgTitleCaption = '図'
179
177
  const mdImgTitleCaptionJa = mdit({html: true}).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
180
- pass = runTest(mdImgTitleCaptionJa, testData.imgTitleCaption, pass, [7, 99])
178
+ pass = runTest(mdImgTitleCaptionJa, testData.imgTitleCaption.replace(/.txt$/, '.ja.txt'), pass)
181
179
 
182
180
  if (pass) console.log('Passed all test.')