@peaceroad/markown-figure-num-setting 0.1.5 → 0.1.6
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 +43 -40
- package/index.js +60 -74
- package/package.json +7 -2
- package/test/examples-no-set-alt.txt +0 -55
- package/test/examples.txt +0 -348
- package/test/test.js +0 -76
package/README.md
CHANGED
|
@@ -10,95 +10,94 @@ setMarkdownFigureNum(markdownCont)
|
|
|
10
10
|
|
|
11
11
|
```
|
|
12
12
|
[Input]
|
|
13
|
-
|
|
13
|
+
Paragraph.
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
Figure. A Caption
|
|
16
16
|
|
|
17
|
-

|
|
17
|
+

|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
Paragraph.
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
Figure. A Caption
|
|
22
22
|
|
|
23
|
-

|
|
23
|
+

|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
Paragraph.
|
|
26
26
|
|
|
27
27
|
[Output]
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
図1 キャプション
|
|
28
|
+
Paragraph.
|
|
31
29
|
|
|
32
|
-
|
|
30
|
+
Figure 1. A Caption
|
|
33
31
|
|
|
34
|
-
|
|
32
|
+

|
|
35
33
|
|
|
36
|
-
|
|
34
|
+
Paragraph.
|
|
37
35
|
|
|
38
|
-
|
|
36
|
+
Figure 2. A Caption
|
|
39
37
|
|
|
40
|
-
|
|
38
|
+

|
|
41
39
|
|
|
40
|
+
Paragraph.
|
|
42
41
|
|
|
43
42
|
|
|
44
43
|
[Input]
|
|
45
|
-
|
|
44
|
+
Paragraph.
|
|
46
45
|
|
|
47
|
-
|
|
46
|
+
Figure 1. A Caption
|
|
48
47
|
|
|
49
|
-

|
|
48
|
+

|
|
50
49
|
|
|
51
|
-
|
|
50
|
+
Paragraph.
|
|
52
51
|
|
|
53
|
-
|
|
52
|
+
Figure 1. A Caption
|
|
54
53
|
|
|
55
|
-

|
|
54
|
+

|
|
56
55
|
|
|
57
|
-
|
|
56
|
+
Paragraph.
|
|
58
57
|
|
|
59
58
|
[Output]
|
|
60
|
-
|
|
59
|
+
Paragraph.
|
|
61
60
|
|
|
62
|
-
|
|
61
|
+
Figure 1. A Caption
|
|
63
62
|
|
|
64
|
-

|
|
65
64
|
|
|
66
|
-
|
|
65
|
+
Paragraph.
|
|
67
66
|
|
|
68
|
-
|
|
67
|
+
Figure 2. A Caption
|
|
69
68
|
|
|
70
|
-

|
|
71
70
|
|
|
72
|
-
|
|
71
|
+
Paragraph.
|
|
73
72
|
|
|
74
73
|
|
|
75
74
|
[Input]
|
|
76
75
|
段落。段落。段落。
|
|
77
76
|
|
|
78
|
-
|
|
77
|
+
図 キャプション
|
|
79
78
|
|
|
80
|
-

|
|
79
|
+

|
|
81
80
|
|
|
82
81
|
段落。段落。段落。
|
|
83
82
|
|
|
84
|
-
|
|
83
|
+
図 キャプション
|
|
85
84
|
|
|
86
|
-

|
|
85
|
+

|
|
87
86
|
|
|
88
87
|
段落。段落。段落。
|
|
89
88
|
|
|
90
89
|
[Output]
|
|
91
90
|
段落。段落。段落。
|
|
92
91
|
|
|
93
|
-
|
|
92
|
+
図1 キャプション
|
|
94
93
|
|
|
95
|
-

|
|
96
95
|
|
|
97
96
|
段落。段落。段落。
|
|
98
97
|
|
|
99
|
-
|
|
98
|
+
図2 キャプション
|
|
100
99
|
|
|
101
|
-

|
|
102
101
|
|
|
103
102
|
段落。段落。段落。
|
|
104
103
|
```
|
|
@@ -106,8 +105,11 @@ Figure 2. キャプション
|
|
|
106
105
|
|
|
107
106
|
## Option
|
|
108
107
|
|
|
109
|
-
###
|
|
108
|
+
### setNumberAlt
|
|
109
|
+
|
|
110
|
+
Default behavior leaves image alt text unchanged. Set `setNumberAlt: true` to add the label number to alt.
|
|
110
111
|
|
|
112
|
+
```
|
|
111
113
|
[Input]
|
|
112
114
|
図 キャプション
|
|
113
115
|
|
|
@@ -120,8 +122,9 @@ Figure 2. キャプション
|
|
|
120
122
|
[Output]
|
|
121
123
|
図1 キャプション
|
|
122
124
|
|
|
123
|
-

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

|
|
130
|
+
```
|
package/index.js
CHANGED
|
@@ -2,92 +2,73 @@ import { markReg as markRegEx, joint as jointStr } from "p7d-markdown-it-p-capti
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
const markReg = markRegEx
|
|
5
|
+
const markRegKeys = Object.keys(markReg)
|
|
5
6
|
const joint = jointStr
|
|
7
|
+
const jointSuffixCaptureReg = new RegExp('(' + joint + ')$')
|
|
8
|
+
const asciiAlphaStartReg = /^[A-Za-z]/
|
|
9
|
+
const blankLineReg = /^[ \t]*$/
|
|
10
|
+
const figureImageReg = /^([ \t]*\!\[) *?(.*?([0-9]*)) *?(\]\(.*?\))/
|
|
6
11
|
//console.log(markReg)
|
|
7
12
|
//console.log(joint)
|
|
8
13
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
const getLabelInfo = (hasMarkLabel) => {
|
|
15
|
+
const markLabel = hasMarkLabel[1] !== undefined
|
|
16
|
+
? hasMarkLabel[1]
|
|
17
|
+
: hasMarkLabel[4] !== undefined
|
|
18
|
+
? hasMarkLabel[4]
|
|
19
|
+
: hasMarkLabel[0]
|
|
20
|
+
const jointMatch = hasMarkLabel[0].match(jointSuffixCaptureReg)
|
|
21
|
+
return {
|
|
22
|
+
markLabel,
|
|
23
|
+
joint: jointMatch ? jointMatch[1] : '',
|
|
24
|
+
needsSpace: asciiAlphaStartReg.test(markLabel),
|
|
20
25
|
}
|
|
21
|
-
|
|
26
|
+
}
|
|
22
27
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
label = label.replace(new RegExp(joint +'$'), '') + spaceBeforeCounter + counter + hasLabelLastJoint[1]
|
|
28
|
-
}
|
|
29
|
-
} else {
|
|
30
|
-
label += counter
|
|
28
|
+
const buildLabel = (labelInfo, counter, isAlt) => {
|
|
29
|
+
let label = labelInfo.markLabel + (labelInfo.needsSpace ? ' ' : '') + counter
|
|
30
|
+
if (!isAlt && labelInfo.joint) {
|
|
31
|
+
label += labelInfo.joint
|
|
31
32
|
}
|
|
32
|
-
//console.log('label: ' + label)
|
|
33
33
|
return label
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (!isFigureImage) break
|
|
52
|
-
|
|
53
|
-
let j = i
|
|
54
|
-
while (j >= 0) {
|
|
55
|
-
if (/^[ \t]*$/.test(lines[j])) {
|
|
56
|
-
j--
|
|
57
|
-
continue
|
|
58
|
-
}
|
|
59
|
-
//console.log(isFigureImage[3], (counter.img - 1).toString())
|
|
60
|
-
if (isFigureImage[3] === (counter.img - 1).toString()) {
|
|
61
|
-
hasPrevFigureImage = false
|
|
62
|
-
break
|
|
63
|
-
}
|
|
64
|
-
lines[i] = lines[i].replace(new RegExp(figureImageReg), '$1' + label(hasMarkLabel, counter[mark], true) + '$4')
|
|
37
|
+
const setImageAltNumber = (lines, n, currentNumber, altLabel) => {
|
|
38
|
+
const prevNumber = currentNumber - 1
|
|
39
|
+
let i = n - 1
|
|
40
|
+
//console.log('lines[n]: ' + lines[n])
|
|
41
|
+
//console.log('CheckPrevLine')
|
|
42
|
+
while (i >= 0 && blankLineReg.test(lines[i])) {
|
|
43
|
+
i--
|
|
44
|
+
}
|
|
45
|
+
if (i >= 0) {
|
|
46
|
+
const isFigureImage = lines[i].match(figureImageReg)
|
|
47
|
+
if (isFigureImage) {
|
|
48
|
+
//console.log(isFigureImage[3], prevNumber.toString())
|
|
49
|
+
if (isFigureImage[3] !== prevNumber.toString()) {
|
|
50
|
+
lines[i] = lines[i].replace(figureImageReg, '$1' + altLabel + '$4')
|
|
65
51
|
//console.log('ChangePrevLine: ' + lines[i])
|
|
66
|
-
|
|
67
|
-
break
|
|
52
|
+
return
|
|
68
53
|
}
|
|
69
|
-
break
|
|
70
54
|
}
|
|
55
|
+
}
|
|
71
56
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
i
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
//console.log(
|
|
83
|
-
if (isFigureImage) {
|
|
84
|
-
lines[i] = lines[i].replace(new RegExp(figureImageReg), '$1' + label(hasMarkLabel, counter[mark], true) + '$4')
|
|
85
|
-
//console.log('ChangeNextLine: ' + lines[i])
|
|
86
|
-
}
|
|
87
|
-
break
|
|
57
|
+
//console.log('CheckNextLine')
|
|
58
|
+
i = n + 1
|
|
59
|
+
while (i < lines.length && blankLineReg.test(lines[i])) {
|
|
60
|
+
i++
|
|
61
|
+
}
|
|
62
|
+
if (i < lines.length) {
|
|
63
|
+
const isFigureImage = lines[i].match(figureImageReg)
|
|
64
|
+
//console.log(isFigureImage)
|
|
65
|
+
if (isFigureImage) {
|
|
66
|
+
lines[i] = lines[i].replace(figureImageReg, '$1' + altLabel + '$4')
|
|
67
|
+
//console.log('ChangeNextLine: ' + lines[i])
|
|
88
68
|
}
|
|
89
|
-
return
|
|
90
69
|
}
|
|
70
|
+
return
|
|
71
|
+
}
|
|
91
72
|
|
|
92
73
|
const setMarkdownFigureNum = (markdown, option) => {
|
|
93
74
|
let opt = {
|
|
@@ -97,10 +78,12 @@ const setMarkdownFigureNum = (markdown, option) => {
|
|
|
97
78
|
'pre-samp': false,
|
|
98
79
|
blockquote: false,
|
|
99
80
|
slide: false,
|
|
100
|
-
noSetAlt:
|
|
81
|
+
noSetAlt: true,
|
|
82
|
+
setNumberAlt: false,
|
|
101
83
|
setImgAlt: false,
|
|
102
84
|
}
|
|
103
85
|
if (option) Object.assign(opt, option)
|
|
86
|
+
const shouldSetAlt = opt.setNumberAlt || opt.setImgAlt || opt.noSetAlt === false
|
|
104
87
|
|
|
105
88
|
let n = 0
|
|
106
89
|
let lines = []
|
|
@@ -150,14 +133,17 @@ const setMarkdownFigureNum = (markdown, option) => {
|
|
|
150
133
|
}
|
|
151
134
|
|
|
152
135
|
//console.log('====== n: ' + n + ' lines[n]: ' + lines[n])
|
|
153
|
-
for (let mark of
|
|
136
|
+
for (let mark of markRegKeys) {
|
|
154
137
|
const hasMarkLabel = lines[n].match(markReg[mark])
|
|
155
138
|
if (hasMarkLabel && opt[mark]) {
|
|
156
139
|
//console.log(hasMarkLabel)
|
|
157
140
|
counter[mark]++
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
141
|
+
const labelInfo = getLabelInfo(hasMarkLabel)
|
|
142
|
+
const captionLabel = buildLabel(labelInfo, counter[mark], false)
|
|
143
|
+
lines[n] = lines[n].replace(hasMarkLabel[0], () => captionLabel)
|
|
144
|
+
if (mark === 'img' && shouldSetAlt) {
|
|
145
|
+
const altLabel = buildLabel(labelInfo, counter[mark], true)
|
|
146
|
+
setImageAltNumber(lines, n, counter[mark], altLabel)
|
|
161
147
|
}
|
|
162
148
|
}
|
|
163
149
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peaceroad/markown-figure-num-setting",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Set figure number for p7d-markdown-it-p-captions.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"index.js",
|
|
9
|
+
"README.md",
|
|
10
|
+
"LICENSE"
|
|
11
|
+
],
|
|
7
12
|
"scripts": {
|
|
8
13
|
"test": "node test/test.js"
|
|
9
14
|
},
|
|
@@ -18,6 +23,6 @@
|
|
|
18
23
|
},
|
|
19
24
|
"homepage": "https://github.com/peaceroad/markown-figure-num-setting#readme",
|
|
20
25
|
"dependencies": {
|
|
21
|
-
"p7d-markdown-it-p-captions": "^0.
|
|
26
|
+
"p7d-markdown-it-p-captions": "^0.20.0"
|
|
22
27
|
}
|
|
23
28
|
}
|
|
@@ -1,55 +0,0 @@
|
|
|
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
|
-
図3 キャプション
|
|
22
|
-
|
|
23
|
-

|
|
24
|
-
|
|
25
|
-
図6 キャプション
|
|
26
|
-
|
|
27
|
-

|
|
28
|
-
|
|
29
|
-
[Output]
|
|
30
|
-
図1 キャプション
|
|
31
|
-
|
|
32
|
-

|
|
33
|
-
|
|
34
|
-
図2 キャプション
|
|
35
|
-
|
|
36
|
-

|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
[Input]
|
|
40
|
-
図 キャプション
|
|
41
|
-
|
|
42
|
-

|
|
43
|
-
|
|
44
|
-
図 キャプション
|
|
45
|
-
|
|
46
|
-

|
|
47
|
-
|
|
48
|
-
[Output]
|
|
49
|
-
図1 キャプション
|
|
50
|
-
|
|
51
|
-

|
|
52
|
-
|
|
53
|
-
図2 キャプション
|
|
54
|
-
|
|
55
|
-

|
package/test/examples.txt
DELETED
|
@@ -1,348 +0,0 @@
|
|
|
1
|
-
[Input]
|
|
2
|
-
段落。段落。段落。
|
|
3
|
-
|
|
4
|
-
図 キャプション
|
|
5
|
-
|
|
6
|
-

|
|
7
|
-
|
|
8
|
-
段落。段落。段落。
|
|
9
|
-
|
|
10
|
-
図 キャプション
|
|
11
|
-
|
|
12
|
-

|
|
13
|
-
|
|
14
|
-
段落。段落。段落。
|
|
15
|
-
|
|
16
|
-
[Output]
|
|
17
|
-
段落。段落。段落。
|
|
18
|
-
|
|
19
|
-
図1 キャプション
|
|
20
|
-
|
|
21
|
-

|
|
22
|
-
|
|
23
|
-
段落。段落。段落。
|
|
24
|
-
|
|
25
|
-
図2 キャプション
|
|
26
|
-
|
|
27
|
-

|
|
28
|
-
|
|
29
|
-
段落。段落。段落。
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
[Input]
|
|
34
|
-
段落。段落。段落。
|
|
35
|
-
|
|
36
|
-
図1 キャプション
|
|
37
|
-
|
|
38
|
-

|
|
39
|
-
|
|
40
|
-
段落。段落。段落。
|
|
41
|
-
|
|
42
|
-
図3 キャプション
|
|
43
|
-
|
|
44
|
-

|
|
45
|
-
|
|
46
|
-
段落。段落。段落。
|
|
47
|
-
|
|
48
|
-
[Output]
|
|
49
|
-
段落。段落。段落。
|
|
50
|
-
|
|
51
|
-
図1 キャプション
|
|
52
|
-
|
|
53
|
-

|
|
54
|
-
|
|
55
|
-
段落。段落。段落。
|
|
56
|
-
|
|
57
|
-
図2 キャプション
|
|
58
|
-
|
|
59
|
-

|
|
60
|
-
|
|
61
|
-
段落。段落。段落。
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
[Input]
|
|
66
|
-
図 キャプション
|
|
67
|
-
|
|
68
|
-

|
|
69
|
-
|
|
70
|
-
図 キャプション
|
|
71
|
-
|
|
72
|
-

|
|
73
|
-
|
|
74
|
-
[Output]
|
|
75
|
-
図1 キャプション
|
|
76
|
-
|
|
77
|
-

|
|
78
|
-
|
|
79
|
-
図2 キャプション
|
|
80
|
-
|
|
81
|
-

|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
[Input]
|
|
86
|
-

|
|
87
|
-
|
|
88
|
-
図 キャプション
|
|
89
|
-
|
|
90
|
-

|
|
91
|
-
|
|
92
|
-
図 キャプション
|
|
93
|
-
[Output]
|
|
94
|
-

|
|
95
|
-
|
|
96
|
-
図1 キャプション
|
|
97
|
-
|
|
98
|
-

|
|
99
|
-
|
|
100
|
-
図2 キャプション
|
|
101
|
-
|
|
102
|
-
[Input]
|
|
103
|
-
段落。段落。段落。
|
|
104
|
-
|
|
105
|
-
```
|
|
106
|
-
図 キャプション
|
|
107
|
-
|
|
108
|
-

|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
```
|
|
112
|
-
Code. Caption
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
段落。段落。段落。
|
|
116
|
-
|
|
117
|
-
[Output]
|
|
118
|
-
段落。段落。段落。
|
|
119
|
-
|
|
120
|
-
```
|
|
121
|
-
図 キャプション
|
|
122
|
-
|
|
123
|
-

|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
```
|
|
127
|
-
Code. Caption
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
段落。段落。段落。
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
[Input]
|
|
134
|
-
段落。段落。段落。
|
|
135
|
-
|
|
136
|
-
Figure. キャプション
|
|
137
|
-
|
|
138
|
-

|
|
139
|
-
|
|
140
|
-
段落。段落。段落。
|
|
141
|
-
|
|
142
|
-
Figure. キャプション
|
|
143
|
-
|
|
144
|
-

|
|
145
|
-
|
|
146
|
-
段落。段落。段落。
|
|
147
|
-
|
|
148
|
-
[Output]
|
|
149
|
-
段落。段落。段落。
|
|
150
|
-
|
|
151
|
-
Figure 1. キャプション
|
|
152
|
-
|
|
153
|
-

|
|
154
|
-
|
|
155
|
-
段落。段落。段落。
|
|
156
|
-
|
|
157
|
-
Figure 2. キャプション
|
|
158
|
-
|
|
159
|
-

|
|
160
|
-
|
|
161
|
-
段落。段落。段落。
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
[Input]
|
|
165
|
-
図 キャプション
|
|
166
|
-
|
|
167
|
-

|
|
168
|
-
|
|
169
|
-
図 キャプション
|
|
170
|
-
|
|
171
|
-

|
|
172
|
-
|
|
173
|
-
[Output]
|
|
174
|
-
図1 キャプション
|
|
175
|
-
|
|
176
|
-

|
|
177
|
-
|
|
178
|
-
図2 キャプション
|
|
179
|
-
|
|
180
|
-

|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
[Input]
|
|
184
|
-

|
|
185
|
-
|
|
186
|
-
図 キャプション
|
|
187
|
-
|
|
188
|
-

|
|
189
|
-
|
|
190
|
-
図 キャプション
|
|
191
|
-
[Output]
|
|
192
|
-

|
|
193
|
-
|
|
194
|
-
図1 キャプション
|
|
195
|
-
|
|
196
|
-

|
|
197
|
-
|
|
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
|
-
図
|
|
230
|
-
|
|
231
|
-

|
|
232
|
-
|
|
233
|
-
図
|
|
234
|
-
|
|
235
|
-

|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
[Input]
|
|
239
|
-
図
|
|
240
|
-
|
|
241
|
-

|
|
242
|
-
|
|
243
|
-
図
|
|
244
|
-
|
|
245
|
-

|
|
246
|
-
[Output]
|
|
247
|
-
図1
|
|
248
|
-
|
|
249
|
-

|
|
250
|
-
|
|
251
|
-
図2
|
|
252
|
-
|
|
253
|
-

|
|
254
|
-
|
|
255
|
-
[Input]
|
|
256
|
-
図
|
|
257
|
-
|
|
258
|
-

|
|
259
|
-
|
|
260
|
-
図
|
|
261
|
-
|
|
262
|
-

|
|
263
|
-
[Output]
|
|
264
|
-
図1
|
|
265
|
-
|
|
266
|
-

|
|
267
|
-
|
|
268
|
-
図2
|
|
269
|
-
|
|
270
|
-

|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
[Input]
|
|
274
|
-
段落。段落。段落。段落。段落。段落。段落。段落。段落。
|
|
275
|
-
|
|
276
|
-
図1 キャプション
|
|
277
|
-
|
|
278
|
-

|
|
279
|
-
|
|
280
|
-
段落。段落。段落。段落。段落。段落。段落。段落。段落。
|
|
281
|
-
|
|
282
|
-
図2 キャプション
|
|
283
|
-
|
|
284
|
-

|
|
285
|
-
|
|
286
|
-
段落。段落。段落。段落。段落。段落。段落。段落。段落。
|
|
287
|
-
|
|
288
|
-
図 キャプション
|
|
289
|
-
|
|
290
|
-

|
|
291
|
-
|
|
292
|
-
段落。段落。段落。段落。段落。段落。段落。段落。段落。
|
|
293
|
-
|
|
294
|
-
図2 キャプション
|
|
295
|
-
|
|
296
|
-

|
|
297
|
-
|
|
298
|
-
段落。段落。段落。段落。段落。段落。段落。段落。段落。
|
|
299
|
-
|
|
300
|
-
図 キャプション
|
|
301
|
-
|
|
302
|
-

|
|
303
|
-
|
|
304
|
-
段落。段落。段落。段落。段落。段落。段落。段落。段落。
|
|
305
|
-
|
|
306
|
-
図2 キャプション
|
|
307
|
-
|
|
308
|
-

|
|
309
|
-
|
|
310
|
-
段落。段落。段落。段落。段落。段落。段落。段落。段落。
|
|
311
|
-
[Output]
|
|
312
|
-
段落。段落。段落。段落。段落。段落。段落。段落。段落。
|
|
313
|
-
|
|
314
|
-
図1 キャプション
|
|
315
|
-
|
|
316
|
-

|
|
317
|
-
|
|
318
|
-
段落。段落。段落。段落。段落。段落。段落。段落。段落。
|
|
319
|
-
|
|
320
|
-
図2 キャプション
|
|
321
|
-
|
|
322
|
-

|
|
323
|
-
|
|
324
|
-
段落。段落。段落。段落。段落。段落。段落。段落。段落。
|
|
325
|
-
|
|
326
|
-
図3 キャプション
|
|
327
|
-
|
|
328
|
-

|
|
329
|
-
|
|
330
|
-
段落。段落。段落。段落。段落。段落。段落。段落。段落。
|
|
331
|
-
|
|
332
|
-
図4 キャプション
|
|
333
|
-
|
|
334
|
-

|
|
335
|
-
|
|
336
|
-
段落。段落。段落。段落。段落。段落。段落。段落。段落。
|
|
337
|
-
|
|
338
|
-
図5 キャプション
|
|
339
|
-
|
|
340
|
-

|
|
341
|
-
|
|
342
|
-
段落。段落。段落。段落。段落。段落。段落。段落。段落。
|
|
343
|
-
|
|
344
|
-
図6 キャプション
|
|
345
|
-
|
|
346
|
-

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