@peaceroad/markdown-it-figure-with-p-caption 0.4.3 → 0.4.4

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
@@ -284,11 +284,13 @@ module.exports = function figure_with_caption_plugin(md, option) {
284
284
  }
285
285
  }
286
286
 
287
- if (token.type === 'paragraph_open'
288
- && nextToken.type === 'inline'
289
- && nextToken.children[0].type === 'image'
290
- && nextToken.children.length === 1
291
- && state.tokens[n+2].type === 'paragraph_close') {
287
+
288
+ if (token.type === 'paragraph_open' && nextToken.type === 'inline' && nextToken.children[0].type === 'image' && state.tokens[n+2].type === 'paragraph_close' && nextToken.children.length < 3) {
289
+ if (nextToken.children.length === 2) {
290
+ if (!nextToken.children[nextToken.children.length - 1].type === 'text' || !/^ *?\{.*?\}$/.test(nextToken.children[nextToken.children.length - 1].content)) {
291
+ n++; continue;
292
+ }
293
+ }
292
294
  checkToken = true;
293
295
  en = n + 2;
294
296
  range.end = en;
@@ -296,9 +298,9 @@ module.exports = function figure_with_caption_plugin(md, option) {
296
298
  nextToken.children[0].type = 'image';
297
299
  caption = checkCaption(state, n, en, tagName, caption);
298
300
  if (opt.oneImageWithoutCaption && state.tokens[n-1]) {
299
- if (state.tokens[n-1].type === 'list_item_open') {n++; continue;}
301
+ if (state.tokens[n-1].type === 'list_item_open') {checkToken = false;}
300
302
  }
301
- if (opt.oneImageWithoutCaption || caption.hasPrev || caption.hasNext) {
303
+ if (checkToken && (opt.oneImageWithoutCaption || caption.hasPrev || caption.hasNext)) {
302
304
  range = wrapWithFigure(state, range, tagName, true);
303
305
  }
304
306
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peaceroad/markdown-it-figure-with-p-caption",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
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,7 +13,8 @@
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"
16
+ "markdown-it": "^12.1.0",
17
+ "markdown-it-attrs": "^4.1.4"
17
18
  },
18
19
  "dependencies": {
19
20
  "p7d-markdown-it-p-captions": "^0.9.0"
package/test/examples.txt CHANGED
@@ -666,3 +666,20 @@ A paragraph.
666
666
  <p>A paragraph.</p>
667
667
 
668
668
 
669
+ [Markdown]
670
+ Figure. A Caption.
671
+
672
+ ![Figure](cat.jpg) {.style}
673
+ [HTML]
674
+ <figure class="f-img style">
675
+ <figcaption><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> A Caption.</figcaption>
676
+ <img src="cat.jpg" alt="Figure">
677
+ </figure>
678
+
679
+ [Markdown]
680
+ Figure. A Caption.
681
+
682
+ ![Figure](cat.jpg) Text {.style}
683
+ [HTML]
684
+ <p class="f-img"><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> A Caption.</p>
685
+ <p class="style"><img src="cat.jpg" alt="Figure"> Text</p>
package/test/test.js CHANGED
@@ -4,6 +4,7 @@ const md = require('markdown-it')({ html: true });
4
4
  const mdOneImage = require('markdown-it')({ html: true });
5
5
  const mdFigureWithPCaption = require('../index.js');
6
6
 
7
+ const attrs = require('../node_modules/markdown-it-attrs');
7
8
 
8
9
  md.use(mdFigureWithPCaption, {
9
10
  dquoteFilename: true,
@@ -17,8 +18,7 @@ mdOneImage.use(mdFigureWithPCaption, {
17
18
  strongFilename: true,
18
19
  oneImageWithoutCaption: true,
19
20
  hasNumClass: true,
20
- });
21
-
21
+ }).use(attrs);
22
22
 
23
23
  const example = __dirname + '/examples.txt';
24
24
  const mdPath = __dirname + '/examples.md';