@peaceroad/markdown-it-figure-with-p-caption 0.3.0 → 0.3.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/README.md CHANGED
@@ -158,3 +158,67 @@ A paragraph.
158
158
  </figure>
159
159
  <p>A paragraph.</p>
160
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', 'video', 'audio', 'pre', 'blockquote'];
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, {'classPrefix': opt.classPrefix});
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@peaceroad/markdown-it-figure-with-p-caption",
3
- "version": "0.3.0",
3
+ "version": "0.3.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.5.0"
19
+ "p7d-markdown-it-p-captions": "^0.6.3"
20
20
  }
21
21
  }
package/test/examples.txt CHANGED
@@ -373,3 +373,119 @@ A paragraph.
373
373
  </figure>
374
374
  <p>A paragraph.</p>
375
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>
452
+
453
+ [Markdown]
454
+ A paragraph.
455
+
456
+ Code. "filename.js"
457
+
458
+ ```js
459
+ console.log('Nyaan!');
460
+ ```
461
+
462
+ A paragraph.
463
+
464
+ [HTML]
465
+ <p>A paragraph.</p>
466
+ <figure class="f-pre-code" role="doc-example">
467
+ <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>
468
+ <pre><code class="language-js">console.log('Nyaan!');
469
+ </code></pre>
470
+ </figure>
471
+ <p>A paragraph.</p>
472
+
473
+ [Markdown]
474
+ A paragraph.
475
+
476
+ Code. **filename.js**
477
+
478
+ ```js
479
+ console.log('Nyaan!');
480
+ ```
481
+
482
+ A paragraph.
483
+
484
+ [HTML]
485
+ <p>A paragraph.</p>
486
+ <figure class="f-pre-code" role="doc-example">
487
+ <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>
488
+ <pre><code class="language-js">console.log('Nyaan!');
489
+ </code></pre>
490
+ </figure>
491
+ <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 !== 1) { n++; continue };
39
+ //if (n !== 21) { n++; continue };
35
40
  console.log('Test: ' + n + ' >>>');
36
41
  //console.log(ms[n].markdown);
37
42