@peaceroad/markdown-it-figure-with-p-caption 0.3.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/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', 'video', 'audio', 'pre', 'blockquote'];
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@peaceroad/markdown-it-figure-with-p-caption",
3
- "version": "0.3.0",
3
+ "version": "0.3.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": {
package/test/examples.txt CHANGED
@@ -373,3 +373,38 @@ 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>
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,7 +33,7 @@ while(n < ms0.length) {
31
33
 
32
34
  n = 1;
33
35
  while(n < ms.length) {
34
- //if (n !== 1) { n++; continue };
36
+ //if (n !== 21) { n++; continue };
35
37
  console.log('Test: ' + n + ' >>>');
36
38
  //console.log(ms[n].markdown);
37
39