@peaceroad/markdown-it-figure-with-p-caption 0.3.3 → 0.4.0

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
@@ -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![Figure](cat.jpg)');
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, audio as well.
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
+ ![Figure](cat.jpg)
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,7 +1,5 @@
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');
@@ -11,6 +9,7 @@ module.exports = function figure_with_caption_plugin(md, option) {
11
9
  scaleSuffix: false,
12
10
  dquoteFilename: false,
13
11
  strongFilename: false,
12
+ oneImageWithoutCaption: false,
14
13
  };
15
14
  if (option !== undefined) {
16
15
  for (let o in option) {
@@ -251,7 +250,7 @@ module.exports = function figure_with_caption_plugin(md, option) {
251
250
  tagName = 'img';
252
251
  nextToken.children[0].type = 'image';
253
252
  caption = checkCaption(state, n, en, tagName, caption);
254
- if (caption.hasPrev || caption.hasNext) {
253
+ if (opt.oneImageWithoutCaption || caption.hasPrev || caption.hasNext) {
255
254
  range = wrapWithFigure(state, range, tagName, true);
256
255
  }
257
256
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peaceroad/markdown-it-figure-with-p-caption",
3
- "version": "0.3.3",
3
+ "version": "0.4.0",
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
@@ -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
 
@@ -489,3 +488,22 @@ A paragraph.
489
488
  </code></pre>
490
489
  </figure>
491
490
  <p>A paragraph.</p>
491
+
492
+ [Markdown]
493
+ ![Figure](cat.jpg)
494
+
495
+ A paragraph.
496
+
497
+ ![Figure](cat.jpg)
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>
package/test/test.js CHANGED
@@ -5,11 +5,14 @@ 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,
11
13
  });
12
14
 
15
+
13
16
  const example = __dirname + '/examples.txt';
14
17
  const mdPath = __dirname + '/examples.md';
15
18
  const exampleCont = fs.readFileSync(example, 'utf-8').trim();