@peaceroad/markdown-it-figure-with-p-caption 0.4.5 → 0.5.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.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  This is a markdown-it plugin.
4
4
 
5
- For a paragraph with only one image, a table or code block or a blockquote, and by writing a caption paragraph immediately before or after, they are converted into the figure element with the figcaption element.
5
+ For a paragraph with one image/images only, a table or code block or a blockquote, and by writing a caption paragraph immediately before or after, they are converted into the figure element with the figcaption element.
6
6
 
7
7
  1. Check that the element: one image only paragraph, table, code block, samp block, blockquote, and video.
8
8
  2. Check if this element has a caption paragraph immediately before or after it
@@ -10,7 +10,9 @@ For a paragraph with only one image, a table or code block or a blockquote, and
10
10
 
11
11
  The figcaption behavior of this plugin depends on [p7d-markdown-it-p-captions](https://www.npmjs.com/package/p7d-markdown-it-p-captions).
12
12
 
13
- Note. If code block language setting is "samp", change it to use samp element instead of code element.
13
+ Notice. If code block language setting is "samp", change it to use samp element instead of code element.
14
+
15
+ Notice. It assumes simultaneous use of `markdown-it-attrs`. However, if there is `{.style}` at the end of the image-only paragraph, and the next paragraph is a caption, processing is not handled well with `markdown-it-attrs` alone, so in order to normalize it, {} The processing is written in this plugin. (This process can be turned off by specifying `{styleProcess: false}`.) [0.5.0]
14
16
 
15
17
  Use it as follows.
16
18
 
@@ -96,7 +98,6 @@ A paragraph.
96
98
  <p>A paragraph.</p>
97
99
 
98
100
 
99
-
100
101
  [Markdown]
101
102
  A paragraph.
102
103
 
@@ -121,7 +122,7 @@ A paragraph.
121
122
  [Markdown]
122
123
  A paragraph.
123
124
 
124
- Quote. A Caption.
125
+ Source. A Caption.
125
126
 
126
127
  > A quoted paragraph.
127
128
 
@@ -130,7 +131,7 @@ A paragraph.
130
131
  [HTML]
131
132
  <p>A paragraph.</p>
132
133
  <figure class="f-blockquote">
133
- <figcaption><span class="f-blockquote-label">Code<span class="f-blockquote-label-joint">.</span></span> A Caption.</figcaption>
134
+ <figcaption><span class="f-blockquote-label">Source<span class="f-blockquote-label-joint">.</span></span> A Caption.</figcaption>
134
135
  <blockquote>
135
136
  <p>A quoted paragraph.</p>
136
137
  </blockquote>
@@ -219,40 +220,85 @@ A paragraph.
219
220
  [Markdown]
220
221
  A paragraph.
221
222
 
222
- Quote. Twitter Post.
223
+ Figure. Twitter Post.
223
224
 
224
- <blockquote class="twitter-tweet"><p lang="ja" dir="ltr">XXXXX <a href="https://t.co/XXXXX">https://t.co/XXXXX</a></p>&mdash; User (@twitter) <a href="https://twitter.com/UserID/status/XXXXX">August 4, 2022</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
225
+ <blockquote class="twitter-tweet"><p lang="ja" dir="ltr">XXXXX <a href="https://t.co/XXXXX">https://t.co/XXXXX</a></p>&mdash; UserName (@account) <a href="https://twitter.com/account/status/XXXXX">August 4, 2022</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
225
226
 
226
227
  A paragraph.
227
228
  [HTML]
228
229
  <p>A paragraph.</p>
229
- <figure class="f-blockquote">
230
- <figcaption><span class="f-blockquote-label">Quote<span class="f-blockquote-label-joint">.</span></span> Twitter Post.</figcaption>
230
+ <figure class="f-img">
231
+ <figcaption><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> Twitter Post.</figcaption>
231
232
  <blockquote class="twitter-tweet"><p lang="ja" dir="ltr">XXXXX <a href="https://t.co/XXXXX">https://t.co/XXXXX</a></p>&mdash; User (@twitter) <a href="https://twitter.com/UserID/status/XXXXX">August 4, 2022</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
232
233
  </figure>
233
234
  <p>A paragraph.</p>
234
235
 
236
+ ~~~
235
237
 
238
+ Note: External embedding supports Youtube and Twitter. Twitter embedding uses blockquote instead of iframe. Therefore, the caption identifier should use "Quote", but "Figure" is also acceptable.
239
+
240
+
241
+ From version 0.5.0, it supports cases where a paragraph contains only multiple images. Instead of `f-img` as the figure class name, use the following class name. (This class name is unstable, but I probably won't change it.)
242
+
243
+ - `f-img-horizontal` if the image is written in one line on Markdown
244
+ - `f-img-vertical` if images are written only vertically, one per line
245
+ - `f-img-multiple` in other cases
246
+
247
+ Notice. This process can be turned off by specifying `{multipleImages: false}`.
248
+
249
+ ```
236
250
  [Markdown]
237
- A paragraph.
251
+ A paragraph. multipleImages: true. horizontal images only.
238
252
 
239
- Figure. Twitter Post.
253
+ ![One cat](cat1.jpg) ![Two cat](cat2.jpg)
240
254
 
241
- <blockquote class="twitter-tweet"><p lang="ja" dir="ltr">XXXXX <a href="https://t.co/XXXXX">https://t.co/XXXXX</a></p>&mdash; UserName (@account) <a href="https://twitter.com/account/status/XXXXX">August 4, 2022</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
255
+ Figure. Cats.
242
256
 
243
257
  A paragraph.
244
258
  [HTML]
259
+ <p>A paragraph. multipleImages: true. horizontal images only</p>
260
+ <figure class="f-img-horizontal">
261
+ <img src="cat1.jpg" alt="One cat"><img src="cat2.jpg" alt="Two cat">
262
+ <figcaption><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> Cats.</figcaption>
263
+ </figure>
245
264
  <p>A paragraph.</p>
246
- <figure class="f-img">
247
- <figcaption><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> Twitter Post.</figcaption>
248
- <blockquote class="twitter-tweet"><p lang="ja" dir="ltr">XXXXX <a href="https://t.co/XXXXX">https://t.co/XXXXX</a></p>&mdash; User (@twitter) <a href="https://twitter.com/UserID/status/XXXXX">August 4, 2022</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
265
+
266
+ [Markdown]
267
+ A paragraph. multipleImages: true. vertical images only.
268
+
269
+ Figure. Cats.
270
+
271
+ ![One cat](cat1.jpg)
272
+ ![Two cat](cat2.jpg)
273
+
274
+ A paragraph.
275
+ [HTML]
276
+ <p>A paragraph. multipleImages: true. vertical images only.</p>
277
+ <figure class="f-img-vertical">
278
+ <figcaption><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> Cats.</figcaption>
279
+ <img src="cat1.jpg" alt="One cat">
280
+ <img src="cat2.jpg" alt="Two cat">
249
281
  </figure>
250
282
  <p>A paragraph.</p>
251
283
 
252
- ~~~
284
+ [Markdown]
285
+ A paragraph. multipleImages: true.
253
286
 
254
- Note: External embedding supports Youtube and Twitter. Twitter embedding uses blockquote instead of iframe. Therefore, the caption identifier should use "Quote", but "Figure" is also acceptable.
287
+ Figure. Cats.
255
288
 
289
+ ![One cat](cat1.jpg) ![Two cat](cat2.jpg)
290
+ ![Three cat](cat3.jpg)
291
+
292
+ A paragraph.
293
+ [HTML]
294
+ <p>A paragraph. multipleImages: true.</p>
295
+ <figure class="f-img-multiple">
296
+ <figcaption><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> Cats.</figcaption>
297
+ <img src="cat1.jpg" alt="One cat"><img src="cat2.jpg" alt="Two cat">
298
+ <img src="cat3.jpg" alt="Three cat">
299
+ </figure>
300
+ <p>A paragraph.</p>
301
+ ```
256
302
 
257
303
  ## Option: Specify file name
258
304
 
@@ -345,13 +391,20 @@ A paragraph.
345
391
 
346
392
  #### Convert one iframe without caption
347
393
 
348
- Convert one iframe without a caption paragraph to figure element.
394
+ Convert one iframe without a caption paragraph to iframe element. (adn twitter blockquote embed eelment.)
349
395
 
350
396
  ```js
351
397
  md.use(mdFigureWithPCaption, {iframeWithoutCaption: true});
352
398
  ```
353
399
 
354
400
  ~~~
401
+ [Markdown]
402
+ <iframe src="https://example.com/embed" class="mastodon-embed" style="max-width: 100%; border: 0" width="400" allowfullscreen="allowfullscreen"></iframe><script src="https://exapmle.com/embed.js" async="async"></script>
403
+ [HTML]
404
+ <figure class="f-iframe">
405
+ <iframe src="https://example.com/embed" class="mastodon-embed" style="max-width: 100%; border: 0" width="400" allowfullscreen="allowfullscreen"></iframe><script src="https://exapmle.com/embed.js" async="async"></script>
406
+ </figure>
407
+
355
408
  [Markdown]
356
409
  A paragraph.
357
410
 
@@ -364,4 +417,38 @@ A paragraph.
364
417
  <iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/XXXXXXXXXXX" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
365
418
  </figure>
366
419
  <p>A paragraph.</p>
420
+
421
+ [Markdown]
422
+ <iframe src="https://player.vimeo.com/video/xxxxxxxxxxxxxxx" width="640" height="360" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>
423
+ [HTML]
424
+ <figure class="f-video">
425
+ <iframe src="https://player.vimeo.com/video/xxxxxxxxxxxxxxx" width="640" height="360" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>
426
+ </figure>
427
+
428
+ [Markdown]
429
+ A paragraph. iframeWithoutCaption: true.
430
+
431
+ <blockquote class="twitter-tweet"><p lang="ja" dir="ltr">XXXXX <a href="https://t.co/XXXXX">https://t.co/XXXXX</a></p>&mdash; User (@twitter) <a href="https://twitter.com/UserID/status/XXXXX">August 4, 2022</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
432
+
433
+ A paragraph.
434
+ [HTML]
435
+ <p>A paragraph. iframeWithoutCaption: true.</p>
436
+ <figure class="f-iframe">
437
+ <blockquote class="twitter-tweet"><p lang="ja" dir="ltr">XXXXX <a href="https://t.co/XXXXX">https://t.co/XXXXX</a></p>&mdash; User (@twitter) <a href="https://twitter.com/UserID/status/XXXXX">August 4, 2022</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
438
+ </figure>
439
+ <p>A paragraph.</p>
440
+
441
+ [Markdown]
442
+ <iframe src="https://example.com/embed" class="mastodon-embed" style="max-width: 100%; border: 0" width="400" allowfullscreen="allowfullscreen"></iframe><script src="https://exapmle.com/embed.js" async="async"></script>
443
+ [HTML]
444
+ <figure class="f-iframe">
445
+ <iframe src="https://example.com/embed" class="mastodon-embed" style="max-width: 100%; border: 0" width="400" allowfullscreen="allowfullscreen"></iframe><script src="https://exapmle.com/embed.js" async="async"></script>
446
+ </figure>
447
+
448
+ [Markdown]
449
+ <iframe class="speakerdeck-iframe" style="border: 0px none; background: rgba(0, 0, 0, 0.1) padding-box; margin: 0px; padding: 0px; border-radius: 6px; box-shadow: rgba(0, 0, 0, 0.2) 0px 5px 40px; width: 100%; height: auto; aspect-ratio: 560 / 314;" src="https://speakerdeck.com/player/xxxxxxxxxxxxxx" title="xxxxxxxxxxx" allowfullscreen="true" data-ratio="1.78343949044586" frameborder="0"></iframe>
450
+ [HTML]
451
+ <figure class="f-iframe">
452
+ <iframe class="speakerdeck-iframe" style="border: 0px none; background: rgba(0, 0, 0, 0.1) padding-box; margin: 0px; padding: 0px; border-radius: 6px; box-shadow: rgba(0, 0, 0, 0.2) 0px 5px 40px; width: 100%; height: auto; aspect-ratio: 560 / 314;" src="https://speakerdeck.com/player/xxxxxxxxxxxxxx" title="xxxxxxxxxxx" allowfullscreen="true" data-ratio="1.78343949044586" frameborder="0"></iframe>
453
+ </figure>
367
454
  ~~~
package/index.js CHANGED
@@ -16,6 +16,8 @@ module.exports = function figure_with_caption_plugin(md, option) {
16
16
  oneImageWithoutCaption: false,
17
17
  iframeWithoutCaption: false,
18
18
  removeUnnumberedLabel: false,
19
+ multipleImages: true,
20
+ styleProcess: true,
19
21
  };
20
22
  if (option !== undefined) {
21
23
  for (let o in option) {
@@ -127,8 +129,12 @@ module.exports = function figure_with_caption_plugin(md, option) {
127
129
  const figureStartToken = new state.Token('figure_open', 'figure', 1);
128
130
  figureStartToken.attrSet('class', 'f-' + tagName);
129
131
  if (sp) {
130
- if (sp.isTwitterBlock && sp.hasImgCaption) {
131
- figureStartToken.attrSet('class', 'f-img');
132
+ if (sp.isTwitterBlock) {
133
+ if (sp.hasImgCaption) {
134
+ figureStartToken.attrSet('class', 'f-img');
135
+ } else {
136
+ figureStartToken.attrSet('class', 'f-iframe');
137
+ }
132
138
  }
133
139
  }
134
140
  if(/pre-(?:code|samp)/.test(tagName)) {
@@ -137,6 +143,13 @@ module.exports = function figure_with_caption_plugin(md, option) {
137
143
  const figureEndToken = new state.Token('figure_close', 'figure', -1);
138
144
  const breakToken = new state.Token('text', '', 0);
139
145
  breakToken.content = '\n';
146
+ if (sp) {
147
+ if (sp.attrs) {
148
+ for (let attr of sp.attrs) {
149
+ figureStartToken.attrJoin(attr[0], attr[1]);
150
+ }
151
+ }
152
+ }
140
153
  ///Add for vsce
141
154
  if(state.tokens[n].attrs) {
142
155
  for (let attr of state.tokens[n].attrs) {
@@ -182,9 +195,11 @@ module.exports = function figure_with_caption_plugin(md, option) {
182
195
  let tagName = '';
183
196
  let caption = {
184
197
  name: '',
198
+ nameSuffix: '',
185
199
  hasPrev: false,
186
200
  hasNext: false,
187
201
  };
202
+ let sp = {attrs: []};
188
203
 
189
204
  const checkTags = ['table', 'pre', 'blockquote'];
190
205
  let cti = 0;
@@ -235,7 +250,6 @@ module.exports = function figure_with_caption_plugin(md, option) {
235
250
  if (token.type === 'html_block') {
236
251
  const tags = ['video', 'audio', 'iframe', 'blockquote'];
237
252
  let ctj = 0;
238
- let sp = {};
239
253
  while (ctj < tags.length) {
240
254
  const hasTag = token.content.match(new RegExp('^<'+ tags[ctj] + ' ?[^>]*?>[\\s\\S]*?<\\/' + tags[ctj] + '> *?(?:<script [^>]*?>(?:</script>)?)?(\\n|$)'));
241
255
  if (!hasTag) {
@@ -247,11 +261,9 @@ module.exports = function figure_with_caption_plugin(md, option) {
247
261
  }
248
262
  tagName = tags[ctj];
249
263
  if (tagName === 'iframe') {
250
- if(/^<[^>]*? title="YouTube video player"/i.test(token.content)) {
264
+ if(/^<[^>]*? src="https:\/\/(?:www.youtube-nocookie.com|player.vimeo.com)\//i.test(token.content)) {
251
265
  tagName = 'video'; // figure.f-video used.
252
266
  }
253
- // Non Youtube iframe currently use figure.f-iframe.
254
- // Class in caption uses actual caption identifier.
255
267
  }
256
268
  if (tagName === 'blockquote') {
257
269
  if(/^<[^>]*? class="twitter-tweet"/.test(token.content)) {
@@ -259,9 +271,16 @@ module.exports = function figure_with_caption_plugin(md, option) {
259
271
  if (n > 2) {
260
272
  if (state.tokens[n-2].children.length > 1) {
261
273
  if (state.tokens[n-2].children[1].attrs.length > 0) {
262
- if (state.tokens[n-2].children[1].attrs[0][0] === 'class' &&
263
- state.tokens[n-2].children[1].attrs[0][1] === 'f-img-label') {
264
- sp.hasImgCaption = true;
274
+ if (state.tokens[n-2].children[1].attrs[0][0] === 'class') {
275
+ if (state.tokens[n-2].children[1].attrs[0][1] === 'f-img-label') {
276
+ sp.hasImgCaption = true;
277
+ /* under consideration. I think I should use figure instead of blockquoe for caption.
278
+ } else {
279
+ if (state.tokens[n-2].children[1].attrs[0][1] === 'f-blockquote-label') {
280
+ state.tokens[n-2].children[1].attrs[0][1] = 'f-iframe-label'
281
+ state.tokens[n-2].children[3].attrs[0][1] = 'f-iframe-label-joint'
282
+ } */
283
+ }
265
284
  }
266
285
  }
267
286
  }
@@ -292,13 +311,77 @@ module.exports = function figure_with_caption_plugin(md, option) {
292
311
  }
293
312
 
294
313
 
295
- if (token.type === 'paragraph_open' && nextToken.type === 'inline' && nextToken.children[0].type === 'image' && state.tokens[n+2].type === 'paragraph_close' && nextToken.children.length < 3) {
296
- if (nextToken.children.length === 2) {
297
- if (!nextToken.children[nextToken.children.length - 1].type === 'text' || !/^ *?\{.*?\}$/.test(nextToken.children[nextToken.children.length - 1].content)) {
298
- n++; continue;
314
+ if (token.type === 'paragraph_open' && nextToken.type === 'inline' && nextToken.children[0].type === 'image') {
315
+ let ntChildTokenIndex = 1
316
+ let imageNum = 1
317
+ let isMultipleImagesHorizontal = true
318
+ let isMultipleImagesVertical = true
319
+ checkToken = true
320
+ while (ntChildTokenIndex < nextToken.children.length) {
321
+ const ntChildToken = nextToken.children[ntChildTokenIndex]
322
+ if (ntChildTokenIndex === nextToken.children.length - 1) {
323
+ let imageAttrs = ntChildToken.content.match(/^ *\{(.*?)\} *$/)
324
+ if(ntChildToken.type === 'text' && imageAttrs) {
325
+ imageAttrs = imageAttrs[1].split(/ +/)
326
+ let iai = 0
327
+ while (iai < imageAttrs.length) {
328
+ if (/^\./.test(imageAttrs[iai])) {
329
+ imageAttrs[iai] = imageAttrs[iai].replace(/^\./, "class=")
330
+ }
331
+ if (/^#/.test(imageAttrs[iai])) {
332
+ imageAttrs[iai] = imageAttrs[iai].replace(/^\#/, "id=")
333
+ }
334
+ let imageAttr = imageAttrs[iai].match(/^(.*?)="?(.*)"?$/)
335
+ if (!imageAttr || !imageAttr[1]) {
336
+ iai++
337
+ continue
338
+ }
339
+ sp.attrs.push([imageAttr[1], imageAttr[2]])
340
+ iai++
341
+ }
342
+ break
343
+ }
344
+ }
345
+
346
+ if (!opt.multipleImages) {
347
+ checkToken = false
348
+ break
349
+ }
350
+ if (ntChildToken.type === 'image') {
351
+ imageNum += 1
352
+ } else if (ntChildToken.type === 'text' && /^ *$/.test(ntChildToken.content)) {
353
+ isMultipleImagesVertical = false
354
+ if (isMultipleImagesVertical) {
355
+ isMultipleImagesHorizontal = false
356
+ }
357
+ } else if (ntChildToken.type === 'softbreak') {
358
+ isMultipleImagesHorizontal = false
359
+ if (isMultipleImagesHorizontal) {
360
+ isMultipleImagesVertical = false
361
+ }
362
+ } else {
363
+ checkToken = false
364
+ break
365
+ }
366
+ ntChildTokenIndex++
367
+ }
368
+ if (checkToken && imageNum > 1 && opt.multipleImages) {
369
+ if (isMultipleImagesHorizontal) {
370
+ caption.nameSuffix = '-horizontal'
371
+ } else if (isMultipleImagesVertical) {
372
+ caption.nameSuffix = '-vertical'
373
+ } else {
374
+ caption.nameSuffix = '-multiple'
375
+ }
376
+ ntChildTokenIndex = 0
377
+ while (ntChildTokenIndex < nextToken.children.length) {
378
+ const ccToken = nextToken.children[ntChildTokenIndex]
379
+ if (ccToken.type === 'text' && /^ *$/.test(ccToken.content)) {
380
+ ccToken.content = ''
381
+ }
382
+ ntChildTokenIndex++
299
383
  }
300
384
  }
301
- checkToken = true;
302
385
  en = n + 2;
303
386
  range.end = en;
304
387
  tagName = 'img';
@@ -308,7 +391,12 @@ module.exports = function figure_with_caption_plugin(md, option) {
308
391
  if (state.tokens[n-1].type === 'list_item_open') {checkToken = false;}
309
392
  }
310
393
  if (checkToken && (opt.oneImageWithoutCaption || caption.hasPrev || caption.hasNext)) {
311
- range = wrapWithFigure(state, range, tagName, true);
394
+ if (caption.nameSuffix) tagName += caption.nameSuffix
395
+ if (caption.hasNext && opt.styleProcess) {
396
+ range = wrapWithFigure(state, range, tagName, true, sp);
397
+ } else {
398
+ range = wrapWithFigure(state, range, tagName, true);
399
+ }
312
400
  }
313
401
  }
314
402
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peaceroad/markdown-it-figure-with-p-caption",
3
- "version": "0.4.5",
3
+ "version": "0.5.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
  "scripts": {
@@ -17,6 +17,6 @@
17
17
  "markdown-it-attrs": "^4.1.4"
18
18
  },
19
19
  "dependencies": {
20
- "p7d-markdown-it-p-captions": "^0.9.0"
20
+ "p7d-markdown-it-p-captions": "^0.9.1"
21
21
  }
22
22
  }
package/test/examples.txt CHANGED
@@ -456,15 +456,15 @@ A paragraph.
456
456
  [Markdown]
457
457
  A paragraph.
458
458
 
459
- Quote. Twitter Post.
459
+ Source. Twitter Post.
460
460
 
461
461
  <blockquote class="twitter-tweet"><p lang="ja" dir="ltr">XXXXX <a href="https://t.co/XXXXX">https://t.co/XXXXX</a></p>&mdash; User (@twitter) <a href="https://twitter.com/UserID/status/XXXXX">August 4, 2022</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
462
462
 
463
463
  A paragraph.
464
464
  [HTML]
465
465
  <p>A paragraph.</p>
466
- <figure class="f-blockquote">
467
- <figcaption><span class="f-blockquote-label">Quote<span class="f-blockquote-label-joint">.</span></span> Twitter Post.</figcaption>
466
+ <figure class="f-iframe">
467
+ <figcaption><span class="f-blockquote-label">Source<span class="f-blockquote-label-joint">.</span></span> Twitter Post.</figcaption>
468
468
  <blockquote class="twitter-tweet"><p lang="ja" dir="ltr">XXXXX <a href="https://t.co/XXXXX">https://t.co/XXXXX</a></p>&mdash; User (@twitter) <a href="https://twitter.com/UserID/status/XXXXX">August 4, 2022</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
469
469
  </figure>
470
470
  <p>A paragraph.</p>
@@ -511,7 +511,7 @@ Quote. Twitter Post.
511
511
  A paragraph.
512
512
  [HTML]
513
513
  <p>A paragraph.</p>
514
- <figure class="f-blockquote">
514
+ <figure class="f-iframe">
515
515
  <blockquote class="twitter-tweet"><p lang="ja" dir="ltr">XXXXX <a href="https://t.co/XXXXX">https://t.co/XXXXX</a></p>&mdash; User (@twitter) <a href="https://twitter.com/UserID/status/XXXXX">August 4, 2022</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
516
516
  <figcaption><span class="f-blockquote-label">Quote<span class="f-blockquote-label-joint">.</span></span> Twitter Post.</figcaption>
517
517
  </figure>
@@ -519,13 +519,13 @@ A paragraph.
519
519
 
520
520
 
521
521
  [Markdown]
522
- A paragraph.
522
+ A paragraph. 28.
523
523
 
524
524
  <blockquote class="twitter-tweet"><p lang="ja" dir="ltr">XXXXX <a href="https://t.co/XXXXX">https://t.co/XXXXX</a></p>&mdash; User (@twitter) <a href="https://twitter.com/UserID/status/XXXXX">August 4, 2022</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
525
525
 
526
526
  A paragraph.
527
527
  [HTML]
528
- <p>A paragraph.</p>
528
+ <p>A paragraph. 28.</p>
529
529
  <blockquote class="twitter-tweet"><p lang="ja" dir="ltr">XXXXX <a href="https://t.co/XXXXX">https://t.co/XXXXX</a></p>&mdash; User (@twitter) <a href="https://twitter.com/UserID/status/XXXXX">August 4, 2022</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
530
530
  <p>A paragraph.</p>
531
531
 
@@ -676,6 +676,17 @@ Figure. A Caption.
676
676
  <img src="cat.jpg" alt="Figure">
677
677
  </figure>
678
678
 
679
+
680
+ [Markdown]
681
+ ![Figure](cat.jpg) {.style}
682
+
683
+ Figure. A Caption.
684
+ [HTML]
685
+ <figure class="f-img style">
686
+ <img src="cat.jpg" alt="Figure">
687
+ <figcaption><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> A Caption.</figcaption>
688
+ </figure>
689
+
679
690
  [Markdown]
680
691
  Figure. A Caption.
681
692
 
@@ -712,3 +723,178 @@ A paragraph.
712
723
  <figure class="f-iframe">
713
724
  <iframe src="https://example.com/embed" class="mastodon-embed" style="max-width: 100%; border: 0" width="400" allowfullscreen="allowfullscreen"></iframe><script src="https://exapmle.com/embed.js" async="async"></script>
714
725
  </figure>
726
+
727
+ [Markdown]
728
+ <iframe class="speakerdeck-iframe" style="border: 0px none; background: rgba(0, 0, 0, 0.1) padding-box; margin: 0px; padding: 0px; border-radius: 6px; box-shadow: rgba(0, 0, 0, 0.2) 0px 5px 40px; width: 100%; height: auto; aspect-ratio: 560 / 314;" src="https://speakerdeck.com/player/xxxxxxxxxxxxxx" title="xxxxxxxxxxx" allowfullscreen="true" data-ratio="1.78343949044586" frameborder="0"></iframe>
729
+ [HTML]
730
+ <figure class="f-iframe">
731
+ <iframe class="speakerdeck-iframe" style="border: 0px none; background: rgba(0, 0, 0, 0.1) padding-box; margin: 0px; padding: 0px; border-radius: 6px; box-shadow: rgba(0, 0, 0, 0.2) 0px 5px 40px; width: 100%; height: auto; aspect-ratio: 560 / 314;" src="https://speakerdeck.com/player/xxxxxxxxxxxxxx" title="xxxxxxxxxxx" allowfullscreen="true" data-ratio="1.78343949044586" frameborder="0"></iframe>
732
+ </figure>
733
+
734
+ [Markdown]
735
+ <iframe src="https://player.vimeo.com/video/xxxxxxxxxxxxxxx" width="640" height="360" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>
736
+ <p><a href="https://vimeo.com/xxxx">Title</a> from <a href="https://vimeo.com/yyy">User</a> on <a href="https://vimeo.com">Vimeo</a>.</p>
737
+ [HTML]
738
+ <figure class="f-video">
739
+ <iframe src="https://player.vimeo.com/video/xxxxxxxxxxxxxxx" width="640" height="360" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>
740
+ <p><a href="https://vimeo.com/xxxx">Title</a> from <a href="https://vimeo.com/yyy">User</a> on <a href="https://vimeo.com">Vimeo</a>.</p></figure>
741
+
742
+ [Markdown]
743
+ <iframe src="https://player.vimeo.com/video/xxxxxxxxxxxxxxx" width="640" height="360" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>
744
+ [HTML]
745
+ <figure class="f-video">
746
+ <iframe src="https://player.vimeo.com/video/xxxxxxxxxxxxxxx" width="640" height="360" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>
747
+ </figure>
748
+
749
+ [Markdown]
750
+ A paragraph. iframeWithoutCaption: true.
751
+
752
+ <blockquote class="twitter-tweet"><p lang="ja" dir="ltr">XXXXX <a href="https://t.co/XXXXX">https://t.co/XXXXX</a></p>&mdash; User (@twitter) <a href="https://twitter.com/UserID/status/XXXXX">August 4, 2022</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
753
+
754
+ A paragraph.
755
+ [HTML]
756
+ <p>A paragraph. iframeWithoutCaption: true.</p>
757
+ <figure class="f-iframe">
758
+ <blockquote class="twitter-tweet"><p lang="ja" dir="ltr">XXXXX <a href="https://t.co/XXXXX">https://t.co/XXXXX</a></p>&mdash; User (@twitter) <a href="https://twitter.com/UserID/status/XXXXX">August 4, 2022</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
759
+ </figure>
760
+ <p>A paragraph.</p>
761
+
762
+ [Markdown]
763
+ A paragraph. multipleImages: true.
764
+
765
+ Figure. Cats.
766
+
767
+ ![One cat](cat1.jpg) ![Two cat](cat2.jpg)
768
+
769
+ A paragraph.
770
+ [HTML]
771
+ <p>A paragraph. multipleImages: true.</p>
772
+ <figure class="f-img-horizontal">
773
+ <figcaption><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> Cats.</figcaption>
774
+ <img src="cat1.jpg" alt="One cat"><img src="cat2.jpg" alt="Two cat">
775
+ </figure>
776
+ <p>A paragraph.</p>
777
+
778
+
779
+ [Markdown]
780
+ A paragraph. multipleImages: true.
781
+
782
+ ![One cat](cat1.jpg) ![Two cat](cat2.jpg)
783
+
784
+ Figure. Cats.
785
+
786
+ A paragraph.
787
+ [HTML]
788
+ <p>A paragraph. multipleImages: true.</p>
789
+ <figure class="f-img-horizontal">
790
+ <img src="cat1.jpg" alt="One cat"><img src="cat2.jpg" alt="Two cat">
791
+ <figcaption><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> Cats.</figcaption>
792
+ </figure>
793
+ <p>A paragraph.</p>
794
+
795
+
796
+ [Markdown]
797
+ A paragraph. multipleImages: true.
798
+
799
+ Figure. Cats.
800
+
801
+ ![One cat](cat1.jpg)![Two cat](cat2.jpg)![Three cat](cat3.jpg) {.style}
802
+
803
+ A paragraph.
804
+ [HTML]
805
+ <p>A paragraph. multipleImages: true.</p>
806
+ <figure class="f-img-horizontal style">
807
+ <figcaption><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> Cats.</figcaption>
808
+ <img src="cat1.jpg" alt="One cat"><img src="cat2.jpg" alt="Two cat"><img src="cat3.jpg" alt="Three cat">
809
+ </figure>
810
+ <p>A paragraph.</p>
811
+
812
+ [Markdown]
813
+ A paragraph. multipleImages: true.
814
+
815
+ Figure. Cats.
816
+
817
+ ![One cat](cat1.jpg)
818
+ ![Two cat](cat2.jpg)
819
+
820
+ A paragraph.
821
+ [HTML]
822
+ <p>A paragraph. multipleImages: true.</p>
823
+ <figure class="f-img-vertical">
824
+ <figcaption><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> Cats.</figcaption>
825
+ <img src="cat1.jpg" alt="One cat">
826
+ <img src="cat2.jpg" alt="Two cat">
827
+ </figure>
828
+ <p>A paragraph.</p>
829
+
830
+ [Markdown]
831
+ A paragraph. multipleImages: true.
832
+
833
+ Figure. Cats.
834
+
835
+ ![One cat](cat1.jpg) ![Two cat](cat2.jpg)
836
+ ![Three cat](cat3.jpg)
837
+
838
+ A paragraph.
839
+ [HTML]
840
+ <p>A paragraph. multipleImages: true.</p>
841
+ <figure class="f-img-multiple">
842
+ <figcaption><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> Cats.</figcaption>
843
+ <img src="cat1.jpg" alt="One cat"><img src="cat2.jpg" alt="Two cat">
844
+ <img src="cat3.jpg" alt="Three cat">
845
+ </figure>
846
+ <p>A paragraph.</p>
847
+
848
+ [Markdown]
849
+ A paragraph. multipleImages: true.
850
+
851
+ Figure. Cats.
852
+
853
+ ![One cat](cat1.jpg) ![Two cat](cat2.jpg)
854
+ ![Three cat](cat3.jpg) {.style}
855
+
856
+ A paragraph.
857
+ [HTML]
858
+ <p>A paragraph. multipleImages: true.</p>
859
+ <figure class="f-img-multiple style">
860
+ <figcaption><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> Cats.</figcaption>
861
+ <img src="cat1.jpg" alt="One cat"><img src="cat2.jpg" alt="Two cat">
862
+ <img src="cat3.jpg" alt="Three cat">
863
+ </figure>
864
+ <p>A paragraph.</p>
865
+
866
+
867
+ [Markdown]
868
+ A paragraph. multipleImages: true.
869
+
870
+ ![One cat](cat1.jpg) ![Two cat](cat2.jpg)
871
+ ![Three cat](cat3.jpg)![Four cat](cat4.jpg) {.style #id}
872
+
873
+ Figure. Cats.
874
+
875
+ A paragraph.
876
+ [HTML]
877
+ <p>A paragraph. multipleImages: true.</p>
878
+ <figure class="f-img-multiple style" id="id">
879
+ <img src="cat1.jpg" alt="One cat"><img src="cat2.jpg" alt="Two cat">
880
+ <img src="cat3.jpg" alt="Three cat"><img src="cat4.jpg" alt="Four cat">
881
+ <figcaption><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> Cats.</figcaption>
882
+ </figure>
883
+ <p>A paragraph.</p>
884
+
885
+
886
+
887
+ [Markdown]
888
+ A paragraph. multipleImages: true.
889
+
890
+ ![One cat](cat1.jpg) ![Two cat](cat2.jpg)
891
+ ![Three cat](cat3.jpg)![Four cat](cat4.jpg) {.style #id}
892
+
893
+ A paragraph.
894
+ [HTML]
895
+ <p>A paragraph. multipleImages: true.</p>
896
+ <figure class="f-img-multiple style" id="id">
897
+ <img src="cat1.jpg" alt="One cat"><img src="cat2.jpg" alt="Two cat">
898
+ <img src="cat3.jpg" alt="Three cat"><img src="cat4.jpg" alt="Four cat">
899
+ </figure>
900
+ <p>A paragraph.</p>
package/test/test.js CHANGED
@@ -3,6 +3,7 @@ const fs = require('fs');
3
3
  const md = require('markdown-it')({ html: true });
4
4
  const mdOneImage = require('markdown-it')({ html: true });
5
5
  const mdWithoutCaption = require('markdown-it')({ html: true });
6
+ const mdMultipleImages = require('markdown-it')({ html: true });
6
7
 
7
8
  const mdFigureWithPCaption = require('../index.js');
8
9
 
@@ -30,6 +31,15 @@ mdWithoutCaption.use(mdFigureWithPCaption, {
30
31
  hasNumClass: true,
31
32
  }).use(attrs);
32
33
 
34
+ mdMultipleImages.use(attrs).use(mdFigureWithPCaption, {
35
+ dquoteFilename: true,
36
+ strongFilename: true,
37
+ oneImageWithoutCaption: true,
38
+ iframeWithoutCaption: true,
39
+ hasNumClass: true,
40
+ multipleImages: true,
41
+ })
42
+
33
43
  const example = __dirname + '/examples.txt';
34
44
  const mdPath = __dirname + '/examples.md';
35
45
  const exampleCont = fs.readFileSync(example, 'utf-8').trim();
@@ -56,13 +66,15 @@ while(n < ms0.length) {
56
66
 
57
67
  n = 1;
58
68
  while(n < ms.length) {
59
- //if (n !== 22) { n++; continue };
69
+ //if (n !== 37) { n++; continue };
60
70
  console.log('Test: ' + n + ' >>>');
61
71
  //console.log(ms[n].markdown);
62
72
 
63
73
  const m = ms[n].markdown;
64
74
  let h = ''
65
- if (n > 37) {
75
+ if (n > 44) {
76
+ h = mdMultipleImages.render(m);
77
+ } else if (n > 37) {
66
78
  h = mdWithoutCaption.render(m);
67
79
  } else if (n > 20) {
68
80
  h = mdOneImage.render(m);