@peaceroad/markown-figure-num-setting 0.1.3 → 0.1.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/README.md +23 -0
- package/index.js +18 -9
- package/package.json +1 -1
- package/test/examples-no-set-alt.txt +36 -0
- package/test/examples.txt +133 -1
- package/test/test.js +57 -33
- package/test/examples_paragraphnumber.txt +0 -28
package/README.md
CHANGED
|
@@ -102,3 +102,26 @@ Figure 2. キャプション
|
|
|
102
102
|
|
|
103
103
|
段落。段落。段落。
|
|
104
104
|
```
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
## Option
|
|
108
|
+
|
|
109
|
+
### noSetAlt
|
|
110
|
+
|
|
111
|
+
[Input]
|
|
112
|
+
図 キャプション
|
|
113
|
+
|
|
114
|
+

|
|
115
|
+
|
|
116
|
+
図 キャプション
|
|
117
|
+
|
|
118
|
+

|
|
119
|
+
|
|
120
|
+
[Output]
|
|
121
|
+
図1 キャプション
|
|
122
|
+
|
|
123
|
+

|
|
124
|
+
|
|
125
|
+
図2 キャプション
|
|
126
|
+
|
|
127
|
+

|
package/index.js
CHANGED
|
@@ -7,6 +7,8 @@ const setMarkdownFigureNum = (markdown, option) => {
|
|
|
7
7
|
samp: false,
|
|
8
8
|
blockquote: false,
|
|
9
9
|
slide: false,
|
|
10
|
+
noSetAlt: false,
|
|
11
|
+
setImgAlt: false,
|
|
10
12
|
}
|
|
11
13
|
opt["pre-code"] = opt.code
|
|
12
14
|
opt["pre-samp"] = opt.samp
|
|
@@ -35,7 +37,8 @@ const setMarkdownFigureNum = (markdown, option) => {
|
|
|
35
37
|
')|' +
|
|
36
38
|
'[.](' + markAfterNum + ')(?:' +
|
|
37
39
|
joint + '|(?=[ ]+[^a-z])|$' +
|
|
38
|
-
')' +
|
|
40
|
+
')|' +
|
|
41
|
+
'[ ]*$' +
|
|
39
42
|
')';
|
|
40
43
|
|
|
41
44
|
const markAfterJa = '(?:' +
|
|
@@ -48,13 +51,14 @@ const setMarkdownFigureNum = (markdown, option) => {
|
|
|
48
51
|
jointHalfWidth + '(?:(?=[ ]+)|$)|' +
|
|
49
52
|
jointFullWidth + '|' +
|
|
50
53
|
'(?=[ ]+)|$' +
|
|
51
|
-
')' +
|
|
54
|
+
')|' +
|
|
55
|
+
'[ ]*$' +
|
|
52
56
|
')';
|
|
53
57
|
|
|
54
58
|
const markReg = {
|
|
55
59
|
//fig(ure)?, illust, photo
|
|
56
60
|
"img": new RegExp('^(?:' +
|
|
57
|
-
'(?:[fF][iI][gG](?:[uU][rR][eE])?|[iI][lL]{2}[uU][sS][tT]|[pP][hH][oO[tT][oO])'+ markAfterEn + '|' +
|
|
61
|
+
'(?:[fF][iI][gG](?:[uU][rR][eE])?|[iI][lL]{2}[uU][sS][tT]|[pP][hH][oO][tT][oO])'+ markAfterEn + '|' +
|
|
58
62
|
'(?:図|イラスト|写真)' + markAfterJa +
|
|
59
63
|
')'),
|
|
60
64
|
//movie, video
|
|
@@ -69,7 +73,7 @@ const setMarkdownFigureNum = (markdown, option) => {
|
|
|
69
73
|
')'),
|
|
70
74
|
//code(block)?, program
|
|
71
75
|
"pre-code": new RegExp('^(?:' +
|
|
72
|
-
'(?:[cC][oO][dD][eE](?:[bB][lL][oO][cC][kK])?|[pP][rR][oO][gG][rR][aA][mM]|[aA][lL][gG][oO][rR][iI[tT][hH][mM])'+ markAfterEn + '|' +
|
|
76
|
+
'(?:[cC][oO][dD][eE](?:[bB][lL][oO][cC][kK])?|[pP][rR][oO][gG][rR][aA][mM]|[aA][lL][gG][oO][rR][iI][tT][hH][mM])'+ markAfterEn + '|' +
|
|
73
77
|
'(?:(?:ソース)?コード|リスト|命令|プログラム|算譜|アルゴリズム|算法)' + markAfterJa +
|
|
74
78
|
')'),
|
|
75
79
|
//terminal, prompt, command
|
|
@@ -92,16 +96,22 @@ const setMarkdownFigureNum = (markdown, option) => {
|
|
|
92
96
|
const label = (hasMarkLabel, counter, isAlt) => {
|
|
93
97
|
|
|
94
98
|
let label = hasMarkLabel[0]
|
|
99
|
+
let LabelIsEn = /[a-zA-Z]/.test(label)
|
|
100
|
+
let spaceBeforeCounter = ''
|
|
101
|
+
if (LabelIsEn) {
|
|
102
|
+
spaceBeforeCounter = ' '
|
|
103
|
+
}
|
|
95
104
|
|
|
96
105
|
if (hasMarkLabel[3]) {
|
|
97
106
|
label = hasMarkLabel[0].replace(new RegExp(hasMarkLabel[3] + '$'), '')
|
|
98
107
|
}
|
|
99
108
|
let isLabelLastJoint = label.match(new RegExp('(' + joint +')$'))
|
|
109
|
+
|
|
100
110
|
if (isLabelLastJoint) {
|
|
101
111
|
if (isAlt) {
|
|
102
|
-
label = label.replace(new RegExp(joint +'$'), '') +
|
|
112
|
+
label = label.replace(new RegExp(joint +'$'), '') + spaceBeforeCounter + counter
|
|
103
113
|
} else {
|
|
104
|
-
label = label.replace(new RegExp(joint +'$'), '') +
|
|
114
|
+
label = label.replace(new RegExp(joint +'$'), '') + spaceBeforeCounter + counter + isLabelLastJoint[1]
|
|
105
115
|
}
|
|
106
116
|
} else {
|
|
107
117
|
label += counter
|
|
@@ -125,7 +135,6 @@ const setMarkdownFigureNum = (markdown, option) => {
|
|
|
125
135
|
}
|
|
126
136
|
isFigureImage = lines[i].match(new RegExp(figureImageReg))
|
|
127
137
|
if (!isFigureImage) break
|
|
128
|
-
//console.log(isFigureImage)
|
|
129
138
|
|
|
130
139
|
let j = i
|
|
131
140
|
while (j >= 0) {
|
|
@@ -207,13 +216,13 @@ const setMarkdownFigureNum = (markdown, option) => {
|
|
|
207
216
|
}
|
|
208
217
|
|
|
209
218
|
for (let mark of Object.keys(markReg)) {
|
|
210
|
-
const hasMarkLabel = lines[n].match(markReg[mark])
|
|
219
|
+
const hasMarkLabel = lines[n].match(markReg[mark])
|
|
211
220
|
//if (hasMarkLabel) console.log(hasMarkLabel)
|
|
212
221
|
if (hasMarkLabel && opt[mark]) {
|
|
213
222
|
counter[mark]++
|
|
214
223
|
//console.log('lines[n]: ' + lines[n])
|
|
215
224
|
lines[n] = lines[n].replace(new RegExp('^([ \t]*)' + hasMarkLabel[0]), '$1' + label(hasMarkLabel, counter[mark]))
|
|
216
|
-
if (mark === 'img') {
|
|
225
|
+
if (mark === 'img' && !opt.noSetAlt) {
|
|
217
226
|
setImageAltNumber(lines, n, mark, hasMarkLabel, counter)
|
|
218
227
|
}
|
|
219
228
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
[Input]
|
|
2
|
+
図 キャプション
|
|
3
|
+
|
|
4
|
+

|
|
5
|
+
|
|
6
|
+
図 キャプション
|
|
7
|
+
|
|
8
|
+

|
|
9
|
+
|
|
10
|
+
[Output]
|
|
11
|
+
図1 キャプション
|
|
12
|
+
|
|
13
|
+

|
|
14
|
+
|
|
15
|
+
図2 キャプション
|
|
16
|
+
|
|
17
|
+

|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
[Input]
|
|
21
|
+
図
|
|
22
|
+
|
|
23
|
+

|
|
24
|
+
|
|
25
|
+
図
|
|
26
|
+
|
|
27
|
+

|
|
28
|
+
|
|
29
|
+
[Output]
|
|
30
|
+
図1
|
|
31
|
+
|
|
32
|
+

|
|
33
|
+
|
|
34
|
+
図2
|
|
35
|
+
|
|
36
|
+

|
package/test/examples.txt
CHANGED
|
@@ -195,4 +195,136 @@ Figure 2. キャプション
|
|
|
195
195
|
|
|
196
196
|

|
|
197
197
|
|
|
198
|
-
図2 キャプション
|
|
198
|
+
図2 キャプション
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
[Input]
|
|
203
|
+
図
|
|
204
|
+
|
|
205
|
+

|
|
206
|
+
|
|
207
|
+
図
|
|
208
|
+
|
|
209
|
+

|
|
210
|
+
[Output]
|
|
211
|
+
図1
|
|
212
|
+
|
|
213
|
+

|
|
214
|
+
|
|
215
|
+
図2
|
|
216
|
+
|
|
217
|
+

|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
[Input]
|
|
221
|
+
図
|
|
222
|
+
|
|
223
|
+

|
|
224
|
+
|
|
225
|
+
図
|
|
226
|
+
|
|
227
|
+

|
|
228
|
+
[Output]
|
|
229
|
+
図1
|
|
230
|
+
|
|
231
|
+

|
|
232
|
+
|
|
233
|
+
図2
|
|
234
|
+
|
|
235
|
+

|
|
236
|
+
|
|
237
|
+
[Input]
|
|
238
|
+
図
|
|
239
|
+
|
|
240
|
+

|
|
241
|
+
|
|
242
|
+
図
|
|
243
|
+
|
|
244
|
+

|
|
245
|
+
[Output]
|
|
246
|
+
図1
|
|
247
|
+
|
|
248
|
+

|
|
249
|
+
|
|
250
|
+
図2
|
|
251
|
+
|
|
252
|
+

|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
[Input]
|
|
256
|
+
段落。段落。段落。段落。段落。段落。段落。段落。段落。
|
|
257
|
+
|
|
258
|
+
図1
|
|
259
|
+
|
|
260
|
+

|
|
261
|
+
|
|
262
|
+
段落。段落。段落。段落。段落。段落。段落。段落。段落。
|
|
263
|
+
|
|
264
|
+
図2
|
|
265
|
+
|
|
266
|
+

|
|
267
|
+
|
|
268
|
+
段落。段落。段落。段落。段落。段落。段落。段落。段落。
|
|
269
|
+
|
|
270
|
+
図
|
|
271
|
+
|
|
272
|
+

|
|
273
|
+
|
|
274
|
+
段落。段落。段落。段落。段落。段落。段落。段落。段落。
|
|
275
|
+
|
|
276
|
+
図2
|
|
277
|
+
|
|
278
|
+

|
|
279
|
+
|
|
280
|
+
段落。段落。段落。段落。段落。段落。段落。段落。段落。
|
|
281
|
+
|
|
282
|
+
図
|
|
283
|
+
|
|
284
|
+

|
|
285
|
+
|
|
286
|
+
段落。段落。段落。段落。段落。段落。段落。段落。段落。
|
|
287
|
+
|
|
288
|
+
図2
|
|
289
|
+
|
|
290
|
+

|
|
291
|
+
|
|
292
|
+
段落。段落。段落。段落。段落。段落。段落。段落。段落。
|
|
293
|
+
[Output]
|
|
294
|
+
段落。段落。段落。段落。段落。段落。段落。段落。段落。
|
|
295
|
+
|
|
296
|
+
図1
|
|
297
|
+
|
|
298
|
+

|
|
299
|
+
|
|
300
|
+
段落。段落。段落。段落。段落。段落。段落。段落。段落。
|
|
301
|
+
|
|
302
|
+
図2
|
|
303
|
+
|
|
304
|
+

|
|
305
|
+
|
|
306
|
+
段落。段落。段落。段落。段落。段落。段落。段落。段落。
|
|
307
|
+
|
|
308
|
+
図3
|
|
309
|
+
|
|
310
|
+

|
|
311
|
+
|
|
312
|
+
段落。段落。段落。段落。段落。段落。段落。段落。段落。
|
|
313
|
+
|
|
314
|
+
図4
|
|
315
|
+
|
|
316
|
+

|
|
317
|
+
|
|
318
|
+
段落。段落。段落。段落。段落。段落。段落。段落。段落。
|
|
319
|
+
|
|
320
|
+
図5
|
|
321
|
+
|
|
322
|
+

|
|
323
|
+
|
|
324
|
+
段落。段落。段落。段落。段落。段落。段落。段落。段落。
|
|
325
|
+
|
|
326
|
+
図6
|
|
327
|
+
|
|
328
|
+

|
|
329
|
+
|
|
330
|
+
段落。段落。段落。段落。段落。段落。段落。段落。段落。
|
package/test/test.js
CHANGED
|
@@ -2,46 +2,70 @@ import assert from 'assert'
|
|
|
2
2
|
import fs from 'fs'
|
|
3
3
|
import path from 'path'
|
|
4
4
|
import setMarkdownFigureNum from '../index.js'
|
|
5
|
+
import setMarkdownFigureNumWithNoSetAlt from '../index.js'
|
|
5
6
|
|
|
6
7
|
let __dirname = path.dirname(new URL(import.meta.url).pathname)
|
|
7
8
|
const isWindows = (process.platform === 'win32')
|
|
8
9
|
if (isWindows) {
|
|
9
10
|
__dirname = __dirname.replace(/^\/+/, '').replace(/\//g, '\\')
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
let
|
|
15
|
-
let
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
mhs[i]
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
|
|
13
|
+
const check = (name, ex) => {
|
|
14
|
+
const exCont = fs.readFileSync(ex, 'utf-8').trim()
|
|
15
|
+
let ms = [];
|
|
16
|
+
let ms0 = exCont.split(/\n*\[Input\]\n/)
|
|
17
|
+
let n = 1;
|
|
18
|
+
while(n < ms0.length) {
|
|
19
|
+
let mhs = ms0[n].split(/\n+\[Output[^\]]*?\]\n/)
|
|
20
|
+
let i = 1
|
|
21
|
+
while (i < 2) {
|
|
22
|
+
if (mhs[i] === undefined) {
|
|
23
|
+
mhs[i] = ''
|
|
24
|
+
} else {
|
|
25
|
+
mhs[i] = mhs[i].replace(/$/,'\n')
|
|
26
|
+
}
|
|
27
|
+
i++
|
|
24
28
|
}
|
|
25
|
-
|
|
29
|
+
ms[n] = {
|
|
30
|
+
inputMarkdown: mhs[0].trim(),
|
|
31
|
+
outputMarkdown: mhs[1].trim(),
|
|
32
|
+
};
|
|
33
|
+
n++
|
|
26
34
|
}
|
|
27
|
-
ms[n] = {
|
|
28
|
-
inputMarkdown: mhs[0].trim(),
|
|
29
|
-
outputMarkdown: mhs[1].trim(),
|
|
30
|
-
};
|
|
31
|
-
n++
|
|
32
|
-
}
|
|
33
35
|
|
|
34
|
-
n = 1
|
|
35
|
-
while(n < ms.length) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
36
|
+
n = 1
|
|
37
|
+
while(n < ms.length) {
|
|
38
|
+
//if (n !== 10) { n++; continue }
|
|
39
|
+
console.log('Test: ' + n + ' >>>')
|
|
40
|
+
const m = ms[n].inputMarkdown
|
|
41
|
+
let h
|
|
42
|
+
let option = {}
|
|
43
|
+
if (name === 'default') {
|
|
44
|
+
h = setMarkdownFigureNum(m)
|
|
45
|
+
}
|
|
46
|
+
if (name === 'noSetAlt') {
|
|
47
|
+
option.noSetAlt = true
|
|
48
|
+
h = setMarkdownFigureNumWithNoSetAlt(m, option)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
assert.strictEqual(h, ms[n].outputMarkdown)
|
|
53
|
+
} catch(e) {
|
|
54
|
+
console.log('incorrect: ')
|
|
55
|
+
//console.log(m)
|
|
56
|
+
//console.log('::convert ->')
|
|
57
|
+
console.log('H: ' + h +'\n\nC: ' + ms[n].outputMarkdown)
|
|
58
|
+
}
|
|
59
|
+
n++
|
|
45
60
|
}
|
|
46
|
-
|
|
47
|
-
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
const example = {
|
|
65
|
+
default: __dirname + path.sep + 'examples.txt',
|
|
66
|
+
noSetAlt: __dirname + path.sep + 'examples-no-set-alt.txt',
|
|
67
|
+
}
|
|
68
|
+
for (let ex in example) {
|
|
69
|
+
check(ex, example[ex])
|
|
70
|
+
}
|
|
71
|
+
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
[Input]
|
|
2
|
-
This line is [Figure][#flag] paragraph.
|
|
3
|
-
|
|
4
|
-
Figure. A caption.
|
|
5
|
-
|
|
6
|
-
 {#flag}
|
|
7
|
-
|
|
8
|
-
Figure. A caption.
|
|
9
|
-
|
|
10
|
-
 {#flag2}
|
|
11
|
-
|
|
12
|
-
A paragraph. [Figure][#flag2] paragraph.
|
|
13
|
-
|
|
14
|
-
[Output]
|
|
15
|
-
This line is [Figure 1][] paragraph.
|
|
16
|
-
|
|
17
|
-
Figure 1. A caption.
|
|
18
|
-
|
|
19
|
-
 {#figure1}
|
|
20
|
-
|
|
21
|
-
Figure 2. A caption.
|
|
22
|
-
|
|
23
|
-
 {#figure2}
|
|
24
|
-
|
|
25
|
-
A paragraph. [Figure 2][] paragraph.
|
|
26
|
-
|
|
27
|
-
[Figure 1]: #figure1
|
|
28
|
-
[Figure 2]: #figure2
|