@peaceroad/markdown-it-figure-with-p-caption 0.11.0 → 0.13.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.
@@ -1,59 +0,0 @@
1
- [Markdown]
2
- ![Figure](cat.jpg)
3
-
4
- A paragraph.
5
-
6
- ![Figure](cat.jpg)
7
-
8
- A paragraph.
9
-
10
- [HTML]
11
- <figure class="f-img">
12
- <img src="cat.jpg" alt="Figure">
13
- </figure>
14
- <p>A paragraph.</p>
15
- <figure class="f-img">
16
- <img src="cat.jpg" alt="Figure">
17
- </figure>
18
- <p>A paragraph.</p>
19
-
20
-
21
- [Markdown]
22
- A paragraph.
23
-
24
- - ![Figure](cat.jpg)
25
-
26
- A paragraph.
27
-
28
- [HTML]
29
- <p>A paragraph.</p>
30
- <ul>
31
- <li><img src="cat.jpg" alt="Figure"></li>
32
- </ul>
33
- <p>A paragraph.</p>
34
-
35
- [Markdown]
36
- Figure. A Caption.
37
-
38
- ![Figure](cat.jpg)
39
- [HTML]
40
- <figure class="f-img">
41
- <figcaption><span class="f-img-label">Figure<span class="f-img-label-joint">.</span></span> A Caption.</figcaption>
42
- <img src="cat.jpg" alt="Figure">
43
- </figure>
44
-
45
-
46
- [Markdown]
47
-
48
- ```
49
- code
50
- ```
51
-
52
- ![A caption.](cat.jpg)
53
-
54
- [HTML]
55
- <pre><code>code
56
- </code></pre>
57
- <figure class="f-img">
58
- <img src="cat.jpg" alt="A caption.">
59
- </figure>
@@ -1,21 +0,0 @@
1
- [Markdown]
2
- Figure. A caption.
3
-
4
- ![](example.jpg)
5
-
6
- Figure. A caption.
7
-
8
- ![](example.jpg)
9
-
10
- [HTML]
11
- <figure class="f-img">
12
- <figcaption><span class="f-img-label">Figure 1<span class="f-img-label-joint">.</span></span> A caption.</figcaption>
13
- <img src="example.jpg" alt="">
14
- </figure>
15
- <figure class="f-img">
16
- <figcaption><span class="f-img-label">Figure 2<span class="f-img-label-joint">.</span></span> A caption.</figcaption>
17
- <img src="example.jpg" alt="">
18
- </figure>
19
-
20
-
21
-
@@ -1,52 +0,0 @@
1
- [Markdown]
2
- <video controls width="400" height="300">
3
- <source src="example.mp4" type="video/mp4">
4
- </video>
5
- [HTML]
6
- <figure class="f-video">
7
- <video controls width="400" height="300">
8
- <source src="example.mp4" type="video/mp4">
9
- </video>
10
- </figure>
11
-
12
- [Markdown]
13
- Video. A caption.
14
-
15
- <video controls width="400" height="300">
16
- <source src="example.mp4" type="video/mp4">
17
- </video>
18
- [HTML]
19
- <figure class="f-video">
20
- <figcaption><span class="f-video-label">Video<span class="f-video-label-joint">.</span></span> A caption.</figcaption>
21
- <video controls width="400" height="300">
22
- <source src="example.mp4" type="video/mp4">
23
- </video>
24
- </figure>
25
-
26
-
27
- [Markdown]
28
- A YouTube paragraph.
29
-
30
- <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>
31
-
32
- A paragraph.
33
- [HTML]
34
- <p>A YouTube paragraph.</p>
35
- <figure class="f-video">
36
- <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>
37
- </figure>
38
- <p>A paragraph.</p>
39
-
40
-
41
- [Markdown]
42
- Video. A YouTube caption.
43
-
44
- <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>
45
-
46
- A paragraph.
47
- [HTML]
48
- <figure class="f-video">
49
- <figcaption><span class="f-video-label">Video<span class="f-video-label-joint">.</span></span> A YouTube caption.</figcaption>
50
- <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>
51
- </figure>
52
- <p>A paragraph.</p>
package/test/test.js DELETED
@@ -1,208 +0,0 @@
1
- import assert from 'assert'
2
- import fs from 'fs'
3
- import path from 'path'
4
- import mdit from 'markdown-it'
5
- import mditAttrs from 'markdown-it-attrs'
6
- import mditRndererFence from '@peaceroad/markdown-it-renderer-fence'
7
-
8
- import mdFigureWithPCaption from '../index.js'
9
- import highlightjs from 'highlight.js'
10
-
11
- let opt = {
12
- dquoteFilename: true,
13
- strongFilename: true,
14
- oneImageWithoutCaption: false,
15
- iframeWithoutCaption: false,
16
- videoWithoutCaption: false,
17
- hasNumClass: false,
18
- iframeTypeBlockquoteWithoutCaption: false,
19
- setFigureNumber: false,
20
- }
21
-
22
- const md = mdit({ html: true }).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
23
-
24
- opt.hasNumClass = true
25
- const mdHasNumClass = mdit({ html: true }).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
26
-
27
- opt.hasNumClass = false
28
- opt.oneImageWithoutCaption = true
29
- const mdOneImage = mdit({ html: true }).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
30
-
31
- opt.iframeWithoutCaption = true
32
- opt.hasNumClass = false
33
- const mdIframeWithoutCaption = mdit({ html: true }).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
34
-
35
- opt.iframeTypeBlockquoteWithoutCaption = true
36
- const mdIframeTypeBlockquoteWithoutCaption = mdit({ html: true }).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
37
-
38
- opt.multipleImages = true
39
- const mdMultipleImages = mdit({ html: true }).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
40
-
41
- opt.videoWithoutCaption = true
42
- const mdVideoWithoutCaption = mdit({ html: true }).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
43
-
44
-
45
- const mdConsole = mdit({
46
- html: true,
47
- langPrefix: 'language-',
48
- typographer: false,
49
- highlight: (str, lang) => {
50
- if (lang && highlightjs.getLanguage(lang)) {
51
- try {
52
- return highlightjs.highlight(str, { language: lang }).value
53
- } catch (__) {}
54
- }
55
- return str
56
- }
57
- }).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
58
-
59
- let __dirname = path.dirname(new URL(import.meta.url).pathname)
60
- const isWindows = (process.platform === 'win32')
61
- if (isWindows) {
62
- __dirname = __dirname.replace(/^\/+/, '').replace(/\//g, '\\')
63
- }
64
-
65
-
66
- const testData = {
67
- noOption: __dirname + path.sep + 'examples-no-option.txt',
68
- hasNumClass: __dirname + path.sep + 'examples-has-num-class.txt',
69
- oneImageWithoutCaption: __dirname + path.sep + 'examples-one-image-without-caption.txt',
70
- iframeWithoutCaption: __dirname + path.sep + 'examples-iframe-without-caption.txt',
71
- iframeTypeBlockquoteWithoutCaption: __dirname + path.sep + 'examples-iframe-type-blockquote-without-caption.txt',
72
- multipleImages: __dirname + path.sep + 'examples-multiple-images.txt',
73
- videoWithoutCaption: __dirname + path.sep + 'examples-video-without-caption.txt',
74
- mdAllOption: __dirname + path.sep + 'examples-all-option.txt',
75
- imgAltCaption: __dirname + path.sep + 'examples-img-alt-caption.txt',
76
- imgTitleCaption: __dirname + path.sep + 'examples-img-title-caption.txt',
77
- console: __dirname + path.sep + 'examples-console.txt',
78
- setFigureNumber: __dirname + path.sep + 'examples-set-figure-number.txt',
79
- imgAltCaptionNumber: __dirname + path.sep + 'examples-img-alt-caption-number.txt',
80
- imgTitleCaptionNumber: __dirname + path.sep + 'examples-img-title-caption-number.txt',
81
- allIframeTypeFigureClassName: __dirname + path.sep + 'examples-all-iframe-type-figure-class-name.txt',
82
- }
83
-
84
- const getTestData = (pat) => {
85
- let ms = [];
86
- if(!fs.existsSync(pat)) {
87
- console.log('No exist: ' + pat)
88
- return ms
89
- }
90
- const exampleCont = fs.readFileSync(pat, 'utf-8').trim();
91
-
92
- let ms0 = exampleCont.split(/\n*\[Markdown\]\n/);
93
- let n = 1;
94
- while(n < ms0.length) {
95
- let mhs = ms0[n].split(/\n+\[HTML[^\]]*?\]\n/);
96
- let i = 1;
97
- while (i < 2) {
98
- if (mhs[i] === undefined) {
99
- mhs[i] = '';
100
- } else {
101
- mhs[i] = mhs[i].replace(/$/,'\n');
102
- }
103
- i++;
104
- }
105
- ms[n] = {
106
- "markdown": mhs[0],
107
- "html": mhs[1],
108
- };
109
- n++;
110
- }
111
- return ms
112
- }
113
-
114
- const runTest = (process, pat, pass, testId) => {
115
- console.log('===========================================================')
116
- console.log(pat)
117
- let ms = getTestData(pat)
118
- if (ms.length === 0) return
119
- let n = 1;
120
- let end = ms.length - 1
121
- if(testId) {
122
- if (testId[0]) n = testId[0]
123
- if (testId[1]) {
124
- if (ms.length >= testId[1]) {
125
- end = testId[1]
126
- }
127
- }
128
- }
129
- //console.log(n, end)
130
-
131
- while(n <= end) {
132
-
133
- if (!ms[n]
134
- //|| n != 11
135
- ) {
136
- n++
137
- continue
138
- }
139
-
140
- const m = ms[n].markdown;
141
- const h = process.render(m)
142
- console.log('Test: ' + n + ' >>>');
143
- //console.log(ms[n].markdown);
144
- try {
145
- assert.strictEqual(h, ms[n].html);
146
- } catch(e) {
147
- pass = false
148
- //console.log('Test: ' + n + ' >>>');
149
- //console.log(opt);
150
- console.log(ms[n].markdown);
151
- console.log('incorrect:');
152
- console.log('H: ' + h +'C: ' + ms[n].html);
153
- }
154
- n++;
155
- }
156
- return pass
157
- }
158
-
159
- let pass = true
160
- pass = runTest(md, testData.noOption, pass)
161
- pass = runTest(mdHasNumClass, testData.hasNumClass, pass)
162
- pass = runTest(mdOneImage, testData.oneImageWithoutCaption, pass)
163
- pass = runTest(mdIframeWithoutCaption, testData.iframeWithoutCaption, pass)
164
- pass = runTest(mdIframeTypeBlockquoteWithoutCaption, testData.iframeTypeBlockquoteWithoutCaption, pass)
165
- pass = runTest(mdMultipleImages, testData.multipleImages, pass)
166
- pass = runTest(mdVideoWithoutCaption, testData.videoWithoutCaption, pass)
167
- pass = runTest(mdConsole, testData.console, pass)
168
-
169
-
170
- opt.imgAltCaption = 'Figure'
171
- const mdImgAltCaption = mdit({html: true}).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
172
- pass = runTest(mdImgAltCaption, testData.imgAltCaption.replace(/\.txt$/, '.en.txt'), pass)
173
- opt.imgAltCaption = '図'
174
- const mdImgAltCaptionJa = mdit({html: true}).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
175
- pass = runTest(mdImgAltCaptionJa, testData.imgAltCaption.replace(/\.txt$/, '.ja.txt'), pass)
176
-
177
- opt.imgAltCaption = false
178
-
179
- opt.imgTitleCaption = 'Figure'
180
- const mdImgTitleCaption = mdit({html: true}).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
181
- pass = runTest(mdImgTitleCaption, testData.imgTitleCaption.replace(/\.txt$/, '.en.txt'), pass)
182
- opt.imgTitleCaption = '図'
183
- const mdImgTitleCaptionJa = mdit({html: true}).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
184
- pass = runTest(mdImgTitleCaptionJa, testData.imgTitleCaption.replace(/.txt$/, '.ja.txt'), pass)
185
-
186
- opt = {}
187
- opt.setFigureNumber = true
188
- const mdSetFigureNumber = mdit({html: true}).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
189
- pass = runTest(mdSetFigureNumber, testData.setFigureNumber.replace(/\.txt$/, '.en.txt'), pass)
190
-
191
- opt.imgAltCaption = true
192
- const mdImgAltCaptionNumber = mdit({html: true}).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
193
- pass = runTest(mdImgAltCaptionNumber, testData.imgAltCaptionNumber.replace(/\.txt$/, '.en.txt'), pass)
194
-
195
- opt = {}
196
- opt.imgTitleCaption = true
197
- const mdImgTitleCaptionNumber = mdit({html: true}).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
198
- //pass = runTest(mdImgTitleCaptionNumber, testData.imgTitleCaptionNumber.replace(/\.txt$/, '.en.txt'), pass)
199
-
200
- opt = {}
201
- opt.videoWithoutCaption = true
202
- opt.iframeWithoutCaption = true
203
- opt.iframeTypeBlockquoteWithoutCaption = true
204
- opt.allIframeTypeFigureClassName = 'f-embed'
205
- const mdAllIframeTypeFigureClassName = mdit({html: true}).use(mdFigureWithPCaption, opt).use(mditAttrs).use(mditRndererFence);
206
- pass = runTest(mdAllIframeTypeFigureClassName, testData.allIframeTypeFigureClassName, pass)
207
-
208
- if (pass) console.log('Passed all test.')