@peaceroad/markdown-it-figure-with-p-caption 0.3.1 → 0.3.2
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 +64 -0
- package/index.js +11 -3
- package/package.json +2 -2
- package/test/examples.txt +41 -0
- package/test/test.js +4 -1
package/README.md
CHANGED
|
@@ -158,3 +158,67 @@ A paragraph.
|
|
|
158
158
|
</figure>
|
|
159
159
|
<p>A paragraph.</p>
|
|
160
160
|
~~~
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
## Option: Specify file name
|
|
164
|
+
|
|
165
|
+
Specify the file name before writing the caption.
|
|
166
|
+
Note that a space is required between the file name and caption.
|
|
167
|
+
|
|
168
|
+
### Use double quote
|
|
169
|
+
|
|
170
|
+
```js
|
|
171
|
+
|
|
172
|
+
md.use(mdFigureWithPCaption, {dquoteFilename: true});
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
~~~
|
|
176
|
+
[Markdown]
|
|
177
|
+
A paragraph.
|
|
178
|
+
|
|
179
|
+
Code. "filename.js" Call a cat.
|
|
180
|
+
|
|
181
|
+
```js
|
|
182
|
+
console.log('Nyaan!');
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
A paragraph.
|
|
186
|
+
|
|
187
|
+
[HTML]
|
|
188
|
+
<p>A paragraph.</p>
|
|
189
|
+
<figure class="f-pre-code" role="doc-example">
|
|
190
|
+
<figcaption><span class="f-pre-code-label">Code<span class="f-pre-code-label-joint">.</span></span> <strong class="f-pre-code-filename">filename.js</strong> Call a cat.</figcaption>
|
|
191
|
+
<pre><code class="language-js">console.log('Nyaan!');
|
|
192
|
+
</code></pre>
|
|
193
|
+
</figure>
|
|
194
|
+
<p>A paragraph.</p>
|
|
195
|
+
~~~
|
|
196
|
+
|
|
197
|
+
### Use strong mark
|
|
198
|
+
|
|
199
|
+
```js
|
|
200
|
+
md.use(mdFigureWithPCaption, {strongFilename: true});
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
~~~
|
|
204
|
+
|
|
205
|
+
[Markdown]
|
|
206
|
+
A paragraph.
|
|
207
|
+
|
|
208
|
+
Code. **filename.js** Call a cat.
|
|
209
|
+
|
|
210
|
+
```js
|
|
211
|
+
console.log('Nyaan!');
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
A paragraph.
|
|
215
|
+
|
|
216
|
+
[HTML]
|
|
217
|
+
<p>A paragraph.</p>
|
|
218
|
+
<figure class="f-pre-code" role="doc-example">
|
|
219
|
+
<figcaption><span class="f-pre-code-label">Code<span class="f-pre-code-label-joint">.</span></span> <strong class="f-pre-code-filename">filename.js</strong> Call a cat.</figcaption>
|
|
220
|
+
<pre><code class="language-js">console.log('Nyaan!');
|
|
221
|
+
</code></pre>
|
|
222
|
+
</figure>
|
|
223
|
+
<p>A paragraph.</p>
|
|
224
|
+
~~~
|
package/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const { has } = require('markdown-it/lib/common/utils');
|
|
4
|
+
|
|
3
5
|
module.exports = function figure_with_caption_plugin(md, option) {
|
|
4
6
|
|
|
5
7
|
const mdPCaption = require('p7d-markdown-it-p-captions');
|
|
@@ -7,6 +9,8 @@ module.exports = function figure_with_caption_plugin(md, option) {
|
|
|
7
9
|
let opt = {
|
|
8
10
|
classPrefix: 'f',
|
|
9
11
|
scaleSuffix: false,
|
|
12
|
+
dquoteFilename: false,
|
|
13
|
+
strongFilename: false,
|
|
10
14
|
};
|
|
11
15
|
if (option !== undefined) {
|
|
12
16
|
for (let o in option) {
|
|
@@ -215,7 +219,7 @@ module.exports = function figure_with_caption_plugin(md, option) {
|
|
|
215
219
|
const tags = ['video', 'audio', 'iframe'];
|
|
216
220
|
let ctj = 0;
|
|
217
221
|
while (ctj < tags.length) {
|
|
218
|
-
const hasTag = token.content.match(new RegExp('^<'+ tags[ctj] + ' ?[^>]*?>[\\s\\S]*?<\\/' + tags[ctj] + '>\\n'))
|
|
222
|
+
const hasTag = token.content.match(new RegExp('^<'+ tags[ctj] + ' ?[^>]*?>[\\s\\S]*?<\\/' + tags[ctj] + '>\\n'));
|
|
219
223
|
if (!hasTag) {
|
|
220
224
|
ctj++;
|
|
221
225
|
continue;
|
|
@@ -232,8 +236,8 @@ module.exports = function figure_with_caption_plugin(md, option) {
|
|
|
232
236
|
range = wrapWithFigure(state, range, tagName, false);
|
|
233
237
|
break;
|
|
234
238
|
}
|
|
239
|
+
ctj++
|
|
235
240
|
}
|
|
236
|
-
ctj++
|
|
237
241
|
}
|
|
238
242
|
|
|
239
243
|
if (token.type === 'paragraph_open'
|
|
@@ -271,7 +275,11 @@ module.exports = function figure_with_caption_plugin(md, option) {
|
|
|
271
275
|
return;
|
|
272
276
|
}
|
|
273
277
|
|
|
274
|
-
md.use(mdPCaption, {
|
|
278
|
+
md.use(mdPCaption, {
|
|
279
|
+
classPrefix: opt.classPrefix,
|
|
280
|
+
dquoteFilename: opt.dquoteFilename,
|
|
281
|
+
strongFilename: opt.strongFilename,
|
|
282
|
+
});
|
|
275
283
|
md.core.ruler.before('linkify', 'figure_with_caption', figureWithCaption);
|
|
276
284
|
md.renderer.rules['fence_samp'] = function (tokens, idx, options, env, slf) {
|
|
277
285
|
const token = tokens[idx];
|
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
|
+
"version": "0.3.2",
|
|
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": {
|
|
@@ -16,6 +16,6 @@
|
|
|
16
16
|
"markdown-it": "^12.1.0"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"p7d-markdown-it-p-captions": "^0.
|
|
19
|
+
"p7d-markdown-it-p-captions": "^0.6.2"
|
|
20
20
|
}
|
|
21
21
|
}
|
package/test/examples.txt
CHANGED
|
@@ -408,3 +408,44 @@ A paragraph.
|
|
|
408
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
409
|
</figure>
|
|
410
410
|
<p>A paragraph.</p>
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
[Markdown]
|
|
414
|
+
A paragraph.
|
|
415
|
+
|
|
416
|
+
Code. "filename.js" Call a cat.
|
|
417
|
+
|
|
418
|
+
```js
|
|
419
|
+
console.log('Nyaan!');
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
A paragraph.
|
|
423
|
+
|
|
424
|
+
[HTML]
|
|
425
|
+
<p>A paragraph.</p>
|
|
426
|
+
<figure class="f-pre-code" role="doc-example">
|
|
427
|
+
<figcaption><span class="f-pre-code-label">Code<span class="f-pre-code-label-joint">.</span></span> <strong class="f-pre-code-filename">filename.js</strong> Call a cat.</figcaption>
|
|
428
|
+
<pre><code class="language-js">console.log('Nyaan!');
|
|
429
|
+
</code></pre>
|
|
430
|
+
</figure>
|
|
431
|
+
<p>A paragraph.</p>
|
|
432
|
+
|
|
433
|
+
[Markdown]
|
|
434
|
+
A paragraph.
|
|
435
|
+
|
|
436
|
+
Code. **filename.js** Call a cat.
|
|
437
|
+
|
|
438
|
+
```js
|
|
439
|
+
console.log('Nyaan!');
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
A paragraph.
|
|
443
|
+
|
|
444
|
+
[HTML]
|
|
445
|
+
<p>A paragraph.</p>
|
|
446
|
+
<figure class="f-pre-code" role="doc-example">
|
|
447
|
+
<figcaption><span class="f-pre-code-label">Code<span class="f-pre-code-label-joint">.</span></span> <strong class="f-pre-code-filename">filename.js</strong> Call a cat.</figcaption>
|
|
448
|
+
<pre><code class="language-js">console.log('Nyaan!');
|
|
449
|
+
</code></pre>
|
|
450
|
+
</figure>
|
|
451
|
+
<p>A paragraph.</p>
|
package/test/test.js
CHANGED
|
@@ -5,7 +5,10 @@ const md = require('markdown-it')({
|
|
|
5
5
|
});
|
|
6
6
|
const mdFigureWithPCaption = require('../index.js');
|
|
7
7
|
|
|
8
|
-
md.use(mdFigureWithPCaption
|
|
8
|
+
md.use(mdFigureWithPCaption, {
|
|
9
|
+
dquoteFilename: true,
|
|
10
|
+
strongFilename: true,
|
|
11
|
+
});
|
|
9
12
|
|
|
10
13
|
const example = __dirname + '/examples.txt';
|
|
11
14
|
const mdPath = __dirname + '/examples.md';
|