@peaceroad/markdown-it-figure-with-p-caption 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -0
- package/index.js +48 -6
- package/package.json +2 -2
- package/test/examples.txt +92 -0
- package/test/test.js +1 -1
package/README.md
CHANGED
|
@@ -181,6 +181,7 @@ A paragraph.
|
|
|
181
181
|
</figure>
|
|
182
182
|
<p>A paragraph.</p>
|
|
183
183
|
|
|
184
|
+
|
|
184
185
|
[Markdown]
|
|
185
186
|
A paragraph.
|
|
186
187
|
|
|
@@ -196,8 +197,62 @@ A paragraph.
|
|
|
196
197
|
<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>
|
|
197
198
|
</figure>
|
|
198
199
|
<p>A paragraph.</p>
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
[Markdown]
|
|
203
|
+
A paragraph.
|
|
204
|
+
|
|
205
|
+
Video. A youtube.
|
|
206
|
+
|
|
207
|
+
<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>
|
|
208
|
+
|
|
209
|
+
A paragraph.
|
|
210
|
+
[HTML]
|
|
211
|
+
<p>A paragraph.</p>
|
|
212
|
+
<figure class="f-video">
|
|
213
|
+
<figcaption><span class="f-video-label">Video<span class="f-video-label-joint">.</span></span> A youtube.</figcaption>
|
|
214
|
+
<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>
|
|
215
|
+
</figure>
|
|
216
|
+
<p>A paragraph.</p>
|
|
217
|
+
|
|
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
|
+
[Markdown]
|
|
237
|
+
A paragraph.
|
|
238
|
+
|
|
239
|
+
Figure. Twitter Post.
|
|
240
|
+
|
|
241
|
+
<blockquote class="twitter-tweet"><p lang="ja" dir="ltr">XXXXX <a href="https://t.co/XXXXX">https://t.co/XXXXX</a></p>— 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>
|
|
242
|
+
|
|
243
|
+
A paragraph.
|
|
244
|
+
[HTML]
|
|
245
|
+
<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>— 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>
|
|
249
|
+
</figure>
|
|
250
|
+
<p>A paragraph.</p>
|
|
251
|
+
|
|
199
252
|
~~~
|
|
200
253
|
|
|
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.
|
|
255
|
+
|
|
201
256
|
|
|
202
257
|
## Option: Specify file name
|
|
203
258
|
|
package/index.js
CHANGED
|
@@ -10,6 +10,9 @@ module.exports = function figure_with_caption_plugin(md, option) {
|
|
|
10
10
|
scaleSuffix: false,
|
|
11
11
|
dquoteFilename: false,
|
|
12
12
|
strongFilename: false,
|
|
13
|
+
bLabel: false,
|
|
14
|
+
strongLabel: false,
|
|
15
|
+
jointSpaceUseHalfWidth: false,
|
|
13
16
|
oneImageWithoutCaption: false,
|
|
14
17
|
};
|
|
15
18
|
if (option !== undefined) {
|
|
@@ -110,11 +113,16 @@ module.exports = function figure_with_caption_plugin(md, option) {
|
|
|
110
113
|
return true;
|
|
111
114
|
}
|
|
112
115
|
|
|
113
|
-
function wrapWithFigure(state, range, tagName, replaceInsteadOfWrap) {
|
|
116
|
+
function wrapWithFigure(state, range, tagName, replaceInsteadOfWrap, sp) {
|
|
114
117
|
let n = range.start;
|
|
115
118
|
let en = range.end;
|
|
116
119
|
const figureStartToken = new state.Token('figure_open', 'figure', 1);
|
|
117
120
|
figureStartToken.attrSet('class', 'f-' + tagName);
|
|
121
|
+
if (sp) {
|
|
122
|
+
if (sp.isTwitterBlock && sp.hasImgCaption) {
|
|
123
|
+
figureStartToken.attrSet('class', 'f-img');
|
|
124
|
+
}
|
|
125
|
+
}
|
|
118
126
|
if(/pre-(?:code|samp)/.test(tagName)) {
|
|
119
127
|
figureStartToken.attrSet('role', 'doc-example');
|
|
120
128
|
}
|
|
@@ -216,24 +224,52 @@ module.exports = function figure_with_caption_plugin(md, option) {
|
|
|
216
224
|
}
|
|
217
225
|
|
|
218
226
|
if (token.type === 'html_block') {
|
|
219
|
-
const tags = ['video', 'audio', 'iframe'];
|
|
227
|
+
const tags = ['video', 'audio', 'iframe', 'blockquote'];
|
|
220
228
|
let ctj = 0;
|
|
229
|
+
let sp = {};
|
|
221
230
|
while (ctj < tags.length) {
|
|
222
|
-
const hasTag = token.content.match(new RegExp('^<'+ tags[ctj] + ' ?[^>]*?>[\\s\\S]*?<\\/' + tags[ctj] + '
|
|
231
|
+
const hasTag = token.content.match(new RegExp('^<'+ tags[ctj] + ' ?[^>]*?>[\\s\\S]*?<\\/' + tags[ctj] + '> *?(?:<script [^>]*?>(?:</script>)?)?\\n'));
|
|
223
232
|
if (!hasTag) {
|
|
224
233
|
ctj++;
|
|
225
234
|
continue;
|
|
226
235
|
}
|
|
227
236
|
tagName = tags[ctj];
|
|
228
|
-
if (
|
|
237
|
+
if (tagName === 'iframe') {
|
|
229
238
|
if(/^<[^>]*? title="YouTube video player"/i.test(token.content)) {
|
|
230
|
-
tagName = 'video';
|
|
239
|
+
tagName = 'video'; // figure.f-video used.
|
|
240
|
+
}
|
|
241
|
+
// Non Youtube iframe currently use figure.f-iframe.
|
|
242
|
+
// Class in caption uses actual caption identifier.
|
|
243
|
+
}
|
|
244
|
+
if (tagName === 'blockquote') {
|
|
245
|
+
if(/^<[^>]*? class="twitter-tweet"/.test(token.content)) {
|
|
246
|
+
sp.isTwitterBlock = true;
|
|
247
|
+
if (n > 2) {
|
|
248
|
+
if (state.tokens[n-2].children.length > 1) {
|
|
249
|
+
if (state.tokens[n-2].children[1].attrs.length > 0) {
|
|
250
|
+
if (state.tokens[n-2].children[1].attrs[0][0] === 'class' &&
|
|
251
|
+
state.tokens[n-2].children[1].attrs[0][1] === 'f-img-label') {
|
|
252
|
+
sp.hasImgCaption = true;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
if (n + 2 < state.tokens.length) {
|
|
258
|
+
if (state.tokens[n+2].children.length > 1) {
|
|
259
|
+
if (state.tokens[n+2].children[1].attrs.length > 0) {
|
|
260
|
+
if (state.tokens[n+2].children[1].attrs[0][0] === 'class' &&
|
|
261
|
+
state.tokens[n+2].children[1].attrs[0][1] === 'f-img-label') {
|
|
262
|
+
sp.hasImgCaption = true;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
231
267
|
}
|
|
232
268
|
}
|
|
233
269
|
checkToken = true;
|
|
234
270
|
caption = checkCaption(state, n, en, tagName, caption);
|
|
235
271
|
if (caption.hasPrev || caption.hasNext) {
|
|
236
|
-
range = wrapWithFigure(state, range, tagName, false);
|
|
272
|
+
range = wrapWithFigure(state, range, tagName, false, sp);
|
|
237
273
|
break;
|
|
238
274
|
}
|
|
239
275
|
ctj++
|
|
@@ -251,6 +287,9 @@ module.exports = function figure_with_caption_plugin(md, option) {
|
|
|
251
287
|
tagName = 'img';
|
|
252
288
|
nextToken.children[0].type = 'image';
|
|
253
289
|
caption = checkCaption(state, n, en, tagName, caption);
|
|
290
|
+
if (opt.oneImageWithoutCaption && state.tokens[n-1]) {
|
|
291
|
+
if (state.tokens[n-1].type === 'list_item_open') {n++; continue;}
|
|
292
|
+
}
|
|
254
293
|
if (opt.oneImageWithoutCaption || caption.hasPrev || caption.hasNext) {
|
|
255
294
|
range = wrapWithFigure(state, range, tagName, true);
|
|
256
295
|
}
|
|
@@ -280,6 +319,9 @@ module.exports = function figure_with_caption_plugin(md, option) {
|
|
|
280
319
|
dquoteFilename: opt.dquoteFilename,
|
|
281
320
|
strongFilename: opt.strongFilename,
|
|
282
321
|
hasNumClass: opt.hasNumClass,
|
|
322
|
+
bLabel: opt.bLabel,
|
|
323
|
+
strongLabel: opt.strongLabel,
|
|
324
|
+
jointSpaceUseHalfWidth: opt.jointSpaceUseHalfWidth,
|
|
283
325
|
});
|
|
284
326
|
md.core.ruler.before('linkify', 'figure_with_caption', figureWithCaption);
|
|
285
327
|
md.renderer.rules['fence_samp'] = function (tokens, idx, options, env, slf) {
|
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.2",
|
|
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": {
|
|
@@ -16,6 +16,6 @@
|
|
|
16
16
|
"markdown-it": "^12.1.0"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"p7d-markdown-it-p-captions": "^0.
|
|
19
|
+
"p7d-markdown-it-p-captions": "^0.8.0"
|
|
20
20
|
}
|
|
21
21
|
}
|
package/test/examples.txt
CHANGED
|
@@ -409,6 +409,83 @@ A paragraph.
|
|
|
409
409
|
<p>A paragraph.</p>
|
|
410
410
|
|
|
411
411
|
|
|
412
|
+
[Markdown]
|
|
413
|
+
A paragraph.
|
|
414
|
+
|
|
415
|
+
Quote. Twitter Post.
|
|
416
|
+
|
|
417
|
+
<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>
|
|
418
|
+
|
|
419
|
+
A paragraph.
|
|
420
|
+
[HTML]
|
|
421
|
+
<p>A paragraph.</p>
|
|
422
|
+
<figure class="f-blockquote">
|
|
423
|
+
<figcaption><span class="f-blockquote-label">Quote<span class="f-blockquote-label-joint">.</span></span> Twitter Post.</figcaption>
|
|
424
|
+
<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>
|
|
425
|
+
</figure>
|
|
426
|
+
<p>A paragraph.</p>
|
|
427
|
+
|
|
428
|
+
[Markdown]
|
|
429
|
+
A paragraph.
|
|
430
|
+
|
|
431
|
+
Figure. Twitter Post.
|
|
432
|
+
|
|
433
|
+
<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>
|
|
434
|
+
|
|
435
|
+
A paragraph.
|
|
436
|
+
[HTML]
|
|
437
|
+
<p>A paragraph.</p>
|
|
438
|
+
<figure class="f-img">
|
|
439
|
+
<figcaption><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> Twitter Post.</figcaption>
|
|
440
|
+
<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>
|
|
441
|
+
</figure>
|
|
442
|
+
<p>A paragraph.</p>
|
|
443
|
+
|
|
444
|
+
[Markdown]
|
|
445
|
+
A paragraph.
|
|
446
|
+
|
|
447
|
+
<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>
|
|
448
|
+
|
|
449
|
+
Figure. Twitter Post.
|
|
450
|
+
|
|
451
|
+
A paragraph.
|
|
452
|
+
[HTML]
|
|
453
|
+
<p>A paragraph.</p>
|
|
454
|
+
<figure class="f-img">
|
|
455
|
+
<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>
|
|
456
|
+
<figcaption><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> Twitter Post.</figcaption>
|
|
457
|
+
</figure>
|
|
458
|
+
<p>A paragraph.</p>
|
|
459
|
+
|
|
460
|
+
[Markdown]
|
|
461
|
+
A paragraph.
|
|
462
|
+
|
|
463
|
+
<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>
|
|
464
|
+
|
|
465
|
+
Quote. Twitter Post.
|
|
466
|
+
|
|
467
|
+
A paragraph.
|
|
468
|
+
[HTML]
|
|
469
|
+
<p>A paragraph.</p>
|
|
470
|
+
<figure class="f-blockquote">
|
|
471
|
+
<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>
|
|
472
|
+
<figcaption><span class="f-blockquote-label">Quote<span class="f-blockquote-label-joint">.</span></span> Twitter Post.</figcaption>
|
|
473
|
+
</figure>
|
|
474
|
+
<p>A paragraph.</p>
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
[Markdown]
|
|
478
|
+
A paragraph.
|
|
479
|
+
|
|
480
|
+
<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>
|
|
481
|
+
|
|
482
|
+
A paragraph.
|
|
483
|
+
[HTML]
|
|
484
|
+
<p>A paragraph.</p>
|
|
485
|
+
<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>
|
|
486
|
+
<p>A paragraph.</p>
|
|
487
|
+
|
|
488
|
+
|
|
412
489
|
[Markdown]
|
|
413
490
|
A paragraph.
|
|
414
491
|
|
|
@@ -509,6 +586,21 @@ A paragraph.
|
|
|
509
586
|
<p>A paragraph.</p>
|
|
510
587
|
|
|
511
588
|
|
|
589
|
+
[Markdown]
|
|
590
|
+
A paragraph.
|
|
591
|
+
|
|
592
|
+
- 
|
|
593
|
+
|
|
594
|
+
A paragraph.
|
|
595
|
+
|
|
596
|
+
[HTML]
|
|
597
|
+
<p>A paragraph.</p>
|
|
598
|
+
<ul>
|
|
599
|
+
<li><img src="cat.jpg" alt="Figure"></li>
|
|
600
|
+
</ul>
|
|
601
|
+
<p>A paragraph.</p>
|
|
602
|
+
|
|
603
|
+
|
|
512
604
|
[Markdown]
|
|
513
605
|
A paragraph.
|
|
514
606
|
|