@peaceroad/markdown-it-figure-with-p-caption 0.3.2 → 0.4.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 +65 -2
- package/index.js +4 -3
- package/package.json +2 -2
- package/test/examples.txt +82 -2
- package/test/test.js +4 -0
package/README.md
CHANGED
|
@@ -10,6 +10,8 @@ For a paragraph with only one image, a table or code block or a blockquote, and
|
|
|
10
10
|
|
|
11
11
|
The figcaption behavior of this plugin depends on [p7d-markdown-it-p-captions](https://www.npmjs.com/package/p7d-markdown-it-p-captions).
|
|
12
12
|
|
|
13
|
+
Note. If code block language setting is "samp", change it to use samp element instead of code element.
|
|
14
|
+
|
|
13
15
|
Use it as follows.
|
|
14
16
|
|
|
15
17
|
```js
|
|
@@ -27,10 +29,10 @@ console.log(md.render('Figure. A Cat.\n\n');
|
|
|
27
29
|
|
|
28
30
|
Also, It is recommended to set the width and height attributes of the images at the same time. See: [@peaceroad/markdown-it-renderer-image](https://www.npmjs.com/package/@peaceroad/markdown-it-renderer-image).
|
|
29
31
|
|
|
30
|
-
It could be applied to table, codeblock(pre > code, pre > samp), video
|
|
32
|
+
It could be applied to table, codeblock(pre > code, pre > samp), video as well.
|
|
31
33
|
|
|
32
|
-
Example:
|
|
33
34
|
|
|
35
|
+
## Example
|
|
34
36
|
|
|
35
37
|
~~~
|
|
36
38
|
[Markdown]
|
|
@@ -157,6 +159,43 @@ A paragraph.
|
|
|
157
159
|
</samp></pre>
|
|
158
160
|
</figure>
|
|
159
161
|
<p>A paragraph.</p>
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
[Markdown]
|
|
165
|
+
A paragraph.
|
|
166
|
+
|
|
167
|
+
Video. A mp4.
|
|
168
|
+
|
|
169
|
+
<video controls width="400" height="300">
|
|
170
|
+
<source src="example.mp4" type="video/mp4">
|
|
171
|
+
</video>
|
|
172
|
+
|
|
173
|
+
A paragraph.
|
|
174
|
+
[HTML]
|
|
175
|
+
<p>A paragraph.</p>
|
|
176
|
+
<figure class="f-video">
|
|
177
|
+
<figcaption><span class="f-video-label">Video<span class="f-video-label-joint">.</span></span> A mp4.</figcaption>
|
|
178
|
+
<video controls width="400" height="300">
|
|
179
|
+
<source src="example.mp4" type="video/mp4">
|
|
180
|
+
</video>
|
|
181
|
+
</figure>
|
|
182
|
+
<p>A paragraph.</p>
|
|
183
|
+
|
|
184
|
+
[Markdown]
|
|
185
|
+
A paragraph.
|
|
186
|
+
|
|
187
|
+
Video. A youtube.
|
|
188
|
+
|
|
189
|
+
<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>
|
|
190
|
+
|
|
191
|
+
A paragraph.
|
|
192
|
+
[HTML]
|
|
193
|
+
<p>A paragraph.</p>
|
|
194
|
+
<figure class="f-video">
|
|
195
|
+
<figcaption><span class="f-video-label">Video<span class="f-video-label-joint">.</span></span> A youtube.</figcaption>
|
|
196
|
+
<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
|
+
</figure>
|
|
198
|
+
<p>A paragraph.</p>
|
|
160
199
|
~~~
|
|
161
200
|
|
|
162
201
|
|
|
@@ -222,3 +261,27 @@ A paragraph.
|
|
|
222
261
|
</figure>
|
|
223
262
|
<p>A paragraph.</p>
|
|
224
263
|
~~~
|
|
264
|
+
|
|
265
|
+
## Option: Convert one image paragraph without caption
|
|
266
|
+
|
|
267
|
+
Convert one image paragraph without a caption paragraph to figure element.
|
|
268
|
+
|
|
269
|
+
```js
|
|
270
|
+
md.use(mdFigureWithPCaption, {oneImageWithoutCaption: true});
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
~~~
|
|
274
|
+
[Markdown]
|
|
275
|
+
A paragraph.
|
|
276
|
+
|
|
277
|
+

|
|
278
|
+
|
|
279
|
+
A paragraph.
|
|
280
|
+
|
|
281
|
+
[HTML]
|
|
282
|
+
<p>A paragraph.</p>
|
|
283
|
+
<figure class="f-img">
|
|
284
|
+
<img src="cat.jpg" alt="Figure">
|
|
285
|
+
</figure>
|
|
286
|
+
<p>A paragraph.</p>
|
|
287
|
+
~~~
|
package/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const { has } = require('markdown-it/lib/common/utils');
|
|
4
|
-
|
|
5
3
|
module.exports = function figure_with_caption_plugin(md, option) {
|
|
6
4
|
|
|
7
5
|
const mdPCaption = require('p7d-markdown-it-p-captions');
|
|
8
6
|
|
|
9
7
|
let opt = {
|
|
10
8
|
classPrefix: 'f',
|
|
9
|
+
hasNumClass: false,
|
|
11
10
|
scaleSuffix: false,
|
|
12
11
|
dquoteFilename: false,
|
|
13
12
|
strongFilename: false,
|
|
13
|
+
oneImageWithoutCaption: false,
|
|
14
14
|
};
|
|
15
15
|
if (option !== undefined) {
|
|
16
16
|
for (let o in option) {
|
|
@@ -251,7 +251,7 @@ module.exports = function figure_with_caption_plugin(md, option) {
|
|
|
251
251
|
tagName = 'img';
|
|
252
252
|
nextToken.children[0].type = 'image';
|
|
253
253
|
caption = checkCaption(state, n, en, tagName, caption);
|
|
254
|
-
if (caption.hasPrev || caption.hasNext) {
|
|
254
|
+
if (opt.oneImageWithoutCaption || caption.hasPrev || caption.hasNext) {
|
|
255
255
|
range = wrapWithFigure(state, range, tagName, true);
|
|
256
256
|
}
|
|
257
257
|
}
|
|
@@ -279,6 +279,7 @@ module.exports = function figure_with_caption_plugin(md, option) {
|
|
|
279
279
|
classPrefix: opt.classPrefix,
|
|
280
280
|
dquoteFilename: opt.dquoteFilename,
|
|
281
281
|
strongFilename: opt.strongFilename,
|
|
282
|
+
hasNumClass: opt.hasNumClass,
|
|
282
283
|
});
|
|
283
284
|
md.core.ruler.before('linkify', 'figure_with_caption', figureWithCaption);
|
|
284
285
|
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.
|
|
3
|
+
"version": "0.4.1",
|
|
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.7.0"
|
|
20
20
|
}
|
|
21
21
|
}
|
package/test/examples.txt
CHANGED
|
@@ -266,7 +266,6 @@ A paragraph.
|
|
|
266
266
|
<p><img src="cat.jpg" alt="Figure"></p>
|
|
267
267
|
|
|
268
268
|
|
|
269
|
-
|
|
270
269
|
[Markdown]
|
|
271
270
|
Figure. A cat.
|
|
272
271
|
|
|
@@ -286,7 +285,7 @@ Figure 12. A cat.
|
|
|
286
285
|
|
|
287
286
|
[HTML]
|
|
288
287
|
<figure class="f-img">
|
|
289
|
-
<figcaption><span class="f-img-label">Figure 12<span class="f-img-label-joint">.</span></span> A cat.</figcaption>
|
|
288
|
+
<figcaption><span class="f-img-label label-has-num">Figure 12<span class="f-img-label-joint">.</span></span> A cat.</figcaption>
|
|
290
289
|
<img src="cat.jpg" alt="Figure">
|
|
291
290
|
</figure>
|
|
292
291
|
|
|
@@ -449,3 +448,84 @@ A paragraph.
|
|
|
449
448
|
</code></pre>
|
|
450
449
|
</figure>
|
|
451
450
|
<p>A paragraph.</p>
|
|
451
|
+
|
|
452
|
+
[Markdown]
|
|
453
|
+
A paragraph.
|
|
454
|
+
|
|
455
|
+
Code. "filename.js"
|
|
456
|
+
|
|
457
|
+
```js
|
|
458
|
+
console.log('Nyaan!');
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
A paragraph.
|
|
462
|
+
|
|
463
|
+
[HTML]
|
|
464
|
+
<p>A paragraph.</p>
|
|
465
|
+
<figure class="f-pre-code" role="doc-example">
|
|
466
|
+
<figcaption><span class="f-pre-code-label">Code<span class="f-pre-code-label-joint">.</span></span> <strong class="f-pre-code-filename">filename.js</strong></figcaption>
|
|
467
|
+
<pre><code class="language-js">console.log('Nyaan!');
|
|
468
|
+
</code></pre>
|
|
469
|
+
</figure>
|
|
470
|
+
<p>A paragraph.</p>
|
|
471
|
+
|
|
472
|
+
[Markdown]
|
|
473
|
+
A paragraph.
|
|
474
|
+
|
|
475
|
+
Code. **filename.js**
|
|
476
|
+
|
|
477
|
+
```js
|
|
478
|
+
console.log('Nyaan!');
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
A paragraph.
|
|
482
|
+
|
|
483
|
+
[HTML]
|
|
484
|
+
<p>A paragraph.</p>
|
|
485
|
+
<figure class="f-pre-code" role="doc-example">
|
|
486
|
+
<figcaption><span class="f-pre-code-label">Code<span class="f-pre-code-label-joint">.</span></span> <strong class="f-pre-code-filename">filename.js</strong></figcaption>
|
|
487
|
+
<pre><code class="language-js">console.log('Nyaan!');
|
|
488
|
+
</code></pre>
|
|
489
|
+
</figure>
|
|
490
|
+
<p>A paragraph.</p>
|
|
491
|
+
|
|
492
|
+
[Markdown]
|
|
493
|
+

|
|
494
|
+
|
|
495
|
+
A paragraph.
|
|
496
|
+
|
|
497
|
+

|
|
498
|
+
|
|
499
|
+
A paragraph.
|
|
500
|
+
|
|
501
|
+
[HTML]
|
|
502
|
+
<figure class="f-img">
|
|
503
|
+
<img src="cat.jpg" alt="Figure">
|
|
504
|
+
</figure>
|
|
505
|
+
<p>A paragraph.</p>
|
|
506
|
+
<figure class="f-img">
|
|
507
|
+
<img src="cat.jpg" alt="Figure">
|
|
508
|
+
</figure>
|
|
509
|
+
<p>A paragraph.</p>
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
[Markdown]
|
|
513
|
+
A paragraph.
|
|
514
|
+
|
|
515
|
+
リスト1 キャプション
|
|
516
|
+
|
|
517
|
+
```js
|
|
518
|
+
console.log('Nyaan!');
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
A paragraph.
|
|
522
|
+
|
|
523
|
+
[HTML]
|
|
524
|
+
<p>A paragraph.</p>
|
|
525
|
+
<figure class="f-pre-code" role="doc-example">
|
|
526
|
+
<figcaption><span class="f-pre-code-label label-has-num">リスト1</span> キャプション</figcaption>
|
|
527
|
+
<pre><code class="language-js">console.log('Nyaan!');
|
|
528
|
+
</code></pre>
|
|
529
|
+
</figure>
|
|
530
|
+
<p>A paragraph.</p>
|
|
531
|
+
|
package/test/test.js
CHANGED
|
@@ -5,11 +5,15 @@ const md = require('markdown-it')({
|
|
|
5
5
|
});
|
|
6
6
|
const mdFigureWithPCaption = require('../index.js');
|
|
7
7
|
|
|
8
|
+
|
|
8
9
|
md.use(mdFigureWithPCaption, {
|
|
9
10
|
dquoteFilename: true,
|
|
10
11
|
strongFilename: true,
|
|
12
|
+
oneImageWithoutCaption: true,
|
|
13
|
+
hasNumClass: true,
|
|
11
14
|
});
|
|
12
15
|
|
|
16
|
+
|
|
13
17
|
const example = __dirname + '/examples.txt';
|
|
14
18
|
const mdPath = __dirname + '/examples.md';
|
|
15
19
|
const exampleCont = fs.readFileSync(example, 'utf-8').trim();
|