@peaceroad/markdown-it-figure-with-p-caption 0.5.1 → 0.5.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
@@ -2,9 +2,9 @@
2
2
 
3
3
  This is a markdown-it plugin.
4
4
 
5
- For a paragraph with one image/images only, 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.
5
+ For a paragraph with one image/images only, a table or code block or a blockquote or a iframe, 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, blockquote, and video.
7
+ 1. Check that the element: one image only paragraph, table, code block, samp block, blockquote, and video, iframe.
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
 
@@ -389,6 +389,14 @@ A paragraph.
389
389
  <p>A paragraph.</p>
390
390
  ~~~
391
391
 
392
+ ### Convert one video element without caption
393
+
394
+ Convert one video element without a caption paragraph to figure element.
395
+
396
+ ```js
397
+ md.use(mdFigureWithPCaption, {videoWithoutCaption: true});
398
+ ```
399
+
392
400
  #### Convert one iframe without caption
393
401
 
394
402
  Convert one iframe without a caption paragraph to iframe element. (adn twitter blockquote embed eelment.)
package/index.js CHANGED
@@ -15,6 +15,7 @@ module.exports = function figure_with_caption_plugin(md, option) {
15
15
  jointSpaceUseHalfWidth: false,
16
16
  oneImageWithoutCaption: false,
17
17
  iframeWithoutCaption: false,
18
+ videoWithoutCaption: false,
18
19
  removeUnnumberedLabel: false,
19
20
  removeUnnumberedLabelExceptMarks: [],
20
21
  multipleImages: true,
@@ -130,7 +131,10 @@ module.exports = function figure_with_caption_plugin(md, option) {
130
131
  const figureStartToken = new state.Token('figure_open', 'figure', 1);
131
132
  figureStartToken.attrSet('class', 'f-' + tagName);
132
133
  if (sp) {
133
- if (sp.isTwitterBlock) {
134
+ if (sp.isYoutube) {
135
+ figureStartToken.attrSet('class', 'f-video');
136
+ }
137
+ if (sp.isTwitter) {
134
138
  if (sp.hasImgCaption) {
135
139
  figureStartToken.attrSet('class', 'f-img');
136
140
  } else {
@@ -263,12 +267,12 @@ module.exports = function figure_with_caption_plugin(md, option) {
263
267
  tagName = tags[ctj];
264
268
  if (tagName === 'iframe') {
265
269
  if(/^<[^>]*? src="https:\/\/(?:www.youtube-nocookie.com|player.vimeo.com)\//i.test(token.content)) {
266
- tagName = 'video'; // figure.f-video used.
270
+ sp.isYoutube = true;
267
271
  }
268
272
  }
269
273
  if (tagName === 'blockquote') {
270
274
  if(/^<[^>]*? class="twitter-tweet"/.test(token.content)) {
271
- sp.isTwitterBlock = true;
275
+ sp.isTwitter = true;
272
276
  if (n > 2) {
273
277
  if (state.tokens[n-2].children.length > 1) {
274
278
  if (state.tokens[n-2].children[1].attrs.length > 0) {
@@ -300,9 +304,11 @@ module.exports = function figure_with_caption_plugin(md, option) {
300
304
  }
301
305
  checkToken = true;
302
306
  caption = checkCaption(state, n, en, tagName, caption);
303
- if (opt.iframeWithoutCaption || caption.hasPrev || caption.hasNext) {
307
+ if (caption.hasPrev || caption.hasNext ||
308
+ (opt.iframeWithoutCaption && (tagName === 'iframe' || sp.isTwitter)) ||
309
+ (opt.videoWithoutCaption && tagName === 'video')) {
304
310
  range = wrapWithFigure(state, range, tagName, false, sp);
305
- if (opt.iframeWithoutCaption && (!caption.hasPrev || !caption.hasNext)) {
311
+ if ((opt.videoWithoutCaption || opt.iframeWithoutCaption) && (!caption.hasPrev || !caption.hasNext)) {
306
312
  n = en + 2;
307
313
  }
308
314
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peaceroad/markdown-it-figure-with-p-caption",
3
- "version": "0.5.1",
3
+ "version": "0.5.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": {
@@ -13,10 +13,10 @@
13
13
  "url": "https://github.com/peaceroad/p7d-markdown-it-figure-with-p-caption/issues"
14
14
  },
15
15
  "devDependencies": {
16
- "markdown-it": "^12.1.0",
17
- "markdown-it-attrs": "^4.1.4"
16
+ "markdown-it": "^14.1.0",
17
+ "markdown-it-attrs": "^4.1.6"
18
18
  },
19
19
  "dependencies": {
20
- "p7d-markdown-it-p-captions": "^0.10.0"
20
+ "p7d-markdown-it-p-captions": "^0.12.0"
21
21
  }
22
22
  }
package/test/examples.txt CHANGED
@@ -731,6 +731,17 @@ A paragraph.
731
731
  <iframe class="speakerdeck-iframe" style="border: 0px none; background: rgba(0, 0, 0, 0.1) padding-box; margin: 0px; padding: 0px; border-radius: 6px; box-shadow: rgba(0, 0, 0, 0.2) 0px 5px 40px; width: 100%; height: auto; aspect-ratio: 560 / 314;" src="https://speakerdeck.com/player/xxxxxxxxxxxxxx" title="xxxxxxxxxxx" allowfullscreen="true" data-ratio="1.78343949044586" frameborder="0"></iframe>
732
732
  </figure>
733
733
 
734
+
735
+ [Markdown]
736
+ Slide. A caption.
737
+
738
+ <iframe class="speakerdeck-iframe" style="border: 0px none; background: rgba(0, 0, 0, 0.1) padding-box; margin: 0px; padding: 0px; border-radius: 6px; box-shadow: rgba(0, 0, 0, 0.2) 0px 5px 40px; width: 100%; height: auto; aspect-ratio: 560 / 314;" src="https://speakerdeck.com/player/xxxxxxxxxxxxxx" title="xxxxxxxxxxx" allowfullscreen="true" data-ratio="1.78343949044586" frameborder="0"></iframe>
739
+ [HTML]
740
+ <figure class="f-iframe">
741
+ <figcaption><span class="f-slide-label">Slide<span class="f-slide-label-joint">.</span></span> A caption.</figcaption>
742
+ <iframe class="speakerdeck-iframe" style="border: 0px none; background: rgba(0, 0, 0, 0.1) padding-box; margin: 0px; padding: 0px; border-radius: 6px; box-shadow: rgba(0, 0, 0, 0.2) 0px 5px 40px; width: 100%; height: auto; aspect-ratio: 560 / 314;" src="https://speakerdeck.com/player/xxxxxxxxxxxxxx" title="xxxxxxxxxxx" allowfullscreen="true" data-ratio="1.78343949044586" frameborder="0"></iframe>
743
+ </figure>
744
+
734
745
  [Markdown]
735
746
  <iframe src="https://player.vimeo.com/video/xxxxxxxxxxxxxxx" width="640" height="360" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>
736
747
  <p><a href="https://vimeo.com/xxxx">Title</a> from <a href="https://vimeo.com/yyy">User</a> on <a href="https://vimeo.com">Vimeo</a>.</p>
@@ -898,3 +909,32 @@ A paragraph.
898
909
  <img src="cat3.jpg" alt="Three cat"><img src="cat4.jpg" alt="Four cat">
899
910
  </figure>
900
911
  <p>A paragraph.</p>
912
+
913
+
914
+ [Markdown]
915
+ <video controls width="400" height="300">
916
+ <source src="example.mp4" type="video/mp4">
917
+ </video>
918
+ [HTML]
919
+ <video controls width="400" height="300">
920
+ <source src="example.mp4" type="video/mp4">
921
+ </video>
922
+
923
+ [Markdown]
924
+ <video controls width="400" height="300">
925
+ <source src="example.mp4" type="video/mp4">
926
+ </video>
927
+ [HTML]
928
+ <figure class="f-video">
929
+ <video controls width="400" height="300">
930
+ <source src="example.mp4" type="video/mp4">
931
+ </video>
932
+ </figure>
933
+
934
+ [Markdown]
935
+ <blockquote class="twitter-tweet"><p lang="ja" dir="ltr">XXXXX <a href="https://t.co/XXXXX">https://t.co/XXXXX</a></p>&mdash; User (@twitter) <a href="https://twitter.com/UserID/status/XXXXX">August 4, 2022</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
936
+ [HTML]
937
+ <figure class="f-iframe">
938
+ <blockquote class="twitter-tweet"><p lang="ja" dir="ltr">XXXXX <a href="https://t.co/XXXXX">https://t.co/XXXXX</a></p>&mdash; User (@twitter) <a href="https://twitter.com/UserID/status/XXXXX">August 4, 2022</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
939
+ </figure>
940
+
package/test/test.js CHANGED
@@ -4,44 +4,34 @@ const md = require('markdown-it')({ html: true });
4
4
  const mdOneImage = require('markdown-it')({ html: true });
5
5
  const mdWithoutCaption = require('markdown-it')({ html: true });
6
6
  const mdMultipleImages = require('markdown-it')({ html: true });
7
+ const mdAllOptionTrue = require('markdown-it')({ html: true });
7
8
 
8
9
  const mdFigureWithPCaption = require('../index.js');
9
10
 
10
11
  const attrs = require('../node_modules/markdown-it-attrs');
11
-
12
- md.use(mdFigureWithPCaption, {
12
+ let opt = {
13
13
  dquoteFilename: true,
14
14
  strongFilename: true,
15
15
  oneImageWithoutCaption: false,
16
16
  hasNumClass: true,
17
- });
17
+ }
18
+ md.use(mdFigureWithPCaption, opt);
18
19
 
19
- mdOneImage.use(mdFigureWithPCaption, {
20
- dquoteFilename: true,
21
- strongFilename: true,
22
- oneImageWithoutCaption: true,
23
- hasNumClass: true,
24
- }).use(attrs);
20
+ opt.oneImageWithoutCaption = true
21
+ mdOneImage.use(mdFigureWithPCaption, opt).use(attrs);
25
22
 
26
- mdWithoutCaption.use(mdFigureWithPCaption, {
27
- dquoteFilename: true,
28
- strongFilename: true,
29
- oneImageWithoutCaption: true,
30
- iframeWithoutCaption: true,
31
- hasNumClass: true,
32
- }).use(attrs);
23
+ opt.iframeWithoutCaption = true
24
+ mdWithoutCaption.use(mdFigureWithPCaption, opt).use(attrs);
25
+
26
+ opt.multipleImages = true
27
+ mdMultipleImages.use(mdFigureWithPCaption, opt).use(attrs)
28
+
29
+ opt.videoWithoutCaption = true
30
+ mdAllOptionTrue.use(mdFigureWithPCaption, opt).use(attrs)
33
31
 
34
- mdMultipleImages.use(attrs).use(mdFigureWithPCaption, {
35
- dquoteFilename: true,
36
- strongFilename: true,
37
- oneImageWithoutCaption: true,
38
- iframeWithoutCaption: true,
39
- hasNumClass: true,
40
- multipleImages: true,
41
- })
42
32
 
43
33
  const example = __dirname + '/examples.txt';
44
- const mdPath = __dirname + '/examples.md';
34
+
45
35
  const exampleCont = fs.readFileSync(example, 'utf-8').trim();
46
36
  let ms = [];
47
37
  let ms0 = exampleCont.split(/\n*\[Markdown\]\n/);
@@ -65,14 +55,16 @@ while(n < ms0.length) {
65
55
  }
66
56
 
67
57
  n = 1;
58
+ let pass = true
68
59
  while(n < ms.length) {
69
60
  //if (n !== 37) { n++; continue };
70
- console.log('Test: ' + n + ' >>>');
71
61
  //console.log(ms[n].markdown);
72
62
 
73
63
  const m = ms[n].markdown;
74
64
  let h = ''
75
- if (n > 44) {
65
+ if (n >= 56) {
66
+ h = mdAllOptionTrue.render(m);
67
+ } else if (n > 44) {
76
68
  h = mdMultipleImages.render(m);
77
69
  } else if (n > 37) {
78
70
  h = mdWithoutCaption.render(m);
@@ -85,8 +77,13 @@ while(n < ms.length) {
85
77
  try {
86
78
  assert.strictEqual(h, ms[n].html);
87
79
  } catch(e) {
88
- console.log('incorrect: ');
80
+ pass =false
81
+ console.log('Test: ' + n + ' >>>');
82
+ console.log('incorrect:');
83
+ console.log(opt);
89
84
  console.log('H: ' + h +'C: ' + ms[n].html);
90
85
  };
91
86
  n++;
92
- }
87
+ }
88
+
89
+ if (pass) console.log('Passed all test.')