@peaceroad/markdown-it-figure-with-p-caption 0.5.3 → 0.6.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 +54 -9
- package/index.js +111 -8
- package/package.json +3 -2
- package/test/examples-has-num-class.txt +31 -0
- package/test/examples-iframe-without-caption.txt +86 -0
- package/test/examples-img-alt-caption.txt +76 -0
- package/test/examples-img-title-caption.txt +92 -0
- package/test/examples-multiple-images.txt +140 -0
- package/test/{examples.txt → examples-no-option.txt} +3 -288
- package/test/examples-one-image-without-caption.txt +45 -0
- package/test/examples-video-without-caption.txt +11 -0
- package/test/test.js +133 -64
package/test/test.js
CHANGED
|
@@ -1,89 +1,158 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const mdWithoutCaption = require('markdown-it')({ html: true });
|
|
6
|
-
const mdMultipleImages = require('markdown-it')({ html: true });
|
|
7
|
-
const mdAllOptionTrue = require('markdown-it')({ html: true });
|
|
1
|
+
import assert from 'assert'
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
import path from 'path'
|
|
4
|
+
import mdit from 'markdown-it'
|
|
8
5
|
|
|
9
|
-
|
|
6
|
+
import mdFigureWithPCaption from '../index.js'
|
|
7
|
+
import attrs from 'markdown-it-attrs'
|
|
10
8
|
|
|
11
|
-
const attrs = require('../node_modules/markdown-it-attrs');
|
|
12
9
|
let opt = {
|
|
13
10
|
dquoteFilename: true,
|
|
14
11
|
strongFilename: true,
|
|
15
12
|
oneImageWithoutCaption: false,
|
|
16
|
-
|
|
13
|
+
iframeWithoutCaption: false,
|
|
14
|
+
videoWithoutCaption: false,
|
|
15
|
+
hasNumClass: false,
|
|
17
16
|
}
|
|
18
|
-
md.use(mdFigureWithPCaption, opt);
|
|
19
17
|
|
|
18
|
+
const md = mdit({ html: true }).use(mdFigureWithPCaption, opt).use(attrs);
|
|
19
|
+
|
|
20
|
+
opt.hasNumClass = true
|
|
21
|
+
const mdHasNumClass = mdit({ html: true }).use(mdFigureWithPCaption, opt).use(attrs);
|
|
22
|
+
|
|
23
|
+
opt.hasNumClass = false
|
|
20
24
|
opt.oneImageWithoutCaption = true
|
|
21
|
-
mdOneImage.use(mdFigureWithPCaption, opt).use(attrs);
|
|
25
|
+
const mdOneImage = mdit({ html: true }).use(mdFigureWithPCaption, opt).use(attrs);
|
|
22
26
|
|
|
23
27
|
opt.iframeWithoutCaption = true
|
|
24
|
-
|
|
28
|
+
opt.hasNumClass = false
|
|
29
|
+
const mdIframeWithoutCaption = mdit({ html: true }).use(mdFigureWithPCaption, opt).use(attrs);
|
|
25
30
|
|
|
26
31
|
opt.multipleImages = true
|
|
27
|
-
mdMultipleImages.use(mdFigureWithPCaption, opt).use(attrs)
|
|
32
|
+
const mdMultipleImages = mdit({ html: true }).use(mdFigureWithPCaption, opt).use(attrs)
|
|
28
33
|
|
|
29
34
|
opt.videoWithoutCaption = true
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
35
|
+
const mdVideoWithoutCaption = mdit({ html: true }).use(mdFigureWithPCaption, opt).use(attrs)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
let __dirname = path.dirname(new URL(import.meta.url).pathname)
|
|
39
|
+
const isWindows = (process.platform === 'win32')
|
|
40
|
+
if (isWindows) {
|
|
41
|
+
__dirname = __dirname.replace(/^\/+/, '').replace(/\//g, '\\')
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
const testData = {
|
|
46
|
+
noOption: __dirname + path.sep + 'examples-no-option.txt',
|
|
47
|
+
hasNumClass: __dirname + path.sep + 'examples-has-num-class.txt',
|
|
48
|
+
oneImageWithoutCaption: __dirname + path.sep + 'examples-one-image-without-caption.txt',
|
|
49
|
+
iframeWithoutCaption: __dirname + path.sep + 'examples-iframe-without-caption.txt',
|
|
50
|
+
multipleImages: __dirname + path.sep + 'examples-multiple-images.txt',
|
|
51
|
+
videoWithoutCaption: __dirname + path.sep + 'examples-video-without-caption.txt',
|
|
52
|
+
mdAllOption: __dirname + path.sep + 'examples-all-option.txt',
|
|
53
|
+
imgAltCaption: __dirname + path.sep + 'examples-img-alt-caption.txt',
|
|
54
|
+
imgTitleCaption: __dirname + path.sep + 'examples-img-title-caption.txt',
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const getTestData = (pat) => {
|
|
58
|
+
let ms = [];
|
|
59
|
+
if(!fs.existsSync(pat)) {
|
|
60
|
+
console.log('No exist: ' + pat)
|
|
61
|
+
return ms
|
|
62
|
+
}
|
|
63
|
+
const exampleCont = fs.readFileSync(pat, 'utf-8').trim();
|
|
64
|
+
|
|
65
|
+
let ms0 = exampleCont.split(/\n*\[Markdown\]\n/);
|
|
66
|
+
let n = 1;
|
|
67
|
+
while(n < ms0.length) {
|
|
68
|
+
let mhs = ms0[n].split(/\n+\[HTML[^\]]*?\]\n/);
|
|
69
|
+
let i = 1;
|
|
70
|
+
while (i < 2) {
|
|
71
|
+
if (mhs[i] === undefined) {
|
|
72
|
+
mhs[i] = '';
|
|
73
|
+
} else {
|
|
74
|
+
mhs[i] = mhs[i].replace(/$/,'\n');
|
|
75
|
+
}
|
|
76
|
+
i++;
|
|
47
77
|
}
|
|
48
|
-
|
|
78
|
+
ms[n] = {
|
|
79
|
+
"markdown": mhs[0],
|
|
80
|
+
"html": mhs[1],
|
|
81
|
+
};
|
|
82
|
+
n++;
|
|
49
83
|
}
|
|
50
|
-
ms
|
|
51
|
-
"markdown": mhs[0],
|
|
52
|
-
"html": mhs[1],
|
|
53
|
-
};
|
|
54
|
-
n++;
|
|
84
|
+
return ms
|
|
55
85
|
}
|
|
56
86
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
} else if (n > 20) {
|
|
72
|
-
h = mdOneImage.render(m);
|
|
73
|
-
} else {
|
|
74
|
-
h = md.render(m);
|
|
87
|
+
const runTest = (process, pat, pass, testId) => {
|
|
88
|
+
console.log('===========================================================')
|
|
89
|
+
console.log(pat)
|
|
90
|
+
let ms = getTestData(pat)
|
|
91
|
+
if (ms.length === 0) return
|
|
92
|
+
let n = 1;
|
|
93
|
+
let end = ms.length - 1
|
|
94
|
+
if(testId) {
|
|
95
|
+
if (testId[0]) n = testId[0]
|
|
96
|
+
if (testId[1]) {
|
|
97
|
+
if (ms.length >= testId[1]) {
|
|
98
|
+
end = testId[1]
|
|
99
|
+
}
|
|
100
|
+
}
|
|
75
101
|
}
|
|
102
|
+
//console.log(n, end)
|
|
76
103
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
104
|
+
while(n <= end) {
|
|
105
|
+
|
|
106
|
+
if (!ms[n]
|
|
107
|
+
// || n != 3
|
|
108
|
+
) {
|
|
109
|
+
n++
|
|
110
|
+
continue
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const m = ms[n].markdown;
|
|
114
|
+
const h = process.render(m)
|
|
81
115
|
console.log('Test: ' + n + ' >>>');
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
116
|
+
try {
|
|
117
|
+
assert.strictEqual(h, ms[n].html);
|
|
118
|
+
} catch(e) {
|
|
119
|
+
pass = false
|
|
120
|
+
//console.log('Test: ' + n + ' >>>');
|
|
121
|
+
//console.log(opt);
|
|
122
|
+
console.log(ms[n].markdown);
|
|
123
|
+
console.log('incorrect:');
|
|
124
|
+
console.log('H: ' + h +'C: ' + ms[n].html);
|
|
125
|
+
}
|
|
126
|
+
n++;
|
|
127
|
+
}
|
|
128
|
+
return pass
|
|
87
129
|
}
|
|
88
130
|
|
|
131
|
+
let pass = true
|
|
132
|
+
pass = runTest(md, testData.noOption, pass)
|
|
133
|
+
pass = runTest(mdHasNumClass, testData.hasNumClass, pass)
|
|
134
|
+
pass = runTest(mdOneImage, testData.oneImageWithoutCaption, pass)
|
|
135
|
+
pass = runTest(mdIframeWithoutCaption, testData.iframeWithoutCaption, pass)
|
|
136
|
+
pass = runTest(mdMultipleImages, testData.multipleImages, pass)
|
|
137
|
+
pass = runTest(mdVideoWithoutCaption, testData.videoWithoutCaption, pass)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
opt.oneImageWithoutCaption = false
|
|
141
|
+
|
|
142
|
+
opt.imgAltCaption = 'Figure'
|
|
143
|
+
const mdImgAltCaption = mdit({html: true}).use(mdFigureWithPCaption, opt).use(attrs)
|
|
144
|
+
pass = runTest(mdImgAltCaption, testData.imgAltCaption, pass, [1, 5])
|
|
145
|
+
opt.imgAltCaption = '図'
|
|
146
|
+
const mdImgAltCaptionJa = mdit({html: true}).use(mdFigureWithPCaption, opt).use(attrs)
|
|
147
|
+
pass = runTest(mdImgAltCaptionJa, testData.imgAltCaption, pass, [6 , 99])
|
|
148
|
+
|
|
149
|
+
opt.imgAltCaption = false
|
|
150
|
+
|
|
151
|
+
opt.imgTitleCaption = 'Figure'
|
|
152
|
+
const mdImgTitleCaption = mdit({html: true}).use(mdFigureWithPCaption, opt).use(attrs)
|
|
153
|
+
pass = runTest(mdImgTitleCaption, testData.imgTitleCaption, pass, [1, 6])
|
|
154
|
+
opt.imgTitleCaption = '図'
|
|
155
|
+
const mdImgTitleCaptionJa = mdit({html: true}).use(mdFigureWithPCaption, opt).use(attrs)
|
|
156
|
+
pass = runTest(mdImgTitleCaptionJa, testData.imgTitleCaption, pass, [7, 99])
|
|
157
|
+
|
|
89
158
|
if (pass) console.log('Passed all test.')
|