@peaceroad/markdown-it-figure-with-p-caption 0.6.0 → 0.7.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 +9 -7
- package/index.js +140 -121
- package/package.json +3 -1
- package/test/examples-console.txt +94 -0
- package/test/examples-iframe-type-blockquote-without-caption.txt +64 -0
- package/test/examples-iframe-without-caption.txt +4 -25
- package/test/examples-img-alt-caption.txt +22 -9
- package/test/examples-img-title-caption.txt +0 -2
- package/test/examples-no-option.txt +10 -1
- package/test/test.js +35 -11
package/README.md
CHANGED
|
@@ -4,21 +4,23 @@ This is a markdown-it plugin.
|
|
|
4
4
|
|
|
5
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
|
|
7
|
+
1. Check that the element: one image only paragraph, table, code(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
|
|
|
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
|
-
Notice.
|
|
13
|
+
**Notice.** Starting with version 0.7, the process changing from code to samp tag has been migrated to [@peaceroad/markdown-it-renderer-fence](https://www.npmjs.com/package/@peaceroad/markdown-it-renderer-fence). If you want to continue processing as before, please use this plugin at the same time.
|
|
14
|
+
(The tests for this plugin and this Readme output used the plugins together.)
|
|
14
15
|
|
|
15
|
-
Notice
|
|
16
|
+
**Notice.** You can also use `markdown-it-attrs` at the same time. However, if there is `{.style}` at the end of a paragraph with only an image, and the next paragraph is a caption, `markdown-it-attrs` alone does not handle it well, so this plugin takes care of that. (This processing is optional `{styleProcess: true}` and can be turned off.) [0.5.0]
|
|
16
17
|
|
|
17
18
|
Use it as follows.
|
|
18
19
|
|
|
19
20
|
```js
|
|
20
21
|
import mdit from 'markdown-it'
|
|
21
22
|
import mditFigureWithPCaption from '@peaceroad/markdown-it-figure-with-p-caption'
|
|
23
|
+
import mditRendererFence from '@peaceroad/markdown-it-renderer-fence' /* to processing code -> smap tag etc. process.*/
|
|
22
24
|
|
|
23
25
|
const md = mdit()
|
|
24
26
|
md.use(mditFigureWithPCaption)
|
|
@@ -467,7 +469,7 @@ A paragraph.
|
|
|
467
469
|
In Markdown documents, captions are often written in the alt attribute of images. If you follow the syntax of this plugin, the commit log will be cluttered. Therefore, as an option, the alt attribute is treated as a caption.
|
|
468
470
|
Note that you cannot use this plugin's syntax and this option's syntax at the same time.
|
|
469
471
|
|
|
470
|
-
|
|
472
|
+
The img alt attribute have an empty value.
|
|
471
473
|
|
|
472
474
|
```js
|
|
473
475
|
const mdImgAltCaption = mdit({html: true}).use(mditFigureWithPCaption, {imgAltCaption: 'Figure'})
|
|
@@ -480,16 +482,16 @@ const mdImgAltCaption = mdit({html: true}).use(mditFigureWithPCaption, {imgAltCa
|
|
|
480
482
|
[HTML]
|
|
481
483
|
<figure class="f-img">
|
|
482
484
|
<figcaption><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> A caption.</figcaption>
|
|
483
|
-
<img src="cat.jpg" alt="
|
|
485
|
+
<img src="cat.jpg" alt="">
|
|
484
486
|
</figure>
|
|
485
487
|
```
|
|
486
488
|
|
|
487
489
|
## Option: imgTitleCaption
|
|
488
490
|
|
|
489
491
|
The title attribute of the Markdown img element is used as the caption.
|
|
490
|
-
Note that you cannot use this plugin's syntax and this option's syntax at the same time.
|
|
492
|
+
Note that you cannot use this plugin's standard syntax and this option's syntax at the same time.
|
|
491
493
|
|
|
492
|
-
|
|
494
|
+
The img alt attribute is not specially modified during conversion; the Markdown alt attribute is used as is.
|
|
493
495
|
|
|
494
496
|
```js
|
|
495
497
|
const mdImgAltCaption = mdit({html: true}).use(mditFigureWithPCaption, {imgTitleCaption: 'Figure'})
|
package/index.js
CHANGED
|
@@ -4,6 +4,7 @@ const mditFigureWithPCaption = (md, option) => {
|
|
|
4
4
|
|
|
5
5
|
let opt = {
|
|
6
6
|
classPrefix: 'f',
|
|
7
|
+
styleProcess : true,
|
|
7
8
|
hasNumClass: false,
|
|
8
9
|
scaleSuffix: false,
|
|
9
10
|
dquoteFilename: false,
|
|
@@ -14,10 +15,10 @@ const mditFigureWithPCaption = (md, option) => {
|
|
|
14
15
|
oneImageWithoutCaption: false,
|
|
15
16
|
iframeWithoutCaption: false,
|
|
16
17
|
videoWithoutCaption: false,
|
|
18
|
+
iframeTypeBlockquoteWithoutCaption: false,
|
|
17
19
|
removeUnnumberedLabel: false,
|
|
18
20
|
removeUnnumberedLabelExceptMarks: [],
|
|
19
21
|
multipleImages: true,
|
|
20
|
-
styleProcess: true,
|
|
21
22
|
imgAltCaption: false,
|
|
22
23
|
imgTitleCaption: false,
|
|
23
24
|
};
|
|
@@ -57,6 +58,19 @@ const mditFigureWithPCaption = (md, option) => {
|
|
|
57
58
|
const captionStartToken = state.tokens[n-3];
|
|
58
59
|
const captionInlineToken = state.tokens[n-2];
|
|
59
60
|
const captionEndToken = state.tokens[n-1];
|
|
61
|
+
let isNoCaption = false
|
|
62
|
+
if (captionInlineToken.attrs) {
|
|
63
|
+
for (let attr of captionInlineToken.attrs) {
|
|
64
|
+
if (attr[0] === 'class' && attr[1] === 'nocaption') {
|
|
65
|
+
isNoCaption = true
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (isNoCaption) {
|
|
70
|
+
state.tokens.splice(n-3, 3)
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
|
|
60
74
|
captionStartToken.attrs.forEach(attr => {
|
|
61
75
|
if (attr[0] === 'class') {
|
|
62
76
|
attr[1] = attr[1].replace(new RegExp(' *?f-' + caption.name), '').trim();
|
|
@@ -124,21 +138,19 @@ const mditFigureWithPCaption = (md, option) => {
|
|
|
124
138
|
return true;
|
|
125
139
|
}
|
|
126
140
|
|
|
127
|
-
|
|
141
|
+
const wrapWithFigure = (state, range, tagName, caption, replaceInsteadOfWrap, sp) => {
|
|
128
142
|
let n = range.start;
|
|
129
143
|
let en = range.end;
|
|
130
144
|
const figureStartToken = new state.Token('figure_open', 'figure', 1);
|
|
131
145
|
figureStartToken.attrSet('class', 'f-' + tagName);
|
|
132
|
-
if (sp) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (sp.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
} else {
|
|
146
|
+
if (sp.isVideoIframe) {
|
|
147
|
+
figureStartToken.attrSet('class', 'f-video');
|
|
148
|
+
}
|
|
149
|
+
if (sp.isIframeTypeBlockQuote) {
|
|
150
|
+
if (sp.hasImgCaption) {
|
|
151
|
+
figureStartToken.attrSet('class', 'f-img');
|
|
152
|
+
} else {
|
|
140
153
|
figureStartToken.attrSet('class', 'f-iframe');
|
|
141
|
-
}
|
|
142
154
|
}
|
|
143
155
|
}
|
|
144
156
|
if(/pre-(?:code|samp)/.test(tagName)) {
|
|
@@ -147,14 +159,12 @@ const mditFigureWithPCaption = (md, option) => {
|
|
|
147
159
|
const figureEndToken = new state.Token('figure_close', 'figure', -1);
|
|
148
160
|
const breakToken = new state.Token('text', '', 0);
|
|
149
161
|
breakToken.content = '\n';
|
|
150
|
-
if (sp) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
figureStartToken.attrJoin(attr[0], attr[1]);
|
|
154
|
-
}
|
|
162
|
+
if (opt.styleProcess && caption.hasNext && sp.attrs.length > 0) {
|
|
163
|
+
for (let attr of sp.attrs) {
|
|
164
|
+
figureStartToken.attrJoin(attr[0], attr[1]);
|
|
155
165
|
}
|
|
156
166
|
}
|
|
157
|
-
|
|
167
|
+
// For vsce
|
|
158
168
|
if(state.tokens[n].attrs) {
|
|
159
169
|
for (let attr of state.tokens[n].attrs) {
|
|
160
170
|
figureStartToken.attrJoin(attr[0], attr[1]);
|
|
@@ -204,7 +214,12 @@ const mditFigureWithPCaption = (md, option) => {
|
|
|
204
214
|
hasPrev: false,
|
|
205
215
|
hasNext: false,
|
|
206
216
|
};
|
|
207
|
-
|
|
217
|
+
const sp = {
|
|
218
|
+
attrs: [],
|
|
219
|
+
isVideoIframe: false,
|
|
220
|
+
isIframeTypeBlockQuote: false,
|
|
221
|
+
hasImgCaption: false,
|
|
222
|
+
}
|
|
208
223
|
|
|
209
224
|
const checkTags = ['table', 'pre', 'blockquote'];
|
|
210
225
|
let cti = 0;
|
|
@@ -227,7 +242,7 @@ const mditFigureWithPCaption = (md, option) => {
|
|
|
227
242
|
range.end = en;
|
|
228
243
|
caption = checkCaption(state, n, en, tagName, caption);
|
|
229
244
|
if (caption.hasPrev || caption.hasNext) {
|
|
230
|
-
range = wrapWithFigure(state, range, tagName, false);
|
|
245
|
+
range = wrapWithFigure(state, range, tagName, caption, false, sp);
|
|
231
246
|
break;
|
|
232
247
|
}
|
|
233
248
|
break;
|
|
@@ -236,14 +251,19 @@ const mditFigureWithPCaption = (md, option) => {
|
|
|
236
251
|
if(token.type === 'fence') {
|
|
237
252
|
if (token.tag === 'code' && token.block) {
|
|
238
253
|
checkToken = true;
|
|
239
|
-
|
|
240
|
-
|
|
254
|
+
let isSampInfo = false
|
|
255
|
+
if (token.info === 'samp' || token.info === 'shell' || token.info === 'console') {
|
|
241
256
|
token.tag = 'samp';
|
|
257
|
+
isSampInfo = true
|
|
258
|
+
}
|
|
259
|
+
if (isSampInfo) {
|
|
260
|
+
tagName = 'pre-samp';
|
|
261
|
+
} else {
|
|
262
|
+
tagName = 'pre-code';
|
|
242
263
|
}
|
|
243
|
-
tagName = 'pre-' + token.tag;
|
|
244
264
|
caption = checkCaption(state, n, en, tagName, caption);
|
|
245
265
|
if (caption.hasPrev || caption.hasNext) {
|
|
246
|
-
range = wrapWithFigure(state, range, tagName, false);
|
|
266
|
+
range = wrapWithFigure(state, range, tagName, caption, false, sp);
|
|
247
267
|
break;
|
|
248
268
|
}
|
|
249
269
|
}
|
|
@@ -256,64 +276,68 @@ const mditFigureWithPCaption = (md, option) => {
|
|
|
256
276
|
const tags = ['video', 'audio', 'iframe', 'blockquote'];
|
|
257
277
|
let ctj = 0;
|
|
258
278
|
while (ctj < tags.length) {
|
|
259
|
-
const hasTag = token.content.match(new RegExp('^<'+ tags[ctj] + ' ?[^>]*?>[\\s\\S]*?<\\/' + tags[ctj] + '> *?(
|
|
279
|
+
const hasTag = token.content.match(new RegExp('^<'+ tags[ctj] + ' ?[^>]*?>[\\s\\S]*?<\\/' + tags[ctj] + '>(\\n| *?)(<script [^>]*?>(?:<\\/script>)?)?(\\n|$)'));
|
|
260
280
|
if (!hasTag) {
|
|
261
281
|
ctj++;
|
|
262
282
|
continue;
|
|
263
283
|
}
|
|
264
|
-
|
|
284
|
+
//console.log(hasTag)
|
|
285
|
+
if ((hasTag[2] && hasTag[3] !== '\n') ||
|
|
286
|
+
(hasTag[1] !== '\n' && hasTag[2] === undefined)) {
|
|
265
287
|
token.content += '\n'
|
|
266
288
|
}
|
|
267
289
|
tagName = tags[ctj];
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
290
|
+
checkToken = true;
|
|
291
|
+
if (tagName === 'blockquote') {
|
|
292
|
+
//text-post-media: threads
|
|
293
|
+
if(/^<[^>]*? class="(?:twitter-tweet|instagram-media|text-post-media|bluesky-embed)"/.test(token.content)) {
|
|
294
|
+
sp.isIframeTypeBlockQuote = true
|
|
295
|
+
} else {
|
|
296
|
+
ctj++;
|
|
297
|
+
continue;
|
|
271
298
|
}
|
|
272
299
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
if (n + 2 < state.tokens.length) {
|
|
294
|
-
if (state.tokens[n+2].children.length > 1) {
|
|
295
|
-
if (state.tokens[n+2].children[1].attrs.length > 0) {
|
|
296
|
-
if (state.tokens[n+2].children[1].attrs[0][0] === 'class' &&
|
|
297
|
-
state.tokens[n+2].children[1].attrs[0][1] === 'f-img-label') {
|
|
298
|
-
sp.hasImgCaption = true;
|
|
299
|
-
}
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
302
|
+
if (!checkToken) {n++; continue;}
|
|
303
|
+
if (tagName === 'iframe') {
|
|
304
|
+
if(/^<[^>]*? src="https:\/\/(?:www.youtube-nocookie.com|player.vimeo.com)\//i.test(token.content)) {
|
|
305
|
+
sp.isVideoIframe = true
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
if(sp.isIframeTypeBlockQuote) {
|
|
309
|
+
if(n > 2) {
|
|
310
|
+
if (state.tokens[n-2].children.length > 1) {
|
|
311
|
+
if (state.tokens[n-2].children[1].attrs.length > 0) {
|
|
312
|
+
if (state.tokens[n-2].children[1].attrs[0][0] === 'class') {
|
|
313
|
+
if (state.tokens[n-2].children[1].attrs[0][1] === 'f-img-label') {
|
|
314
|
+
sp.hasImgCaption = true;
|
|
315
|
+
/* For now, I think I should use figure instead of blockquoe for caption. */
|
|
300
316
|
}
|
|
301
317
|
}
|
|
302
318
|
}
|
|
303
319
|
}
|
|
304
320
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
321
|
+
if (n + 2 < state.tokens.length) {
|
|
322
|
+
if (state.tokens[n+2].children.length > 1) {
|
|
323
|
+
if (state.tokens[n+2].children[1].attrs.length > 0) {
|
|
324
|
+
if (state.tokens[n+2].children[1].attrs[0][0] === 'class' &&
|
|
325
|
+
state.tokens[n+2].children[1].attrs[0][1] === 'f-img-label') {
|
|
326
|
+
sp.hasImgCaption = true;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
313
329
|
}
|
|
314
|
-
break;
|
|
315
330
|
}
|
|
316
|
-
|
|
331
|
+
}
|
|
332
|
+
caption = checkCaption(state, n, en, tagName, caption);
|
|
333
|
+
if (caption.hasPrev || caption.hasNext) {
|
|
334
|
+
range = wrapWithFigure(state, range, tagName, caption, false, sp);
|
|
335
|
+
n = en + 2;
|
|
336
|
+
} else if ((opt.iframeWithoutCaption && (tagName === 'iframe')) ||
|
|
337
|
+
(opt.videoWithoutCaption && (tagName === 'video')) ||
|
|
338
|
+
(opt.iframeTypeBlockquoteWithoutCaption && (tagName === 'blockquote'))) {
|
|
339
|
+
range = wrapWithFigure(state, range, tagName, caption, false, sp);
|
|
340
|
+
n = en + 2;
|
|
317
341
|
}
|
|
318
342
|
}
|
|
319
343
|
|
|
@@ -404,11 +428,7 @@ const mditFigureWithPCaption = (md, option) => {
|
|
|
404
428
|
}
|
|
405
429
|
if (checkToken && (opt.oneImageWithoutCaption || caption.hasPrev || caption.hasNext)) {
|
|
406
430
|
if (caption.nameSuffix) tagName += caption.nameSuffix
|
|
407
|
-
|
|
408
|
-
range = wrapWithFigure(state, range, tagName, true, sp);
|
|
409
|
-
} else {
|
|
410
|
-
range = wrapWithFigure(state, range, tagName, true);
|
|
411
|
-
}
|
|
431
|
+
range = wrapWithFigure(state, range, tagName, caption, true, sp)
|
|
412
432
|
}
|
|
413
433
|
}
|
|
414
434
|
|
|
@@ -433,41 +453,44 @@ const mditFigureWithPCaption = (md, option) => {
|
|
|
433
453
|
|
|
434
454
|
const setAltToLabel = (state, n, en, tagName, caption, opt) => {
|
|
435
455
|
if (n < 2) return false
|
|
436
|
-
if (state.tokens[n+1].children[0].type
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
}
|
|
443
|
-
state.tokens[n+1].children[0].content = state.tokens[n-2].children[2].content
|
|
444
|
-
state.tokens[n+1].children[0].children[0].content = state.tokens[n-2].children[2].content
|
|
456
|
+
if (state.tokens[n+1].children[0].type !== 'image' || !state.tokens[n-2].children) return false
|
|
457
|
+
if (state.tokens[n-2].children[2]) {
|
|
458
|
+
state.tokens[n+1].content = state.tokens[n+1].content.replace(/^!\[.*?\]/, '![' + state.tokens[n-2].children[2].content + ']')
|
|
459
|
+
if (!state.tokens[n+1].children[0].children[0]) {
|
|
460
|
+
const textToken = new state.Token('text', '', 0)
|
|
461
|
+
state.tokens[n+1].children[0].children.push(textToken)
|
|
445
462
|
}
|
|
463
|
+
// Set figure label:
|
|
464
|
+
//state.tokens[n+1].children[0].children[0].content = state.tokens[n-2].children[2].content
|
|
465
|
+
// Set img alt to empty value:
|
|
466
|
+
state.tokens[n+1].children[0].children[0].content = ''
|
|
446
467
|
}
|
|
468
|
+
// Set figure label:
|
|
469
|
+
//state.tokens[n+1].children[0].content = state.tokens[n-2].children[2].content
|
|
470
|
+
// Set img alt to empty value:
|
|
471
|
+
state.tokens[n+1].children[0].content = ''
|
|
447
472
|
//console.log(state.tokens[n+1].children[0])
|
|
448
473
|
return true
|
|
449
474
|
}
|
|
450
475
|
|
|
451
476
|
const setTitleToLabel = (state, n, en, tagName, caption, opt) => {
|
|
452
477
|
if (n < 2) return false
|
|
453
|
-
if (state.tokens[n+1].children[0].type
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
}
|
|
468
|
-
i++
|
|
469
|
-
}
|
|
478
|
+
if (state.tokens[n+1].children[0].type !== 'image') return false
|
|
479
|
+
if (!state.tokens[n-2].children[0]) return false
|
|
480
|
+
state.tokens[n+1].children[0].attrSet('alt', state.tokens[n+1].children[0].content)
|
|
481
|
+
if (!state.tokens[n+1].children[0].children[0]) {
|
|
482
|
+
const textToken = new state.Token('text', '', 0)
|
|
483
|
+
state.tokens[n+1].children[0].children.push(textToken)
|
|
484
|
+
}
|
|
485
|
+
let i = 0
|
|
486
|
+
while (0 < state.tokens[n+1].children[0].attrs.length) {
|
|
487
|
+
if (state.tokens[n+1].children[0].attrs[i][0] === 'title') {
|
|
488
|
+
state.tokens[n+1].children[0].attrs.splice(i, i + 1)
|
|
489
|
+
break
|
|
490
|
+
} else {
|
|
491
|
+
state.tokens[n+1].children[0].attrJoin('title', '')
|
|
470
492
|
}
|
|
493
|
+
i++
|
|
471
494
|
}
|
|
472
495
|
//console.log(state.tokens[n+1].children[0])
|
|
473
496
|
return true
|
|
@@ -481,6 +504,7 @@ const mditFigureWithPCaption = (md, option) => {
|
|
|
481
504
|
if (opt.imgAltCaption && typeof opt.imgAltCaption === 'string') label = opt.imgAltCaption
|
|
482
505
|
if (opt.imgTitleCaption && typeof opt.imgTitleCaption === 'string') label = opt.imgTitleCaption
|
|
483
506
|
let caption = ''
|
|
507
|
+
let imgAttrUsedCaption = ''
|
|
484
508
|
|
|
485
509
|
const img = inline.match(/^( *!\[)(.*?)\]\( *?((.*?)(?: +?\"(.*?)\")?) *?\)( *?\{.*?\})? *$/)
|
|
486
510
|
if (!img) return
|
|
@@ -489,41 +513,48 @@ const mditFigureWithPCaption = (md, option) => {
|
|
|
489
513
|
if (opt.imgAltCaption) {
|
|
490
514
|
caption = img[2]
|
|
491
515
|
hasLabel = img[2].match(new RegExp('^' + opt.imgAltCaption))
|
|
516
|
+
imgAttrUsedCaption = 'alt'
|
|
492
517
|
}
|
|
493
518
|
if (opt.imgTitleCaption) {
|
|
494
519
|
if (!img[5]) img[5] = ''
|
|
495
520
|
caption = img[5]
|
|
496
521
|
hasLabel = img[5].match(new RegExp('^' + opt.imgTitleCaption))
|
|
522
|
+
imgAttrUsedCaption = 'title'
|
|
497
523
|
}
|
|
498
524
|
let token
|
|
499
525
|
token = state.push('paragraph_open', 'p', 1)
|
|
500
526
|
token.map = [startLine, startLine + 1]
|
|
501
527
|
token = state.push('inline', '', 0)
|
|
502
|
-
|
|
503
528
|
if (hasLabel) {
|
|
504
529
|
token.content = caption
|
|
505
530
|
} else {
|
|
506
|
-
if (label) {
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
} else {
|
|
512
|
-
|
|
531
|
+
if (!label) {
|
|
532
|
+
if (imgAttrUsedCaption === 'alt') {
|
|
533
|
+
label = opt.imgAltCaption
|
|
534
|
+
} else if (imgAttrUsedCaption === 'title') {
|
|
535
|
+
label = opt.imgTitleCaption
|
|
536
|
+
} else if (imgAttrUsedCaption) {
|
|
537
|
+
label = 'Figure'
|
|
513
538
|
}
|
|
514
|
-
|
|
539
|
+
}
|
|
540
|
+
token.content = label
|
|
541
|
+
if (/[a-zA-Z]/.test(label)) {
|
|
542
|
+
token.content += '.'
|
|
543
|
+
if (caption) token.content += ' '
|
|
515
544
|
} else {
|
|
516
|
-
token.content
|
|
545
|
+
token.content += ' '
|
|
517
546
|
}
|
|
547
|
+
token.content += caption
|
|
518
548
|
}
|
|
519
|
-
//console.log('token.content: ' + token.content)
|
|
520
549
|
token.map = [startLine, startLine + 1]
|
|
521
550
|
token.children = []
|
|
551
|
+
if (caption.length === 0) {
|
|
552
|
+
token.attrs = [['class', 'nocaption']]
|
|
553
|
+
}
|
|
522
554
|
token = state.push('paragraph_close', 'p', -1)
|
|
523
555
|
return
|
|
524
556
|
}
|
|
525
557
|
|
|
526
|
-
|
|
527
558
|
if (opt.imgAltCaption || opt.imgTitleCaption) {
|
|
528
559
|
md.block.ruler.before('paragraph', 'img_attr_caption', imgAttrToPCaption)
|
|
529
560
|
}
|
|
@@ -539,18 +570,6 @@ const mditFigureWithPCaption = (md, option) => {
|
|
|
539
570
|
removeUnnumberedLabelExceptMarks: opt.removeUnnumberedLabelExceptMarks,
|
|
540
571
|
})
|
|
541
572
|
md.core.ruler.before('linkify', 'figure_with_caption', figureWithCaption);
|
|
542
|
-
|
|
543
|
-
const token = tokens[idx];
|
|
544
|
-
let sampStartTag = '<samp>';
|
|
545
|
-
if (token.attrs) {
|
|
546
|
-
sampStartTag = sampStartTag.replace('>', '');
|
|
547
|
-
for(let attr of token.attrs) {
|
|
548
|
-
sampStartTag += ' ' + attr[0] + '="' + attr[1] + '"';
|
|
549
|
-
}
|
|
550
|
-
sampStartTag += '>';
|
|
551
|
-
}
|
|
552
|
-
return '<pre>' + sampStartTag + md.utils.escapeHtml(token.content) + '</samp></pre>\n';
|
|
553
|
-
};
|
|
554
|
-
};
|
|
573
|
+
}
|
|
555
574
|
|
|
556
575
|
export default mditFigureWithPCaption
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peaceroad/markdown-it-figure-with-p-caption",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.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
|
"type": "module",
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
"url": "https://github.com/peaceroad/p7d-markdown-it-figure-with-p-caption/issues"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
+
"@peaceroad/markdown-it-renderer-fence": "^0.1.0",
|
|
18
|
+
"highlight.js": "^11.9.0",
|
|
17
19
|
"markdown-it": "^14.1.0",
|
|
18
20
|
"markdown-it-attrs": "^4.1.6"
|
|
19
21
|
},
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
[Markdown]
|
|
2
|
+
```js
|
|
3
|
+
import mdit from 'markdonw-it'
|
|
4
|
+
```
|
|
5
|
+
[HTML]
|
|
6
|
+
<pre><code class="language-js"><span class="hljs-keyword">import</span> mdit <span class="hljs-keyword">from</span> <span class="hljs-string">'markdonw-it'</span>
|
|
7
|
+
</code></pre>
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
[Markdown]
|
|
11
|
+
```html
|
|
12
|
+
<p>I draw <span class="style">cats</span>.</p>
|
|
13
|
+
```
|
|
14
|
+
[HTML]
|
|
15
|
+
<pre><code class="language-html"><span class="hljs-tag"><<span class="hljs-name">p</span>></span>I draw <span class="hljs-tag"><<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"style"</span>></span>cats<span class="hljs-tag"></<span class="hljs-name">span</span>></span>.<span class="hljs-tag"></<span class="hljs-name">p</span>></span>
|
|
16
|
+
</code></pre>
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
[Markdown]
|
|
20
|
+
```js
|
|
21
|
+
import mdit from 'markdonw-it'
|
|
22
|
+
const md = mdit()
|
|
23
|
+
md.render('Nyaan')
|
|
24
|
+
```
|
|
25
|
+
[HTML]
|
|
26
|
+
<pre><code class="language-js"><span class="hljs-keyword">import</span> mdit <span class="hljs-keyword">from</span> <span class="hljs-string">'markdonw-it'</span>
|
|
27
|
+
<span class="hljs-keyword">const</span> md = <span class="hljs-title function_">mdit</span>()
|
|
28
|
+
md.<span class="hljs-title function_">render</span>(<span class="hljs-string">'Nyaan'</span>)
|
|
29
|
+
</code></pre>
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
[Markdown]
|
|
33
|
+
```js {.style}
|
|
34
|
+
import mdit from 'markdonw-it'
|
|
35
|
+
const md = mdit()
|
|
36
|
+
md.render('Nyaan')
|
|
37
|
+
```
|
|
38
|
+
[HTML]
|
|
39
|
+
<pre><code class="language-js style"><span class="hljs-keyword">import</span> mdit <span class="hljs-keyword">from</span> <span class="hljs-string">'markdonw-it'</span>
|
|
40
|
+
<span class="hljs-keyword">const</span> md = <span class="hljs-title function_">mdit</span>()
|
|
41
|
+
md.<span class="hljs-title function_">render</span>(<span class="hljs-string">'Nyaan'</span>)
|
|
42
|
+
</code></pre>
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
[Markdown]
|
|
46
|
+
```html {start="2"}
|
|
47
|
+
<p>I draw <span class="style">cats</span>.</p>
|
|
48
|
+
```
|
|
49
|
+
[HTML]
|
|
50
|
+
<pre><code class="language-html" data-pre-start="2" style="counter-set:pre-line-number 2;"><span class="pre-line"><span class="hljs-tag"><<span class="hljs-name">p</span>></span>I draw <span class="hljs-tag"><<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"style"</span>></span>cats<span class="hljs-tag"></<span class="hljs-name">span</span>></span>.<span class="hljs-tag"></<span class="hljs-name">p</span>></span></span>
|
|
51
|
+
</code></pre>
|
|
52
|
+
|
|
53
|
+
[Markdown]
|
|
54
|
+
```js {start="1"}
|
|
55
|
+
import mdit from 'markdonw-it'
|
|
56
|
+
```
|
|
57
|
+
[HTML]
|
|
58
|
+
<pre><code class="language-js" data-pre-start="1" style="counter-set:pre-line-number 1;"><span class="pre-line"><span class="hljs-keyword">import</span> mdit <span class="hljs-keyword">from</span> <span class="hljs-string">'markdonw-it'</span></span>
|
|
59
|
+
</code></pre>
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
[Markdown]
|
|
63
|
+
```js {.style start="1"}
|
|
64
|
+
import mdit from 'markdonw-it'
|
|
65
|
+
const md = mdit()
|
|
66
|
+
md.render('Nyaan')
|
|
67
|
+
```
|
|
68
|
+
[HTML]
|
|
69
|
+
<pre><code class="language-js style" data-pre-start="1" style="counter-set:pre-line-number 1;"><span class="pre-line"><span class="hljs-keyword">import</span> mdit <span class="hljs-keyword">from</span> <span class="hljs-string">'markdonw-it'</span></span>
|
|
70
|
+
<span class="pre-line"><span class="hljs-keyword">const</span> md = <span class="hljs-title function_">mdit</span>()</span>
|
|
71
|
+
<span class="pre-line">md.<span class="hljs-title function_">render</span>(<span class="hljs-string">'Nyaan'</span>)</span>
|
|
72
|
+
</code></pre>
|
|
73
|
+
|
|
74
|
+
[Markdown]
|
|
75
|
+
```shell
|
|
76
|
+
$ pwd
|
|
77
|
+
/home/User
|
|
78
|
+
```
|
|
79
|
+
[HTML]
|
|
80
|
+
<pre><samp class="language-shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash"><span class="hljs-built_in">pwd</span></span>
|
|
81
|
+
/home/User
|
|
82
|
+
</samp></pre>
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
[Markdown]
|
|
86
|
+
```samp
|
|
87
|
+
$ pwd
|
|
88
|
+
/home/User
|
|
89
|
+
```
|
|
90
|
+
[HTML]
|
|
91
|
+
<pre><samp>$ pwd
|
|
92
|
+
/home/User
|
|
93
|
+
</samp></pre>
|
|
94
|
+
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
[Markdown]
|
|
2
|
+
A paragraph. iframeTypeBlockquoteWithoutCaption: true.
|
|
3
|
+
|
|
4
|
+
<blockquote class="twitter-tweet"><p lang="ja" dir="ltr">XXXXX <a href="https://t.co/XXXXX">https://t.co/XXXXX</a></p>— 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>
|
|
5
|
+
|
|
6
|
+
A paragraph.
|
|
7
|
+
[HTML]
|
|
8
|
+
<p>A paragraph. iframeTypeBlockquoteWithoutCaption: true.</p>
|
|
9
|
+
<figure class="f-iframe">
|
|
10
|
+
<blockquote class="twitter-tweet"><p lang="ja" dir="ltr">XXXXX <a href="https://t.co/XXXXX">https://t.co/XXXXX</a></p>— 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>
|
|
11
|
+
</figure>
|
|
12
|
+
<p>A paragraph.</p>
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
[Markdown]
|
|
16
|
+
<blockquote class="twitter-tweet"><p lang="ja" dir="ltr">XXXXX <a href="https://t.co/XXXXX">https://t.co/XXXXX</a></p>— 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>
|
|
17
|
+
[HTML]
|
|
18
|
+
<figure class="f-iframe">
|
|
19
|
+
<blockquote class="twitter-tweet"><p lang="ja" dir="ltr">XXXXX <a href="https://t.co/XXXXX">https://t.co/XXXXX</a></p>— 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>
|
|
20
|
+
</figure>
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
[Markdown]
|
|
25
|
+
<iframe src="https://mstdn.social/User/xxxxxxxx/embed" class="mastodon-embed" style="max-width: 100%; border: 0" width="400" allowfullscreen="allowfullscreen"></iframe><script src="https://mstdn.social/embed.js" async="async"></script>
|
|
26
|
+
[HTML]
|
|
27
|
+
<figure class="f-iframe">
|
|
28
|
+
<iframe src="https://mstdn.social/User/xxxxxxxx/embed" class="mastodon-embed" style="max-width: 100%; border: 0" width="400" allowfullscreen="allowfullscreen"></iframe><script src="https://mstdn.social/embed.js" async="async"></script>
|
|
29
|
+
</figure>
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
[Markdown]
|
|
33
|
+
<blockquote class="text-post-media" data-text-post-permalink="https://www.threads.net/User/post/xxxxxxxxxx" data-text-post-version="0" id="xxxxxx" style=" background:#FFF; border-width: 1px; border-style: solid; border-color: #00000026; border-radius: 16px; max-width:540px; margin: 1px; min-width:270px; padding:0; width:99.375%; width:-webkit-calc(100% - 2px); width:calc(100% - 2px);"> <a href="https://www.threads.net/User/post/xxxxxxxxxxxxx" style=" background:#FFFFFF; line-height:0; padding:0 0; text-align:center; text-decoration:none; width:100%; font-family: -apple-system, BlinkMacSystemFont, sans-serif;" target="_blank"> <div style=" padding: 40px; display: flex; flex-direction: column; align-items: center;"><div style=" display:block; height:32px; width:32px; padding-bottom:20px;"> <svg aria-label="Threads" height="32px" role="img" viewBox="0 0 192 192" width="32px" xmlns="http://www.w3.org/2000/svg"> <path /></svg></div> <div style=" font-size: 15px; line-height: 21px; color: #999999; font-weight: 400; padding-bottom: 4px; "> 投稿者: xxxxx</div> <div style=" font-size: 15px; line-height: 21px; color: #000000; font-weight: 600; "> Threadsで見る</div></div></a></blockquote>
|
|
34
|
+
<script async src="https://www.threads.net/embed.js"></script>
|
|
35
|
+
|
|
36
|
+
[HTML]
|
|
37
|
+
<figure class="f-iframe">
|
|
38
|
+
<blockquote class="text-post-media" data-text-post-permalink="https://www.threads.net/User/post/xxxxxxxxxx" data-text-post-version="0" id="xxxxxx" style=" background:#FFF; border-width: 1px; border-style: solid; border-color: #00000026; border-radius: 16px; max-width:540px; margin: 1px; min-width:270px; padding:0; width:99.375%; width:-webkit-calc(100% - 2px); width:calc(100% - 2px);"> <a href="https://www.threads.net/User/post/xxxxxxxxxxxxx" style=" background:#FFFFFF; line-height:0; padding:0 0; text-align:center; text-decoration:none; width:100%; font-family: -apple-system, BlinkMacSystemFont, sans-serif;" target="_blank"> <div style=" padding: 40px; display: flex; flex-direction: column; align-items: center;"><div style=" display:block; height:32px; width:32px; padding-bottom:20px;"> <svg aria-label="Threads" height="32px" role="img" viewBox="0 0 192 192" width="32px" xmlns="http://www.w3.org/2000/svg"> <path /></svg></div> <div style=" font-size: 15px; line-height: 21px; color: #999999; font-weight: 400; padding-bottom: 4px; "> 投稿者: xxxxx</div> <div style=" font-size: 15px; line-height: 21px; color: #000000; font-weight: 600; "> Threadsで見る</div></div></a></blockquote>
|
|
39
|
+
<script async src="https://www.threads.net/embed.js"></script>
|
|
40
|
+
</figure>
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
[Markdown]
|
|
44
|
+
<blockquote class="instagram-media" data-instgrm-captioned data-instgrm-permalink="https://www.instagram.com/p/xxxxxxxxxxxxxxxxxxx" data-instgrm-version="14" style=" background:#FFF; border:0; border-radius:3px; box-shadow:0 0 1px 0 rgba(0,0,0,0.5),0 1px 10px 0 rgba(0,0,0,0.15); margin: 1px; max-width:540px; min-width:326px; padding:0; width:99.375%; width:-webkit-calc(100% - 2px); width:calc(100% - 2px);"><div style="padding:16px;"> <a href="https://www.instagram.com/p/xxxxxxxxxxxxxxxxxxxxxxx" style=" background:#FFFFFF; line-height:0; padding:0 0; text-align:center; text-decoration:none; width:100%;" target="_blank"> <div style=" display: flex; flex-direction: row; align-items: center;"> <div style="background-color: #F4F4F4; border-radius: 50%; flex-grow: 0; height: 40px; margin-right: 14px; width: 40px;"></div> <div style="display: flex; flex-direction: column; flex-grow: 1; justify-content: center;"> <div style=" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; margin-bottom: 6px; width: 100px;"></div> <div style=" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; width: 60px;"></div></div></div><div style="padding: 19% 0;"></div> <div style="display:block; height:50px; margin:0 auto 12px; width:50px;"><svg width="50px" height="50px" viewBox="0 0 60 60" version="1.1" xmlns="https://www.w3.org/2000/svg" xmlns:xlink="https://www.w3.org/1999/xlink"><g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g><g><path></path></g></g></g></svg></div><div style="padding-top: 8px;"> <div style=" color:#3897f0; font-family:Arial,sans-serif; font-size:14px; font-style:normal; font-weight:550; line-height:18px;">この投稿をInstagramで見る</div></div><div style="padding: 12.5% 0;"></div> <div style="display: flex; flex-direction: row; margin-bottom: 14px; align-items: center;"><div> <div style="background-color: #F4F4F4; border-radius: 50%; height: 12.5px; width: 12.5px; transform: translateX(0px) translateY(7px);"></div> <div style="background-color: #F4F4F4; height: 12.5px; transform: rotate(-45deg) translateX(3px) translateY(1px); width: 12.5px; flex-grow: 0; margin-right: 14px; margin-left: 2px;"></div> <div style="background-color: #F4F4F4; border-radius: 50%; height: 12.5px; width: 12.5px; transform: translateX(9px) translateY(-18px);"></div></div><div style="margin-left: 8px;"> <div style=" background-color: #F4F4F4; border-radius: 50%; flex-grow: 0; height: 20px; width: 20px;"></div> <div style=" width: 0; height: 0; border-top: 2px solid transparent; border-left: 6px solid #f4f4f4; border-bottom: 2px solid transparent; transform: translateX(16px) translateY(-4px) rotate(30deg)"></div></div><div style="margin-left: auto;"> <div style=" width: 0px; border-top: 8px solid #F4F4F4; border-right: 8px solid transparent; transform: translateY(16px);"></div> <div style=" background-color: #F4F4F4; flex-grow: 0; height: 12px; width: 16px; transform: translateY(-4px);"></div> <div style=" width: 0; height: 0; border-top: 8px solid #F4F4F4; border-left: 8px solid transparent; transform: translateY(-4px) translateX(8px);"></div></div></div> <div style="display: flex; flex-direction: column; flex-grow: 1; justify-content: center; margin-bottom: 24px;"> <div style=" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; margin-bottom: 6px; width: 224px;"></div> <div style=" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; width: 144px;"></div></div></a><p style=" color:#c9c8cd; font-family:Arial,sans-serif; font-size:14px; line-height:17px; margin-bottom:0; margin-top:8px; overflow:hidden; padding:8px 0 7px; text-align:center; text-overflow:ellipsis; white-space:nowrap;"><a href="https://www.instagram.com/p/xxxxxxxxxxxxxx" style=" color:#c9c8cd; font-family:Arial,sans-serif; font-size:14px; font-style:normal; font-weight:normal; line-height:17px; text-decoration:none;" target="_blank">Ueserがシェアした投稿</a></p></div></blockquote>
|
|
45
|
+
<script async src="//www.instagram.com/embed.js"></script>
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
[HTML]
|
|
49
|
+
<figure class="f-iframe">
|
|
50
|
+
<blockquote class="instagram-media" data-instgrm-captioned data-instgrm-permalink="https://www.instagram.com/p/xxxxxxxxxxxxxxxxxxx" data-instgrm-version="14" style=" background:#FFF; border:0; border-radius:3px; box-shadow:0 0 1px 0 rgba(0,0,0,0.5),0 1px 10px 0 rgba(0,0,0,0.15); margin: 1px; max-width:540px; min-width:326px; padding:0; width:99.375%; width:-webkit-calc(100% - 2px); width:calc(100% - 2px);"><div style="padding:16px;"> <a href="https://www.instagram.com/p/xxxxxxxxxxxxxxxxxxxxxxx" style=" background:#FFFFFF; line-height:0; padding:0 0; text-align:center; text-decoration:none; width:100%;" target="_blank"> <div style=" display: flex; flex-direction: row; align-items: center;"> <div style="background-color: #F4F4F4; border-radius: 50%; flex-grow: 0; height: 40px; margin-right: 14px; width: 40px;"></div> <div style="display: flex; flex-direction: column; flex-grow: 1; justify-content: center;"> <div style=" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; margin-bottom: 6px; width: 100px;"></div> <div style=" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; width: 60px;"></div></div></div><div style="padding: 19% 0;"></div> <div style="display:block; height:50px; margin:0 auto 12px; width:50px;"><svg width="50px" height="50px" viewBox="0 0 60 60" version="1.1" xmlns="https://www.w3.org/2000/svg" xmlns:xlink="https://www.w3.org/1999/xlink"><g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g><g><path></path></g></g></g></svg></div><div style="padding-top: 8px;"> <div style=" color:#3897f0; font-family:Arial,sans-serif; font-size:14px; font-style:normal; font-weight:550; line-height:18px;">この投稿をInstagramで見る</div></div><div style="padding: 12.5% 0;"></div> <div style="display: flex; flex-direction: row; margin-bottom: 14px; align-items: center;"><div> <div style="background-color: #F4F4F4; border-radius: 50%; height: 12.5px; width: 12.5px; transform: translateX(0px) translateY(7px);"></div> <div style="background-color: #F4F4F4; height: 12.5px; transform: rotate(-45deg) translateX(3px) translateY(1px); width: 12.5px; flex-grow: 0; margin-right: 14px; margin-left: 2px;"></div> <div style="background-color: #F4F4F4; border-radius: 50%; height: 12.5px; width: 12.5px; transform: translateX(9px) translateY(-18px);"></div></div><div style="margin-left: 8px;"> <div style=" background-color: #F4F4F4; border-radius: 50%; flex-grow: 0; height: 20px; width: 20px;"></div> <div style=" width: 0; height: 0; border-top: 2px solid transparent; border-left: 6px solid #f4f4f4; border-bottom: 2px solid transparent; transform: translateX(16px) translateY(-4px) rotate(30deg)"></div></div><div style="margin-left: auto;"> <div style=" width: 0px; border-top: 8px solid #F4F4F4; border-right: 8px solid transparent; transform: translateY(16px);"></div> <div style=" background-color: #F4F4F4; flex-grow: 0; height: 12px; width: 16px; transform: translateY(-4px);"></div> <div style=" width: 0; height: 0; border-top: 8px solid #F4F4F4; border-left: 8px solid transparent; transform: translateY(-4px) translateX(8px);"></div></div></div> <div style="display: flex; flex-direction: column; flex-grow: 1; justify-content: center; margin-bottom: 24px;"> <div style=" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; margin-bottom: 6px; width: 224px;"></div> <div style=" background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; width: 144px;"></div></div></a><p style=" color:#c9c8cd; font-family:Arial,sans-serif; font-size:14px; line-height:17px; margin-bottom:0; margin-top:8px; overflow:hidden; padding:8px 0 7px; text-align:center; text-overflow:ellipsis; white-space:nowrap;"><a href="https://www.instagram.com/p/xxxxxxxxxxxxxx" style=" color:#c9c8cd; font-family:Arial,sans-serif; font-size:14px; font-style:normal; font-weight:normal; line-height:17px; text-decoration:none;" target="_blank">Ueserがシェアした投稿</a></p></div></blockquote>
|
|
51
|
+
<script async src="//www.instagram.com/embed.js"></script>
|
|
52
|
+
</figure>
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
[Markdown]
|
|
56
|
+
<blockquote class="bluesky-embed" data-bluesky-uri="at://did:plc:xxxxxxxxxz/app.bsky.feed.post/xxxxxxxxxxxxxxxxxx" data-bluesky-cid="xxxxxxxxxxxxxxxxxxxxxxxxxx"><p lang="ja">.....<br><br><a href="https://bsky.app/profile/did:plc:xxxxxxxxxxx/post/xxxxxxxxxxxxxx?ref_src=embed">[image or embed]</a></p>— user (<a href="https://bsky.app/profile/did:plc:xxxxxxxxxx?ref_src=embed">user</a>) <a href="https://bsky.app/profile/did:plc:xxxxxxxxxxxx/post/xxxxxxxxxxxx?ref_src=embed">Jun 7, 2024 at 9:49</a></blockquote><script async src="https://embed.bsky.app/static/embed.js" charset="utf-8"></script>
|
|
57
|
+
|
|
58
|
+
[HTML]
|
|
59
|
+
<figure class="f-iframe">
|
|
60
|
+
<blockquote class="bluesky-embed" data-bluesky-uri="at://did:plc:xxxxxxxxxz/app.bsky.feed.post/xxxxxxxxxxxxxxxxxx" data-bluesky-cid="xxxxxxxxxxxxxxxxxxxxxxxxxx"><p lang="ja">.....<br><br><a href="https://bsky.app/profile/did:plc:xxxxxxxxxxx/post/xxxxxxxxxxxxxx?ref_src=embed">[image or embed]</a></p>— user (<a href="https://bsky.app/profile/did:plc:xxxxxxxxxx?ref_src=embed">user</a>) <a href="https://bsky.app/profile/did:plc:xxxxxxxxxxxx/post/xxxxxxxxxxxx?ref_src=embed">Jun 7, 2024 at 9:49</a></blockquote><script async src="https://embed.bsky.app/static/embed.js" charset="utf-8"></script>
|
|
61
|
+
</figure>
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
[Markdown]
|
|
2
|
-
A paragraph.
|
|
2
|
+
A YouTube paragraph.
|
|
3
3
|
|
|
4
4
|
<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>
|
|
5
5
|
|
|
6
6
|
A paragraph.
|
|
7
7
|
[HTML]
|
|
8
|
-
<p>A paragraph.</p>
|
|
8
|
+
<p>A YouTube paragraph.</p>
|
|
9
9
|
<figure class="f-video">
|
|
10
10
|
<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>
|
|
11
11
|
</figure>
|
|
@@ -53,7 +53,8 @@ Slide. A caption.
|
|
|
53
53
|
[HTML]
|
|
54
54
|
<figure class="f-video">
|
|
55
55
|
<iframe src="https://player.vimeo.com/video/xxxxxxxxxxxxxxx" width="640" height="360" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>
|
|
56
|
-
<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
|
|
56
|
+
<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>
|
|
57
|
+
</figure>
|
|
57
58
|
|
|
58
59
|
[Markdown]
|
|
59
60
|
<iframe src="https://player.vimeo.com/video/xxxxxxxxxxxxxxx" width="640" height="360" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>
|
|
@@ -62,25 +63,3 @@ Slide. A caption.
|
|
|
62
63
|
<iframe src="https://player.vimeo.com/video/xxxxxxxxxxxxxxx" width="640" height="360" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>
|
|
63
64
|
</figure>
|
|
64
65
|
|
|
65
|
-
[Markdown]
|
|
66
|
-
A paragraph. iframeWithoutCaption: true.
|
|
67
|
-
|
|
68
|
-
<blockquote class="twitter-tweet"><p lang="ja" dir="ltr">XXXXX <a href="https://t.co/XXXXX">https://t.co/XXXXX</a></p>— 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>
|
|
69
|
-
|
|
70
|
-
A paragraph.
|
|
71
|
-
[HTML]
|
|
72
|
-
<p>A paragraph. iframeWithoutCaption: true.</p>
|
|
73
|
-
<figure class="f-iframe">
|
|
74
|
-
<blockquote class="twitter-tweet"><p lang="ja" dir="ltr">XXXXX <a href="https://t.co/XXXXX">https://t.co/XXXXX</a></p>— 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>
|
|
75
|
-
</figure>
|
|
76
|
-
<p>A paragraph.</p>
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
[Markdown]
|
|
80
|
-
<blockquote class="twitter-tweet"><p lang="ja" dir="ltr">XXXXX <a href="https://t.co/XXXXX">https://t.co/XXXXX</a></p>— 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>
|
|
81
|
-
[HTML]
|
|
82
|
-
<figure class="f-iframe">
|
|
83
|
-
<blockquote class="twitter-tweet"><p lang="ja" dir="ltr">XXXXX <a href="https://t.co/XXXXX">https://t.co/XXXXX</a></p>— 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>
|
|
84
|
-
</figure>
|
|
85
|
-
|
|
86
|
-
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[HTML]
|
|
5
5
|
<figure class="f-img">
|
|
6
6
|
<figcaption><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> A caption.</figcaption>
|
|
7
|
-
<img src="cat.jpg" alt="
|
|
7
|
+
<img src="cat.jpg" alt="">
|
|
8
8
|
</figure>
|
|
9
9
|
|
|
10
10
|
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
[HTML]
|
|
15
15
|
<figure class="f-img">
|
|
16
16
|
<figcaption><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> A caption.</figcaption>
|
|
17
|
-
<img src="cat.jpg" alt="
|
|
17
|
+
<img src="cat.jpg" alt="">
|
|
18
18
|
</figure>
|
|
19
19
|
|
|
20
20
|
|
|
@@ -23,8 +23,7 @@
|
|
|
23
23
|
|
|
24
24
|
[HTML]
|
|
25
25
|
<figure class="f-img">
|
|
26
|
-
<
|
|
27
|
-
<img src="cat.jpg" alt="Figure">
|
|
26
|
+
<img src="cat.jpg" alt="">
|
|
28
27
|
</figure>
|
|
29
28
|
|
|
30
29
|
|
|
@@ -36,8 +35,7 @@ Figure. A caption.
|
|
|
36
35
|
[HTML]
|
|
37
36
|
<p class="f-img"><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> A caption.</p>
|
|
38
37
|
<figure class="f-img">
|
|
39
|
-
<
|
|
40
|
-
<img src="cat.jpg" alt="Figure">
|
|
38
|
+
<img src="cat.jpg" alt="">
|
|
41
39
|
</figure>
|
|
42
40
|
|
|
43
41
|
|
|
@@ -47,7 +45,7 @@ Figure. A caption.
|
|
|
47
45
|
[HTML]
|
|
48
46
|
<figure class="f-img">
|
|
49
47
|
<figcaption><span class="f-img-label">Figure 12<span class="f-img-label-joint">.</span></span> A caption.</figcaption>
|
|
50
|
-
<img src="cat.jpg" alt="
|
|
48
|
+
<img src="cat.jpg" alt="">
|
|
51
49
|
</figure>
|
|
52
50
|
|
|
53
51
|
|
|
@@ -57,7 +55,7 @@ Figure. A caption.
|
|
|
57
55
|
[HTML]
|
|
58
56
|
<figure class="f-img">
|
|
59
57
|
<figcaption><span class="f-img-label">図1<span class="f-img-label-joint"> </span></span>キャプション</figcaption>
|
|
60
|
-
<img src="cat.jpg" alt="
|
|
58
|
+
<img src="cat.jpg" alt="">
|
|
61
59
|
</figure>
|
|
62
60
|
|
|
63
61
|
|
|
@@ -70,7 +68,22 @@ Figure. A caption.
|
|
|
70
68
|
<p class="f-img"><span class="f-img-label">図</span> キャプション</p>
|
|
71
69
|
<figure class="f-img">
|
|
72
70
|
<figcaption><span class="f-img-label">図1<span class="f-img-label-joint"> </span></span>キャプション</figcaption>
|
|
73
|
-
<img src="cat.jpg" alt="
|
|
71
|
+
<img src="cat.jpg" alt="">
|
|
74
72
|
</figure>
|
|
75
73
|
|
|
76
74
|
|
|
75
|
+
[Markdown]
|
|
76
|
+

|
|
77
|
+
|
|
78
|
+

|
|
79
|
+
|
|
80
|
+
[HTML]
|
|
81
|
+
<figure class="f-img">
|
|
82
|
+
<figcaption><span class="f-img-label">図<span class="f-img-label-joint"> </span></span>A caption.</figcaption>
|
|
83
|
+
<img src="cat.jpg" alt="">
|
|
84
|
+
</figure>
|
|
85
|
+
<figure class="f-img">
|
|
86
|
+
<figcaption><span class="f-img-label">図</span> A caption.</figcaption>
|
|
87
|
+
<img src="cat.jpg" alt="">
|
|
88
|
+
</figure>
|
|
89
|
+
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
|
|
24
24
|
[HTML]
|
|
25
25
|
<figure class="f-img">
|
|
26
|
-
<figcaption><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span></figcaption>
|
|
27
26
|
<img src="cat.jpg" alt="A alt text.">
|
|
28
27
|
</figure>
|
|
29
28
|
|
|
@@ -45,7 +44,6 @@ Figure. A caption.
|
|
|
45
44
|
[HTML]
|
|
46
45
|
<p class="f-img"><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> A caption.</p>
|
|
47
46
|
<figure class="f-img">
|
|
48
|
-
<figcaption><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span></figcaption>
|
|
49
47
|
<img src="cat.jpg" alt="">
|
|
50
48
|
</figure>
|
|
51
49
|
|
|
@@ -611,6 +611,16 @@ Figure. A Caption.
|
|
|
611
611
|
<img src="cat.jpg" alt="Figure">
|
|
612
612
|
</figure>
|
|
613
613
|
|
|
614
|
+
[Markdown]
|
|
615
|
+
Figure. A Caption.
|
|
616
|
+
|
|
617
|
+
 {.style #id}
|
|
618
|
+
[HTML]
|
|
619
|
+
<figure class="f-img style" id="id">
|
|
620
|
+
<figcaption><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> A Caption.</figcaption>
|
|
621
|
+
<img src="cat.jpg" alt="Figure">
|
|
622
|
+
</figure>
|
|
623
|
+
|
|
614
624
|
|
|
615
625
|
[Markdown]
|
|
616
626
|
 {.style}
|
|
@@ -631,7 +641,6 @@ Figure. A Caption.
|
|
|
631
641
|
<p class="style"><img src="cat.jpg" alt="Figure"> Text</p>
|
|
632
642
|
|
|
633
643
|
|
|
634
|
-
|
|
635
644
|
[Markdown]
|
|
636
645
|
Slide. A caption.
|
|
637
646
|
|
package/test/test.js
CHANGED
|
@@ -2,9 +2,11 @@ import assert from 'assert'
|
|
|
2
2
|
import fs from 'fs'
|
|
3
3
|
import path from 'path'
|
|
4
4
|
import mdit from 'markdown-it'
|
|
5
|
+
import mditAttrs from 'markdown-it-attrs'
|
|
6
|
+
import mditRndererFence from '@peaceroad/markdown-it-renderer-fence'
|
|
5
7
|
|
|
6
8
|
import mdFigureWithPCaption from '../index.js'
|
|
7
|
-
import
|
|
9
|
+
import highlightjs from 'highlight.js'
|
|
8
10
|
|
|
9
11
|
let opt = {
|
|
10
12
|
dquoteFilename: true,
|
|
@@ -13,26 +15,44 @@ let opt = {
|
|
|
13
15
|
iframeWithoutCaption: false,
|
|
14
16
|
videoWithoutCaption: false,
|
|
15
17
|
hasNumClass: false,
|
|
18
|
+
iframeTypeBlockquoteWithoutCaption: false,
|
|
16
19
|
}
|
|
17
20
|
|
|
18
|
-
const md = mdit({ html: true }).use(mdFigureWithPCaption, opt).use(
|
|
21
|
+
const md = mdit({ html: true }).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
|
|
19
22
|
|
|
20
23
|
opt.hasNumClass = true
|
|
21
|
-
const mdHasNumClass = mdit({ html: true }).use(mdFigureWithPCaption, opt).use(
|
|
24
|
+
const mdHasNumClass = mdit({ html: true }).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
|
|
22
25
|
|
|
23
26
|
opt.hasNumClass = false
|
|
24
27
|
opt.oneImageWithoutCaption = true
|
|
25
|
-
const mdOneImage = mdit({ html: true }).use(mdFigureWithPCaption, opt).use(
|
|
28
|
+
const mdOneImage = mdit({ html: true }).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
|
|
26
29
|
|
|
27
30
|
opt.iframeWithoutCaption = true
|
|
28
31
|
opt.hasNumClass = false
|
|
29
|
-
const mdIframeWithoutCaption = mdit({ html: true }).use(mdFigureWithPCaption, opt).use(
|
|
32
|
+
const mdIframeWithoutCaption = mdit({ html: true }).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
|
|
33
|
+
|
|
34
|
+
opt.iframeTypeBlockquoteWithoutCaption = true
|
|
35
|
+
const mdIframeTypeBlockquoteWithoutCaption = mdit({ html: true }).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
|
|
30
36
|
|
|
31
37
|
opt.multipleImages = true
|
|
32
|
-
const mdMultipleImages = mdit({ html: true }).use(mdFigureWithPCaption, opt).use(
|
|
38
|
+
const mdMultipleImages = mdit({ html: true }).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
|
|
33
39
|
|
|
34
40
|
opt.videoWithoutCaption = true
|
|
35
|
-
const mdVideoWithoutCaption = mdit({ html: true }).use(mdFigureWithPCaption, opt).use(
|
|
41
|
+
const mdVideoWithoutCaption = mdit({ html: true }).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
|
|
42
|
+
|
|
43
|
+
const mdConsole = mdit({
|
|
44
|
+
html: true,
|
|
45
|
+
langPrefix: 'language-',
|
|
46
|
+
typographer: false,
|
|
47
|
+
highlight: (str, lang) => {
|
|
48
|
+
if (lang && highlightjs.getLanguage(lang)) {
|
|
49
|
+
try {
|
|
50
|
+
return highlightjs.highlight(str, { language: lang }).value
|
|
51
|
+
} catch (__) {}
|
|
52
|
+
}
|
|
53
|
+
return ''
|
|
54
|
+
}
|
|
55
|
+
}).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
|
|
36
56
|
|
|
37
57
|
|
|
38
58
|
let __dirname = path.dirname(new URL(import.meta.url).pathname)
|
|
@@ -47,11 +67,13 @@ const testData = {
|
|
|
47
67
|
hasNumClass: __dirname + path.sep + 'examples-has-num-class.txt',
|
|
48
68
|
oneImageWithoutCaption: __dirname + path.sep + 'examples-one-image-without-caption.txt',
|
|
49
69
|
iframeWithoutCaption: __dirname + path.sep + 'examples-iframe-without-caption.txt',
|
|
70
|
+
iframeTypeBlockquoteWithoutCaption: __dirname + path.sep + 'examples-iframe-type-blockquote-without-caption.txt',
|
|
50
71
|
multipleImages: __dirname + path.sep + 'examples-multiple-images.txt',
|
|
51
72
|
videoWithoutCaption: __dirname + path.sep + 'examples-video-without-caption.txt',
|
|
52
73
|
mdAllOption: __dirname + path.sep + 'examples-all-option.txt',
|
|
53
74
|
imgAltCaption: __dirname + path.sep + 'examples-img-alt-caption.txt',
|
|
54
75
|
imgTitleCaption: __dirname + path.sep + 'examples-img-title-caption.txt',
|
|
76
|
+
console: __dirname + path.sep + 'examples-console.txt',
|
|
55
77
|
}
|
|
56
78
|
|
|
57
79
|
const getTestData = (pat) => {
|
|
@@ -133,26 +155,28 @@ pass = runTest(md, testData.noOption, pass)
|
|
|
133
155
|
pass = runTest(mdHasNumClass, testData.hasNumClass, pass)
|
|
134
156
|
pass = runTest(mdOneImage, testData.oneImageWithoutCaption, pass)
|
|
135
157
|
pass = runTest(mdIframeWithoutCaption, testData.iframeWithoutCaption, pass)
|
|
158
|
+
pass = runTest(mdIframeTypeBlockquoteWithoutCaption, testData.iframeTypeBlockquoteWithoutCaption, pass)
|
|
136
159
|
pass = runTest(mdMultipleImages, testData.multipleImages, pass)
|
|
137
160
|
pass = runTest(mdVideoWithoutCaption, testData.videoWithoutCaption, pass)
|
|
161
|
+
pass = runTest(mdConsole, testData.console, pass)
|
|
138
162
|
|
|
139
163
|
|
|
140
164
|
opt.oneImageWithoutCaption = false
|
|
141
165
|
|
|
142
166
|
opt.imgAltCaption = 'Figure'
|
|
143
|
-
const mdImgAltCaption = mdit({html: true}).use(mdFigureWithPCaption, opt).use(
|
|
167
|
+
const mdImgAltCaption = mdit({html: true}).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
|
|
144
168
|
pass = runTest(mdImgAltCaption, testData.imgAltCaption, pass, [1, 5])
|
|
145
169
|
opt.imgAltCaption = '図'
|
|
146
|
-
const mdImgAltCaptionJa = mdit({html: true}).use(mdFigureWithPCaption, opt).use(
|
|
170
|
+
const mdImgAltCaptionJa = mdit({html: true}).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
|
|
147
171
|
pass = runTest(mdImgAltCaptionJa, testData.imgAltCaption, pass, [6 , 99])
|
|
148
172
|
|
|
149
173
|
opt.imgAltCaption = false
|
|
150
174
|
|
|
151
175
|
opt.imgTitleCaption = 'Figure'
|
|
152
|
-
const mdImgTitleCaption = mdit({html: true}).use(mdFigureWithPCaption, opt).use(
|
|
176
|
+
const mdImgTitleCaption = mdit({html: true}).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
|
|
153
177
|
pass = runTest(mdImgTitleCaption, testData.imgTitleCaption, pass, [1, 6])
|
|
154
178
|
opt.imgTitleCaption = '図'
|
|
155
|
-
const mdImgTitleCaptionJa = mdit({html: true}).use(mdFigureWithPCaption, opt).use(
|
|
179
|
+
const mdImgTitleCaptionJa = mdit({html: true}).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
|
|
156
180
|
pass = runTest(mdImgTitleCaptionJa, testData.imgTitleCaption, pass, [7, 99])
|
|
157
181
|
|
|
158
182
|
if (pass) console.log('Passed all test.')
|