@peaceroad/markdown-it-figure-with-p-caption 0.4.5 → 0.4.6
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 +44 -20
- package/index.js +17 -8
- package/package.json +2 -2
- package/test/examples.txt +42 -6
package/README.md
CHANGED
|
@@ -121,7 +121,7 @@ A paragraph.
|
|
|
121
121
|
[Markdown]
|
|
122
122
|
A paragraph.
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
Source. A Caption.
|
|
125
125
|
|
|
126
126
|
> A quoted paragraph.
|
|
127
127
|
|
|
@@ -130,7 +130,7 @@ A paragraph.
|
|
|
130
130
|
[HTML]
|
|
131
131
|
<p>A paragraph.</p>
|
|
132
132
|
<figure class="f-blockquote">
|
|
133
|
-
<figcaption><span class="f-blockquote-label">
|
|
133
|
+
<figcaption><span class="f-blockquote-label">Source<span class="f-blockquote-label-joint">.</span></span> A Caption.</figcaption>
|
|
134
134
|
<blockquote>
|
|
135
135
|
<p>A quoted paragraph.</p>
|
|
136
136
|
</blockquote>
|
|
@@ -216,23 +216,6 @@ A paragraph.
|
|
|
216
216
|
<p>A paragraph.</p>
|
|
217
217
|
|
|
218
218
|
|
|
219
|
-
[Markdown]
|
|
220
|
-
A paragraph.
|
|
221
|
-
|
|
222
|
-
Quote. Twitter Post.
|
|
223
|
-
|
|
224
|
-
<blockquote class="twitter-tweet"><p lang="ja" dir="ltr">XXXXX <a href="https://t.co/XXXXX">https://t.co/XXXXX</a></p>— 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
|
-
|
|
226
|
-
A paragraph.
|
|
227
|
-
[HTML]
|
|
228
|
-
<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>
|
|
231
|
-
<blockquote class="twitter-tweet"><p lang="ja" dir="ltr">XXXXX <a href="https://t.co/XXXXX">https://t.co/XXXXX</a></p>— 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
|
-
</figure>
|
|
233
|
-
<p>A paragraph.</p>
|
|
234
|
-
|
|
235
|
-
|
|
236
219
|
[Markdown]
|
|
237
220
|
A paragraph.
|
|
238
221
|
|
|
@@ -345,13 +328,20 @@ A paragraph.
|
|
|
345
328
|
|
|
346
329
|
#### Convert one iframe without caption
|
|
347
330
|
|
|
348
|
-
Convert one iframe without a caption paragraph to
|
|
331
|
+
Convert one iframe without a caption paragraph to iframe element. (adn twitter blockquote embed eelment.)
|
|
349
332
|
|
|
350
333
|
```js
|
|
351
334
|
md.use(mdFigureWithPCaption, {iframeWithoutCaption: true});
|
|
352
335
|
```
|
|
353
336
|
|
|
354
337
|
~~~
|
|
338
|
+
[Markdown]
|
|
339
|
+
<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>
|
|
340
|
+
[HTML]
|
|
341
|
+
<figure class="f-iframe">
|
|
342
|
+
<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>
|
|
343
|
+
</figure>
|
|
344
|
+
|
|
355
345
|
[Markdown]
|
|
356
346
|
A paragraph.
|
|
357
347
|
|
|
@@ -364,4 +354,38 @@ A paragraph.
|
|
|
364
354
|
<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
355
|
</figure>
|
|
366
356
|
<p>A paragraph.</p>
|
|
357
|
+
|
|
358
|
+
[Markdown]
|
|
359
|
+
<iframe src="https://player.vimeo.com/video/xxxxxxxxxxxxxxx" width="640" height="360" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>
|
|
360
|
+
[HTML]
|
|
361
|
+
<figure class="f-video">
|
|
362
|
+
<iframe src="https://player.vimeo.com/video/xxxxxxxxxxxxxxx" width="640" height="360" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>
|
|
363
|
+
</figure>
|
|
364
|
+
|
|
365
|
+
[Markdown]
|
|
366
|
+
A paragraph. iframeWithoutCaption: true.
|
|
367
|
+
|
|
368
|
+
<blockquote class="twitter-tweet"><p lang="ja" dir="ltr">XXXXX <a href="https://t.co/XXXXX">https://t.co/XXXXX</a></p>— 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>
|
|
369
|
+
|
|
370
|
+
A paragraph.
|
|
371
|
+
[HTML]
|
|
372
|
+
<p>A paragraph. iframeWithoutCaption: true.</p>
|
|
373
|
+
<figure class="f-iframe">
|
|
374
|
+
<blockquote class="twitter-tweet"><p lang="ja" dir="ltr">XXXXX <a href="https://t.co/XXXXX">https://t.co/XXXXX</a></p>— 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>
|
|
375
|
+
</figure>
|
|
376
|
+
<p>A paragraph.</p>
|
|
377
|
+
|
|
378
|
+
[Markdown]
|
|
379
|
+
<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>
|
|
380
|
+
[HTML]
|
|
381
|
+
<figure class="f-iframe">
|
|
382
|
+
<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>
|
|
383
|
+
</figure>
|
|
384
|
+
|
|
385
|
+
[Markdown]
|
|
386
|
+
<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>
|
|
387
|
+
[HTML]
|
|
388
|
+
<figure class="f-iframe">
|
|
389
|
+
<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>
|
|
390
|
+
</figure>
|
|
367
391
|
~~~
|
package/index.js
CHANGED
|
@@ -127,8 +127,12 @@ module.exports = function figure_with_caption_plugin(md, option) {
|
|
|
127
127
|
const figureStartToken = new state.Token('figure_open', 'figure', 1);
|
|
128
128
|
figureStartToken.attrSet('class', 'f-' + tagName);
|
|
129
129
|
if (sp) {
|
|
130
|
-
if (sp.isTwitterBlock
|
|
131
|
-
|
|
130
|
+
if (sp.isTwitterBlock) {
|
|
131
|
+
if (sp.hasImgCaption) {
|
|
132
|
+
figureStartToken.attrSet('class', 'f-img');
|
|
133
|
+
} else {
|
|
134
|
+
figureStartToken.attrSet('class', 'f-iframe');
|
|
135
|
+
}
|
|
132
136
|
}
|
|
133
137
|
}
|
|
134
138
|
if(/pre-(?:code|samp)/.test(tagName)) {
|
|
@@ -247,11 +251,9 @@ module.exports = function figure_with_caption_plugin(md, option) {
|
|
|
247
251
|
}
|
|
248
252
|
tagName = tags[ctj];
|
|
249
253
|
if (tagName === 'iframe') {
|
|
250
|
-
if(/^<[^>]*?
|
|
254
|
+
if(/^<[^>]*? src="https:\/\/(?:www.youtube-nocookie.com|player.vimeo.com)\//i.test(token.content)) {
|
|
251
255
|
tagName = 'video'; // figure.f-video used.
|
|
252
256
|
}
|
|
253
|
-
// Non Youtube iframe currently use figure.f-iframe.
|
|
254
|
-
// Class in caption uses actual caption identifier.
|
|
255
257
|
}
|
|
256
258
|
if (tagName === 'blockquote') {
|
|
257
259
|
if(/^<[^>]*? class="twitter-tweet"/.test(token.content)) {
|
|
@@ -259,9 +261,16 @@ module.exports = function figure_with_caption_plugin(md, option) {
|
|
|
259
261
|
if (n > 2) {
|
|
260
262
|
if (state.tokens[n-2].children.length > 1) {
|
|
261
263
|
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
|
-
|
|
264
|
+
if (state.tokens[n-2].children[1].attrs[0][0] === 'class') {
|
|
265
|
+
if (state.tokens[n-2].children[1].attrs[0][1] === 'f-img-label') {
|
|
266
|
+
sp.hasImgCaption = true;
|
|
267
|
+
/* under consideration. I think I should use figure instead of blockquoe for caption.
|
|
268
|
+
} else {
|
|
269
|
+
if (state.tokens[n-2].children[1].attrs[0][1] === 'f-blockquote-label') {
|
|
270
|
+
state.tokens[n-2].children[1].attrs[0][1] = 'f-iframe-label'
|
|
271
|
+
state.tokens[n-2].children[3].attrs[0][1] = 'f-iframe-label-joint'
|
|
272
|
+
} */
|
|
273
|
+
}
|
|
265
274
|
}
|
|
266
275
|
}
|
|
267
276
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peaceroad/markdown-it-figure-with-p-caption",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.6",
|
|
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.
|
|
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
|
-
|
|
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>— 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-
|
|
467
|
-
<figcaption><span class="f-blockquote-label">
|
|
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>— 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-
|
|
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>— 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>— 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>— 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
|
|
|
@@ -712,3 +712,39 @@ A paragraph.
|
|
|
712
712
|
<figure class="f-iframe">
|
|
713
713
|
<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
714
|
</figure>
|
|
715
|
+
|
|
716
|
+
[Markdown]
|
|
717
|
+
<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>
|
|
718
|
+
[HTML]
|
|
719
|
+
<figure class="f-iframe">
|
|
720
|
+
<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>
|
|
721
|
+
</figure>
|
|
722
|
+
|
|
723
|
+
[Markdown]
|
|
724
|
+
<iframe src="https://player.vimeo.com/video/xxxxxxxxxxxxxxx" width="640" height="360" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>
|
|
725
|
+
<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>
|
|
726
|
+
[HTML]
|
|
727
|
+
<figure class="f-video">
|
|
728
|
+
<iframe src="https://player.vimeo.com/video/xxxxxxxxxxxxxxx" width="640" height="360" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>
|
|
729
|
+
<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>
|
|
730
|
+
|
|
731
|
+
[Markdown]
|
|
732
|
+
<iframe src="https://player.vimeo.com/video/xxxxxxxxxxxxxxx" width="640" height="360" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>
|
|
733
|
+
[HTML]
|
|
734
|
+
<figure class="f-video">
|
|
735
|
+
<iframe src="https://player.vimeo.com/video/xxxxxxxxxxxxxxx" width="640" height="360" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>
|
|
736
|
+
</figure>
|
|
737
|
+
|
|
738
|
+
[Markdown]
|
|
739
|
+
A paragraph. iframeWithoutCaption: true.
|
|
740
|
+
|
|
741
|
+
<blockquote class="twitter-tweet"><p lang="ja" dir="ltr">XXXXX <a href="https://t.co/XXXXX">https://t.co/XXXXX</a></p>— 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>
|
|
742
|
+
|
|
743
|
+
A paragraph.
|
|
744
|
+
[HTML]
|
|
745
|
+
<p>A paragraph. iframeWithoutCaption: true.</p>
|
|
746
|
+
<figure class="f-iframe">
|
|
747
|
+
<blockquote class="twitter-tweet"><p lang="ja" dir="ltr">XXXXX <a href="https://t.co/XXXXX">https://t.co/XXXXX</a></p>— 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>
|
|
748
|
+
</figure>
|
|
749
|
+
<p>A paragraph.</p>
|
|
750
|
+
|