@peaceroad/markdown-it-figure-with-p-caption 0.2.0 → 0.3.1
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 +23 -3
- package/index.js +26 -1
- package/package.json +3 -3
- package/test/examples.txt +82 -0
- package/test/test.js +5 -6
package/README.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
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, 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 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.
|
|
6
6
|
|
|
7
|
-
1. Check that the element: one image only paragraph, table, code block, samp block ,and video.
|
|
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
|
|
9
9
|
3. If there is the caption paragraph, convert them to figure and figcaption element.
|
|
10
10
|
|
|
@@ -16,7 +16,7 @@ Use it as follows.
|
|
|
16
16
|
const md = require('markdown-it')();
|
|
17
17
|
const mdFigureWithPCaption = require('@peaceroad/markdown-it-figure-with-p-caption');
|
|
18
18
|
|
|
19
|
-
md.use(
|
|
19
|
+
md.use(mdFigureWithPCaption);
|
|
20
20
|
|
|
21
21
|
console.log(md.render('Figure. A Cat.\n\n');
|
|
22
22
|
// <figure class="f-img">
|
|
@@ -116,6 +116,26 @@ A paragraph.
|
|
|
116
116
|
<p>A paragraph.</p>
|
|
117
117
|
|
|
118
118
|
|
|
119
|
+
[Markdown]
|
|
120
|
+
A paragraph.
|
|
121
|
+
|
|
122
|
+
Quote. A Caption.
|
|
123
|
+
|
|
124
|
+
> A quoted paragraph.
|
|
125
|
+
|
|
126
|
+
A paragraph.
|
|
127
|
+
|
|
128
|
+
[HTML]
|
|
129
|
+
<p>A paragraph.</p>
|
|
130
|
+
<figure class="f-blockquote">
|
|
131
|
+
<figcaption><span class="f-blockquote-label">Code<span class="f-blockquote-label-joint">.</span></span> A Caption.</figcaption>
|
|
132
|
+
<blockquote>
|
|
133
|
+
<p>A quoted paragraph.</p>
|
|
134
|
+
</blockquote>
|
|
135
|
+
</figure>
|
|
136
|
+
<p>A paragraph.</p>
|
|
137
|
+
|
|
138
|
+
|
|
119
139
|
[Markdown]
|
|
120
140
|
A paragraph.
|
|
121
141
|
|
package/index.js
CHANGED
|
@@ -165,7 +165,7 @@ module.exports = function figure_with_caption_plugin(md, option) {
|
|
|
165
165
|
hasNext: false,
|
|
166
166
|
};
|
|
167
167
|
|
|
168
|
-
const checkTags = ['table', '
|
|
168
|
+
const checkTags = ['table', 'pre', 'blockquote'];
|
|
169
169
|
let cti = 0;
|
|
170
170
|
while (cti < checkTags.length) {
|
|
171
171
|
if (token.type === checkTags[cti] + '_open') {
|
|
@@ -211,6 +211,31 @@ module.exports = function figure_with_caption_plugin(md, option) {
|
|
|
211
211
|
cti++;
|
|
212
212
|
}
|
|
213
213
|
|
|
214
|
+
if (token.type === 'html_block') {
|
|
215
|
+
const tags = ['video', 'audio', 'iframe'];
|
|
216
|
+
let ctj = 0;
|
|
217
|
+
while (ctj < tags.length) {
|
|
218
|
+
const hasTag = token.content.match(new RegExp('^<'+ tags[ctj] + ' ?[^>]*?>[\\s\\S]*?<\\/' + tags[ctj] + '>\\n'))
|
|
219
|
+
if (!hasTag) {
|
|
220
|
+
ctj++;
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
tagName = tags[ctj];
|
|
224
|
+
if (tags[ctj] === 'iframe') {
|
|
225
|
+
if(/^<[^>]*? title="YouTube video player"/i.test(token.content)) {
|
|
226
|
+
tagName = 'video';
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
checkToken = true;
|
|
230
|
+
caption = checkCaption(state, n, en, tagName, caption);
|
|
231
|
+
if (caption.hasPrev || caption.hasNext) {
|
|
232
|
+
range = wrapWithFigure(state, range, tagName, false);
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
ctj++
|
|
237
|
+
}
|
|
238
|
+
|
|
214
239
|
if (token.type === 'paragraph_open'
|
|
215
240
|
&& nextToken.type === 'inline'
|
|
216
241
|
&& nextToken.children[0].type === 'image'
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peaceroad/markdown-it-figure-with-p-caption",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "A markdown-it plugin. For a paragraph with only one image, a table or code block, and by writing a caption paragraph immediately before or after, they are converted into the figure element with the figcaption element.",
|
|
3
|
+
"version": "0.3.1",
|
|
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": {
|
|
7
7
|
"test": "node test/test.js"
|
|
@@ -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.5.0"
|
|
20
20
|
}
|
|
21
21
|
}
|
package/test/examples.txt
CHANGED
|
@@ -326,3 +326,85 @@ A paragraph.
|
|
|
326
326
|
</tr>
|
|
327
327
|
</tbody>
|
|
328
328
|
</table>
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
[Markdown]
|
|
332
|
+
A paragraph.
|
|
333
|
+
|
|
334
|
+
Quote. A Caption.
|
|
335
|
+
|
|
336
|
+
> A quoted paragraph.
|
|
337
|
+
>
|
|
338
|
+
> A quoted paragraph.
|
|
339
|
+
|
|
340
|
+
A paragraph.
|
|
341
|
+
|
|
342
|
+
[HTML]
|
|
343
|
+
<p>A paragraph.</p>
|
|
344
|
+
<figure class="f-blockquote">
|
|
345
|
+
<figcaption><span class="f-blockquote-label">Quote<span class="f-blockquote-label-joint">.</span></span> A Caption.</figcaption>
|
|
346
|
+
<blockquote>
|
|
347
|
+
<p>A quoted paragraph.</p>
|
|
348
|
+
<p>A quoted paragraph.</p>
|
|
349
|
+
</blockquote>
|
|
350
|
+
</figure>
|
|
351
|
+
<p>A paragraph.</p>
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
[Markdown]
|
|
355
|
+
A paragraph.
|
|
356
|
+
|
|
357
|
+
> A quoted paragraph.
|
|
358
|
+
>
|
|
359
|
+
> A quoted paragraph.
|
|
360
|
+
|
|
361
|
+
Quote. A Caption.
|
|
362
|
+
|
|
363
|
+
A paragraph.
|
|
364
|
+
|
|
365
|
+
[HTML]
|
|
366
|
+
<p>A paragraph.</p>
|
|
367
|
+
<figure class="f-blockquote">
|
|
368
|
+
<blockquote>
|
|
369
|
+
<p>A quoted paragraph.</p>
|
|
370
|
+
<p>A quoted paragraph.</p>
|
|
371
|
+
</blockquote>
|
|
372
|
+
<figcaption><span class="f-blockquote-label">Quote<span class="f-blockquote-label-joint">.</span></span> A Caption.</figcaption>
|
|
373
|
+
</figure>
|
|
374
|
+
<p>A paragraph.</p>
|
|
375
|
+
|
|
376
|
+
[Markdown]
|
|
377
|
+
A paragraph.
|
|
378
|
+
|
|
379
|
+
Video. A mp4.
|
|
380
|
+
|
|
381
|
+
<video controls width="400" height="300">
|
|
382
|
+
<source src="example.mp4" type="video/mp4">
|
|
383
|
+
</video>
|
|
384
|
+
|
|
385
|
+
A paragraph.
|
|
386
|
+
[HTML]
|
|
387
|
+
<p>A paragraph.</p>
|
|
388
|
+
<figure class="f-video">
|
|
389
|
+
<figcaption><span class="f-video-label">Video<span class="f-video-label-joint">.</span></span> A mp4.</figcaption>
|
|
390
|
+
<video controls width="400" height="300">
|
|
391
|
+
<source src="example.mp4" type="video/mp4">
|
|
392
|
+
</video>
|
|
393
|
+
</figure>
|
|
394
|
+
<p>A paragraph.</p>
|
|
395
|
+
|
|
396
|
+
[Markdown]
|
|
397
|
+
A paragraph.
|
|
398
|
+
|
|
399
|
+
Video. A youtube.
|
|
400
|
+
|
|
401
|
+
<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>
|
|
402
|
+
|
|
403
|
+
A paragraph.
|
|
404
|
+
[HTML]
|
|
405
|
+
<p>A paragraph.</p>
|
|
406
|
+
<figure class="f-video">
|
|
407
|
+
<figcaption><span class="f-video-label">Video<span class="f-video-label-joint">.</span></span> A youtube.</figcaption>
|
|
408
|
+
<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>
|
|
409
|
+
</figure>
|
|
410
|
+
<p>A paragraph.</p>
|
package/test/test.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const assert = require('assert');
|
|
2
2
|
const fs = require('fs');
|
|
3
|
-
const md = require('markdown-it')(
|
|
3
|
+
const md = require('markdown-it')({
|
|
4
|
+
html: true,
|
|
5
|
+
});
|
|
4
6
|
const mdFigureWithPCaption = require('../index.js');
|
|
5
7
|
|
|
6
8
|
md.use(mdFigureWithPCaption);
|
|
@@ -31,15 +33,12 @@ while(n < ms0.length) {
|
|
|
31
33
|
|
|
32
34
|
n = 1;
|
|
33
35
|
while(n < ms.length) {
|
|
34
|
-
//if (n !==
|
|
36
|
+
//if (n !== 21) { n++; continue };
|
|
35
37
|
console.log('Test: ' + n + ' >>>');
|
|
36
38
|
//console.log(ms[n].markdown);
|
|
37
39
|
|
|
38
40
|
const m = ms[n].markdown;
|
|
39
|
-
const
|
|
40
|
-
'md': mdPath,
|
|
41
|
-
}
|
|
42
|
-
const h = md.render(m, renderEnv);
|
|
41
|
+
const h = md.render(m);
|
|
43
42
|
try {
|
|
44
43
|
assert.strictEqual(h, ms[n].html);
|
|
45
44
|
} catch(e) {
|