@peaceroad/markdown-it-figure-with-p-caption 0.2.1 → 0.3.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 +86 -2
- package/index.js +35 -2
- package/package.json +3 -3
- package/test/examples.txt +123 -0
- package/test/test.js +8 -3
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
|
|
|
@@ -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
|
|
|
@@ -138,3 +158,67 @@ A paragraph.
|
|
|
138
158
|
</figure>
|
|
139
159
|
<p>A paragraph.</p>
|
|
140
160
|
~~~
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
## Option: Specify file name
|
|
164
|
+
|
|
165
|
+
Specify the file name before writing the caption.
|
|
166
|
+
Note that a space is required between the file name and caption.
|
|
167
|
+
|
|
168
|
+
### Use double quote
|
|
169
|
+
|
|
170
|
+
```js
|
|
171
|
+
|
|
172
|
+
md.use(mdFigureWithPCaption, {dquoteFilename: true});
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
~~~
|
|
176
|
+
[Markdown]
|
|
177
|
+
A paragraph.
|
|
178
|
+
|
|
179
|
+
Code. "filename.js" Call a cat.
|
|
180
|
+
|
|
181
|
+
```js
|
|
182
|
+
console.log('Nyaan!');
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
A paragraph.
|
|
186
|
+
|
|
187
|
+
[HTML]
|
|
188
|
+
<p>A paragraph.</p>
|
|
189
|
+
<figure class="f-pre-code" role="doc-example">
|
|
190
|
+
<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> Call a cat.</figcaption>
|
|
191
|
+
<pre><code class="language-js">console.log('Nyaan!');
|
|
192
|
+
</code></pre>
|
|
193
|
+
</figure>
|
|
194
|
+
<p>A paragraph.</p>
|
|
195
|
+
~~~
|
|
196
|
+
|
|
197
|
+
### Use strong mark
|
|
198
|
+
|
|
199
|
+
```js
|
|
200
|
+
md.use(mdFigureWithPCaption, {strongFilename: true});
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
~~~
|
|
204
|
+
|
|
205
|
+
[Markdown]
|
|
206
|
+
A paragraph.
|
|
207
|
+
|
|
208
|
+
Code. **filename.js** Call a cat.
|
|
209
|
+
|
|
210
|
+
```js
|
|
211
|
+
console.log('Nyaan!');
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
A paragraph.
|
|
215
|
+
|
|
216
|
+
[HTML]
|
|
217
|
+
<p>A paragraph.</p>
|
|
218
|
+
<figure class="f-pre-code" role="doc-example">
|
|
219
|
+
<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> Call a cat.</figcaption>
|
|
220
|
+
<pre><code class="language-js">console.log('Nyaan!');
|
|
221
|
+
</code></pre>
|
|
222
|
+
</figure>
|
|
223
|
+
<p>A paragraph.</p>
|
|
224
|
+
~~~
|
package/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const { has } = require('markdown-it/lib/common/utils');
|
|
4
|
+
|
|
3
5
|
module.exports = function figure_with_caption_plugin(md, option) {
|
|
4
6
|
|
|
5
7
|
const mdPCaption = require('p7d-markdown-it-p-captions');
|
|
@@ -7,6 +9,8 @@ module.exports = function figure_with_caption_plugin(md, option) {
|
|
|
7
9
|
let opt = {
|
|
8
10
|
classPrefix: 'f',
|
|
9
11
|
scaleSuffix: false,
|
|
12
|
+
dquoteFilename: false,
|
|
13
|
+
strongFilename: false,
|
|
10
14
|
};
|
|
11
15
|
if (option !== undefined) {
|
|
12
16
|
for (let o in option) {
|
|
@@ -165,7 +169,7 @@ module.exports = function figure_with_caption_plugin(md, option) {
|
|
|
165
169
|
hasNext: false,
|
|
166
170
|
};
|
|
167
171
|
|
|
168
|
-
const checkTags = ['table', '
|
|
172
|
+
const checkTags = ['table', 'pre', 'blockquote'];
|
|
169
173
|
let cti = 0;
|
|
170
174
|
while (cti < checkTags.length) {
|
|
171
175
|
if (token.type === checkTags[cti] + '_open') {
|
|
@@ -211,6 +215,31 @@ module.exports = function figure_with_caption_plugin(md, option) {
|
|
|
211
215
|
cti++;
|
|
212
216
|
}
|
|
213
217
|
|
|
218
|
+
if (token.type === 'html_block') {
|
|
219
|
+
const tags = ['video', 'audio', 'iframe'];
|
|
220
|
+
let ctj = 0;
|
|
221
|
+
while (ctj < tags.length) {
|
|
222
|
+
const hasTag = token.content.match(new RegExp('^<'+ tags[ctj] + ' ?[^>]*?>[\\s\\S]*?<\\/' + tags[ctj] + '>\\n'));
|
|
223
|
+
if (!hasTag) {
|
|
224
|
+
ctj++;
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
tagName = tags[ctj];
|
|
228
|
+
if (tags[ctj] === 'iframe') {
|
|
229
|
+
if(/^<[^>]*? title="YouTube video player"/i.test(token.content)) {
|
|
230
|
+
tagName = 'video';
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
checkToken = true;
|
|
234
|
+
caption = checkCaption(state, n, en, tagName, caption);
|
|
235
|
+
if (caption.hasPrev || caption.hasNext) {
|
|
236
|
+
range = wrapWithFigure(state, range, tagName, false);
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
ctj++
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
214
243
|
if (token.type === 'paragraph_open'
|
|
215
244
|
&& nextToken.type === 'inline'
|
|
216
245
|
&& nextToken.children[0].type === 'image'
|
|
@@ -246,7 +275,11 @@ module.exports = function figure_with_caption_plugin(md, option) {
|
|
|
246
275
|
return;
|
|
247
276
|
}
|
|
248
277
|
|
|
249
|
-
md.use(mdPCaption, {
|
|
278
|
+
md.use(mdPCaption, {
|
|
279
|
+
classPrefix: opt.classPrefix,
|
|
280
|
+
dquoteFilename: opt.dquoteFilename,
|
|
281
|
+
strongFilename: opt.strongFilename,
|
|
282
|
+
});
|
|
250
283
|
md.core.ruler.before('linkify', 'figure_with_caption', figureWithCaption);
|
|
251
284
|
md.renderer.rules['fence_samp'] = function (tokens, idx, options, env, slf) {
|
|
252
285
|
const token = tokens[idx];
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peaceroad/markdown-it-figure-with-p-caption",
|
|
3
|
-
"version": "0.2
|
|
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.2",
|
|
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.6.2"
|
|
20
20
|
}
|
|
21
21
|
}
|
package/test/examples.txt
CHANGED
|
@@ -326,3 +326,126 @@ 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>
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
[Markdown]
|
|
414
|
+
A paragraph.
|
|
415
|
+
|
|
416
|
+
Code. "filename.js" Call a cat.
|
|
417
|
+
|
|
418
|
+
```js
|
|
419
|
+
console.log('Nyaan!');
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
A paragraph.
|
|
423
|
+
|
|
424
|
+
[HTML]
|
|
425
|
+
<p>A paragraph.</p>
|
|
426
|
+
<figure class="f-pre-code" role="doc-example">
|
|
427
|
+
<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> Call a cat.</figcaption>
|
|
428
|
+
<pre><code class="language-js">console.log('Nyaan!');
|
|
429
|
+
</code></pre>
|
|
430
|
+
</figure>
|
|
431
|
+
<p>A paragraph.</p>
|
|
432
|
+
|
|
433
|
+
[Markdown]
|
|
434
|
+
A paragraph.
|
|
435
|
+
|
|
436
|
+
Code. **filename.js** Call a cat.
|
|
437
|
+
|
|
438
|
+
```js
|
|
439
|
+
console.log('Nyaan!');
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
A paragraph.
|
|
443
|
+
|
|
444
|
+
[HTML]
|
|
445
|
+
<p>A paragraph.</p>
|
|
446
|
+
<figure class="f-pre-code" role="doc-example">
|
|
447
|
+
<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> Call a cat.</figcaption>
|
|
448
|
+
<pre><code class="language-js">console.log('Nyaan!');
|
|
449
|
+
</code></pre>
|
|
450
|
+
</figure>
|
|
451
|
+
<p>A paragraph.</p>
|
package/test/test.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
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
|
-
md.use(mdFigureWithPCaption
|
|
8
|
+
md.use(mdFigureWithPCaption, {
|
|
9
|
+
dquoteFilename: true,
|
|
10
|
+
strongFilename: true,
|
|
11
|
+
});
|
|
7
12
|
|
|
8
13
|
const example = __dirname + '/examples.txt';
|
|
9
14
|
const mdPath = __dirname + '/examples.md';
|
|
@@ -31,7 +36,7 @@ while(n < ms0.length) {
|
|
|
31
36
|
|
|
32
37
|
n = 1;
|
|
33
38
|
while(n < ms.length) {
|
|
34
|
-
//if (n !==
|
|
39
|
+
//if (n !== 21) { n++; continue };
|
|
35
40
|
console.log('Test: ' + n + ' >>>');
|
|
36
41
|
//console.log(ms[n].markdown);
|
|
37
42
|
|