@peaceroad/markdown-it-figure-with-p-caption 0.4.4 → 0.4.5
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 +26 -1
- package/index.js +9 -2
- package/package.json +1 -1
- package/test/examples.txt +29 -0
- package/test/test.js +13 -1
package/README.md
CHANGED
|
@@ -317,7 +317,9 @@ A paragraph.
|
|
|
317
317
|
<p>A paragraph.</p>
|
|
318
318
|
~~~
|
|
319
319
|
|
|
320
|
-
## Option
|
|
320
|
+
## Option
|
|
321
|
+
|
|
322
|
+
### Convert one image paragraph without caption
|
|
321
323
|
|
|
322
324
|
Convert one image paragraph without a caption paragraph to figure element.
|
|
323
325
|
|
|
@@ -340,3 +342,26 @@ A paragraph.
|
|
|
340
342
|
</figure>
|
|
341
343
|
<p>A paragraph.</p>
|
|
342
344
|
~~~
|
|
345
|
+
|
|
346
|
+
#### Convert one iframe without caption
|
|
347
|
+
|
|
348
|
+
Convert one iframe without a caption paragraph to figure element.
|
|
349
|
+
|
|
350
|
+
```js
|
|
351
|
+
md.use(mdFigureWithPCaption, {iframeWithoutCaption: true});
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
~~~
|
|
355
|
+
[Markdown]
|
|
356
|
+
A paragraph.
|
|
357
|
+
|
|
358
|
+
<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>
|
|
359
|
+
|
|
360
|
+
A paragraph.
|
|
361
|
+
[HTML]
|
|
362
|
+
<p>A paragraph.</p>
|
|
363
|
+
<figure class="f-video">
|
|
364
|
+
<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
|
+
</figure>
|
|
366
|
+
<p>A paragraph.</p>
|
|
367
|
+
~~~
|
package/index.js
CHANGED
|
@@ -14,6 +14,7 @@ module.exports = function figure_with_caption_plugin(md, option) {
|
|
|
14
14
|
strongLabel: false,
|
|
15
15
|
jointSpaceUseHalfWidth: false,
|
|
16
16
|
oneImageWithoutCaption: false,
|
|
17
|
+
iframeWithoutCaption: false,
|
|
17
18
|
removeUnnumberedLabel: false,
|
|
18
19
|
};
|
|
19
20
|
if (option !== undefined) {
|
|
@@ -236,11 +237,14 @@ module.exports = function figure_with_caption_plugin(md, option) {
|
|
|
236
237
|
let ctj = 0;
|
|
237
238
|
let sp = {};
|
|
238
239
|
while (ctj < tags.length) {
|
|
239
|
-
const hasTag = token.content.match(new RegExp('^<'+ tags[ctj] + ' ?[^>]*?>[\\s\\S]*?<\\/' + tags[ctj] + '> *?(?:<script [^>]*?>(?:</script>)?)
|
|
240
|
+
const hasTag = token.content.match(new RegExp('^<'+ tags[ctj] + ' ?[^>]*?>[\\s\\S]*?<\\/' + tags[ctj] + '> *?(?:<script [^>]*?>(?:</script>)?)?(\\n|$)'));
|
|
240
241
|
if (!hasTag) {
|
|
241
242
|
ctj++;
|
|
242
243
|
continue;
|
|
243
244
|
}
|
|
245
|
+
if (hasTag[hasTag.length - 1] !== '\n') {
|
|
246
|
+
token.content += '\n'
|
|
247
|
+
}
|
|
244
248
|
tagName = tags[ctj];
|
|
245
249
|
if (tagName === 'iframe') {
|
|
246
250
|
if(/^<[^>]*? title="YouTube video player"/i.test(token.content)) {
|
|
@@ -276,8 +280,11 @@ module.exports = function figure_with_caption_plugin(md, option) {
|
|
|
276
280
|
}
|
|
277
281
|
checkToken = true;
|
|
278
282
|
caption = checkCaption(state, n, en, tagName, caption);
|
|
279
|
-
if (caption.hasPrev || caption.hasNext) {
|
|
283
|
+
if (opt.iframeWithoutCaption || caption.hasPrev || caption.hasNext) {
|
|
280
284
|
range = wrapWithFigure(state, range, tagName, false, sp);
|
|
285
|
+
if (opt.iframeWithoutCaption && (!caption.hasPrev || !caption.hasNext)) {
|
|
286
|
+
n = en + 2;
|
|
287
|
+
}
|
|
281
288
|
break;
|
|
282
289
|
}
|
|
283
290
|
ctj++
|
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.5",
|
|
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": {
|
package/test/examples.txt
CHANGED
|
@@ -683,3 +683,32 @@ Figure. A Caption.
|
|
|
683
683
|
[HTML]
|
|
684
684
|
<p class="f-img"><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> A Caption.</p>
|
|
685
685
|
<p class="style"><img src="cat.jpg" alt="Figure"> Text</p>
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
[Markdown]
|
|
689
|
+
A paragraph.
|
|
690
|
+
|
|
691
|
+
<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>
|
|
692
|
+
|
|
693
|
+
A paragraph.
|
|
694
|
+
[HTML]
|
|
695
|
+
<p>A paragraph.</p>
|
|
696
|
+
<figure class="f-video">
|
|
697
|
+
<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>
|
|
698
|
+
</figure>
|
|
699
|
+
<p>A paragraph.</p>
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
[Markdown]
|
|
703
|
+
<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>
|
|
704
|
+
[HTML]
|
|
705
|
+
<figure class="f-video">
|
|
706
|
+
<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>
|
|
707
|
+
</figure>
|
|
708
|
+
|
|
709
|
+
[Markdown]
|
|
710
|
+
<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>
|
|
711
|
+
[HTML]
|
|
712
|
+
<figure class="f-iframe">
|
|
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
|
+
</figure>
|
package/test/test.js
CHANGED
|
@@ -2,6 +2,8 @@ const assert = require('assert');
|
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const md = require('markdown-it')({ html: true });
|
|
4
4
|
const mdOneImage = require('markdown-it')({ html: true });
|
|
5
|
+
const mdWithoutCaption = require('markdown-it')({ html: true });
|
|
6
|
+
|
|
5
7
|
const mdFigureWithPCaption = require('../index.js');
|
|
6
8
|
|
|
7
9
|
const attrs = require('../node_modules/markdown-it-attrs');
|
|
@@ -20,6 +22,14 @@ mdOneImage.use(mdFigureWithPCaption, {
|
|
|
20
22
|
hasNumClass: true,
|
|
21
23
|
}).use(attrs);
|
|
22
24
|
|
|
25
|
+
mdWithoutCaption.use(mdFigureWithPCaption, {
|
|
26
|
+
dquoteFilename: true,
|
|
27
|
+
strongFilename: true,
|
|
28
|
+
oneImageWithoutCaption: true,
|
|
29
|
+
iframeWithoutCaption: true,
|
|
30
|
+
hasNumClass: true,
|
|
31
|
+
}).use(attrs);
|
|
32
|
+
|
|
23
33
|
const example = __dirname + '/examples.txt';
|
|
24
34
|
const mdPath = __dirname + '/examples.md';
|
|
25
35
|
const exampleCont = fs.readFileSync(example, 'utf-8').trim();
|
|
@@ -52,7 +62,9 @@ while(n < ms.length) {
|
|
|
52
62
|
|
|
53
63
|
const m = ms[n].markdown;
|
|
54
64
|
let h = ''
|
|
55
|
-
if (n >
|
|
65
|
+
if (n > 37) {
|
|
66
|
+
h = mdWithoutCaption.render(m);
|
|
67
|
+
} else if (n > 20) {
|
|
56
68
|
h = mdOneImage.render(m);
|
|
57
69
|
} else {
|
|
58
70
|
h = md.render(m);
|