@peaceroad/markdown-it-figure-with-p-caption 0.4.2 → 0.4.3
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/index.js +9 -0
- package/package.json +2 -2
- package/test/examples.txt +45 -0
- package/test/test.js +17 -5
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
|
+
removeUnnumberedLabel: false,
|
|
17
18
|
};
|
|
18
19
|
if (option !== undefined) {
|
|
19
20
|
for (let o in option) {
|
|
@@ -25,6 +26,9 @@ module.exports = function figure_with_caption_plugin(md, option) {
|
|
|
25
26
|
if(n < 3) {return caption;}
|
|
26
27
|
const captionStartToken = state.tokens[n-3];
|
|
27
28
|
const captionEndToken = state.tokens[n-1];
|
|
29
|
+
if (captionStartToken === undefined || captionEndToken === undefined) {
|
|
30
|
+
return caption;
|
|
31
|
+
}
|
|
28
32
|
if (captionStartToken.type !== 'paragraph_open'
|
|
29
33
|
&& captionEndToken.type !== 'paragraph_close') {
|
|
30
34
|
return caption;
|
|
@@ -71,6 +75,9 @@ module.exports = function figure_with_caption_plugin(md, option) {
|
|
|
71
75
|
if (en + 2 > state.tokens.length) { return caption; }
|
|
72
76
|
const captionStartToken = state.tokens[en+1];
|
|
73
77
|
const captionEndToken = state.tokens[en+3];
|
|
78
|
+
if (captionStartToken === undefined || captionEndToken === undefined) {
|
|
79
|
+
return caption;
|
|
80
|
+
}
|
|
74
81
|
if (captionStartToken.type !== 'paragraph_open'
|
|
75
82
|
&& captionEndToken.type !== 'paragraph_close') {
|
|
76
83
|
return caption;
|
|
@@ -154,6 +161,7 @@ module.exports = function figure_with_caption_plugin(md, option) {
|
|
|
154
161
|
|
|
155
162
|
function checkCaption(state, n, en, tagName, caption) {
|
|
156
163
|
caption = checkPrevCaption(state, n, en, tagName, caption);
|
|
164
|
+
if (caption.hasPrev) return caption;
|
|
157
165
|
caption = checkNextCaption(state, n, en, tagName, caption);
|
|
158
166
|
return caption;
|
|
159
167
|
}
|
|
@@ -322,6 +330,7 @@ module.exports = function figure_with_caption_plugin(md, option) {
|
|
|
322
330
|
bLabel: opt.bLabel,
|
|
323
331
|
strongLabel: opt.strongLabel,
|
|
324
332
|
jointSpaceUseHalfWidth: opt.jointSpaceUseHalfWidth,
|
|
333
|
+
removeUnnumberedLabel: opt.removeUnnumberedLabel,
|
|
325
334
|
});
|
|
326
335
|
md.core.ruler.before('linkify', 'figure_with_caption', figureWithCaption);
|
|
327
336
|
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.3",
|
|
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.9.0"
|
|
20
20
|
}
|
|
21
21
|
}
|
package/test/examples.txt
CHANGED
|
@@ -372,9 +372,16 @@ A paragraph.
|
|
|
372
372
|
</figure>
|
|
373
373
|
<p>A paragraph.</p>
|
|
374
374
|
|
|
375
|
+
|
|
375
376
|
[Markdown]
|
|
376
377
|
A paragraph.
|
|
377
378
|
|
|
379
|
+
Figure. A cat.
|
|
380
|
+
|
|
381
|
+

|
|
382
|
+
|
|
383
|
+
A paragraph.
|
|
384
|
+
|
|
378
385
|
Video. A mp4.
|
|
379
386
|
|
|
380
387
|
<video controls width="400" height="300">
|
|
@@ -382,8 +389,14 @@ Video. A mp4.
|
|
|
382
389
|
</video>
|
|
383
390
|
|
|
384
391
|
A paragraph.
|
|
392
|
+
|
|
385
393
|
[HTML]
|
|
386
394
|
<p>A paragraph.</p>
|
|
395
|
+
<figure class="f-img">
|
|
396
|
+
<figcaption><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> A cat.</figcaption>
|
|
397
|
+
<img src="cat.jpg" alt="Figure">
|
|
398
|
+
</figure>
|
|
399
|
+
<p>A paragraph.</p>
|
|
387
400
|
<figure class="f-video">
|
|
388
401
|
<figcaption><span class="f-video-label">Video<span class="f-video-label-joint">.</span></span> A mp4.</figcaption>
|
|
389
402
|
<video controls width="400" height="300">
|
|
@@ -392,6 +405,37 @@ A paragraph.
|
|
|
392
405
|
</figure>
|
|
393
406
|
<p>A paragraph.</p>
|
|
394
407
|
|
|
408
|
+
|
|
409
|
+
[Markdown]
|
|
410
|
+
A paragraph.
|
|
411
|
+
|
|
412
|
+
Figure. A cat.
|
|
413
|
+
|
|
414
|
+

|
|
415
|
+
|
|
416
|
+
Video. A mp4.
|
|
417
|
+
|
|
418
|
+
<video controls width="400" height="300">
|
|
419
|
+
<source src="example.mp4" type="video/mp4">
|
|
420
|
+
</video>
|
|
421
|
+
|
|
422
|
+
A paragraph.
|
|
423
|
+
|
|
424
|
+
[HTML]
|
|
425
|
+
<p>A paragraph.</p>
|
|
426
|
+
<figure class="f-img">
|
|
427
|
+
<figcaption><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> A cat.</figcaption>
|
|
428
|
+
<img src="cat.jpg" alt="Figure">
|
|
429
|
+
</figure>
|
|
430
|
+
<figure class="f-video">
|
|
431
|
+
<figcaption><span class="f-video-label">Video<span class="f-video-label-joint">.</span></span> A mp4.</figcaption>
|
|
432
|
+
<video controls width="400" height="300">
|
|
433
|
+
<source src="example.mp4" type="video/mp4">
|
|
434
|
+
</video>
|
|
435
|
+
</figure>
|
|
436
|
+
<p>A paragraph.</p>
|
|
437
|
+
|
|
438
|
+
|
|
395
439
|
[Markdown]
|
|
396
440
|
A paragraph.
|
|
397
441
|
|
|
@@ -621,3 +665,4 @@ A paragraph.
|
|
|
621
665
|
</figure>
|
|
622
666
|
<p>A paragraph.</p>
|
|
623
667
|
|
|
668
|
+
|
package/test/test.js
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
const assert = require('assert');
|
|
2
2
|
const fs = require('fs');
|
|
3
|
-
const md = require('markdown-it')({
|
|
4
|
-
|
|
5
|
-
});
|
|
3
|
+
const md = require('markdown-it')({ html: true });
|
|
4
|
+
const mdOneImage = require('markdown-it')({ html: true });
|
|
6
5
|
const mdFigureWithPCaption = require('../index.js');
|
|
7
6
|
|
|
8
7
|
|
|
9
8
|
md.use(mdFigureWithPCaption, {
|
|
9
|
+
dquoteFilename: true,
|
|
10
|
+
strongFilename: true,
|
|
11
|
+
oneImageWithoutCaption: false,
|
|
12
|
+
hasNumClass: true,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
mdOneImage.use(mdFigureWithPCaption, {
|
|
10
16
|
dquoteFilename: true,
|
|
11
17
|
strongFilename: true,
|
|
12
18
|
oneImageWithoutCaption: true,
|
|
@@ -40,12 +46,18 @@ while(n < ms0.length) {
|
|
|
40
46
|
|
|
41
47
|
n = 1;
|
|
42
48
|
while(n < ms.length) {
|
|
43
|
-
//if (n !==
|
|
49
|
+
//if (n !== 22) { n++; continue };
|
|
44
50
|
console.log('Test: ' + n + ' >>>');
|
|
45
51
|
//console.log(ms[n].markdown);
|
|
46
52
|
|
|
47
53
|
const m = ms[n].markdown;
|
|
48
|
-
|
|
54
|
+
let h = ''
|
|
55
|
+
if (n > 20) {
|
|
56
|
+
h = mdOneImage.render(m);
|
|
57
|
+
} else {
|
|
58
|
+
h = md.render(m);
|
|
59
|
+
}
|
|
60
|
+
|
|
49
61
|
try {
|
|
50
62
|
assert.strictEqual(h, ms[n].html);
|
|
51
63
|
} catch(e) {
|