@peaceroad/markown-figure-num-setting 0.1.4 → 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 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
- ![](image.jpg)
17
+ ![A alt text.](image.jpg)
18
18
 
19
- 段落。段落。段落。
19
+ Paragraph.
20
20
 
21
- キャプション
21
+ Figure. A Caption
22
22
 
23
- ![](image.jpg)
23
+ ![A alt text.](image.jpg)
24
24
 
25
- 段落。段落。段落。
25
+ Paragraph.
26
26
 
27
27
  [Output]
28
- 段落。段落。段落。
29
-
30
- 図1 キャプション
28
+ Paragraph.
31
29
 
32
- ![図1](image.jpg)
30
+ Figure 1. A Caption
33
31
 
34
- 段落。段落。段落。
32
+ ![A alt text.](image.jpg)
35
33
 
36
- 図2 キャプション
34
+ Paragraph.
37
35
 
38
- ![図2](image.jpg)
36
+ Figure 2. A Caption
39
37
 
40
- 段落。段落。段落。
38
+ ![A alt text.](image.jpg)
41
39
 
40
+ Paragraph.
42
41
 
43
42
 
44
43
  [Input]
45
- 段落。段落。段落。
44
+ Paragraph.
46
45
 
47
- 1 キャプション
46
+ Figure 1. A Caption
48
47
 
49
- ![](image.jpg)
48
+ ![A alt text.](image.jpg)
50
49
 
51
- 段落。段落。段落。
50
+ Paragraph.
52
51
 
53
- 図2 キャプション
52
+ Figure 1. A Caption
54
53
 
55
- ![](image.jpg)
54
+ ![A alt text.](image.jpg)
56
55
 
57
- 段落。段落。段落。
56
+ Paragraph.
58
57
 
59
58
  [Output]
60
- 段落。段落。段落。
59
+ Paragraph.
61
60
 
62
- 1 キャプション
61
+ Figure 1. A Caption
63
62
 
64
- ![図1](image.jpg)
63
+ ![A alt text.](image.jpg)
65
64
 
66
- 段落。段落。段落。
65
+ Paragraph.
67
66
 
68
- 2 キャプション
67
+ Figure 2. A Caption
69
68
 
70
- ![図2](image.jpg)
69
+ ![A alt text.](image.jpg)
71
70
 
72
- 段落。段落。段落。
71
+ Paragraph.
73
72
 
74
73
 
75
74
  [Input]
76
75
  段落。段落。段落。
77
76
 
78
- Figure. キャプション
77
+ キャプション
79
78
 
80
- ![](image.jpg)
79
+ ![A alt text.](image.jpg)
81
80
 
82
81
  段落。段落。段落。
83
82
 
84
- Figure. キャプション
83
+ キャプション
85
84
 
86
- ![](image.jpg)
85
+ ![A alt text.](image.jpg)
87
86
 
88
87
  段落。段落。段落。
89
88
 
90
89
  [Output]
91
90
  段落。段落。段落。
92
91
 
93
- Figure1. キャプション
92
+ 図1 キャプション
94
93
 
95
- ![Figure 1](image.jpg)
94
+ ![A alt text.](image.jpg)
96
95
 
97
96
  段落。段落。段落。
98
97
 
99
- Figure 2. キャプション
98
+ 2 キャプション
100
99
 
101
- ![Figure 2](image.jpg)
100
+ ![A alt text.](image.jpg)
102
101
 
103
102
  段落。段落。段落。
104
103
  ```
@@ -106,8 +105,11 @@ Figure 2. キャプション
106
105
 
107
106
  ## Option
108
107
 
109
- ### noSetAlt
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
- ![ALT-A](image.jpg)
125
+ ![図1](image.jpg)
124
126
 
125
127
  図2 キャプション
126
128
 
127
- ![ALT-B](image.jpg)
129
+ ![図2](image.jpg)
130
+ ```
package/index.js CHANGED
@@ -1,179 +1,89 @@
1
- const setMarkdownFigureNum = (markdown, option) => {
2
-
3
- let opt = {
4
- img: true,
5
- table: false,
6
- code: false,
7
- samp: false,
8
- blockquote: false,
9
- slide: false,
10
- noSetAlt: false,
11
- setImgAlt: false,
1
+ import { markReg as markRegEx, joint as jointStr } from "p7d-markdown-it-p-captions"
2
+
3
+
4
+ const markReg = markRegEx
5
+ const markRegKeys = Object.keys(markReg)
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]*)) *?(\]\(.*?\))/
11
+ //console.log(markReg)
12
+ //console.log(joint)
13
+
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),
12
25
  }
13
- opt["pre-code"] = opt.code
14
- opt["pre-samp"] = opt.samp
15
- if (option !== undefined) {
16
- for (let o in option) {
17
- opt[o] = option[o];
18
- }
19
- }
20
-
21
-
22
- const markAfterNum = '[A-Z0-9]{1,6}(?:[.-][A-Z0-9]{1,6}){0,5}';
23
- const joint = '[.:.。: ]';
24
- const jointFullWidth = '[.。: ]';
25
- const jointHalfWidth = '[.:]';
26
-
27
- const markAfterEn = '(?:' +
28
- ' *(?:' +
29
- jointHalfWidth + '(?:(?=[ ]+)|$)|' +
30
- jointFullWidth + '|' +
31
- '(?=[ ]+[^0-9a-zA-Z])' +
32
- ')|' +
33
- ' *' + '(' + markAfterNum + ')(?:' +
34
- jointHalfWidth + '(?:(?=[ ]+)|$)|' +
35
- jointFullWidth + '|' +
36
- '(?=[ ]+[^a-z])|$' +
37
- ')|' +
38
- '[.](' + markAfterNum + ')(?:' +
39
- joint + '|(?=[ ]+[^a-z])|$' +
40
- ')|' +
41
- '[  ]*$' +
42
- ')';
43
-
44
- const markAfterJa = '(?:' +
45
- ' *(?:' +
46
- jointHalfWidth + '(?:(?=[ ]+)|$)|' +
47
- jointFullWidth + '|' +
48
- '(?=[ ]+)' +
49
- ')|' +
50
- ' *' + '(' + markAfterNum + ')(?:' +
51
- jointHalfWidth + '(?:(?=[ ]+)|$)|' +
52
- jointFullWidth + '|' +
53
- '(?=[ ]+)|$' +
54
- ')|' +
55
- '[  ]*$' +
56
- ')';
57
-
58
- const markReg = {
59
- //fig(ure)?, illust, photo
60
- "img": new RegExp('^(?:' +
61
- '(?:[fF][iI][gG](?:[uU][rR][eE])?|[iI][lL]{2}[uU][sS][tT]|[pP][hH][oO][tT][oO])'+ markAfterEn + '|' +
62
- '(?:図|イラスト|写真)' + markAfterJa +
63
- ')'),
64
- //movie, video
65
- "video": new RegExp('^(?:' +
66
- '(?:[mM][oO][vV][iI][eE]|[vV][iI][dD][eE][oO])'+ markAfterEn + '|' +
67
- '(?:動画|ビデオ)' + markAfterJa +
68
- ')'),
69
- //table
70
- "table": new RegExp('^(?:' +
71
- '(?:[tT][aA][bB][lL][eE])'+ markAfterEn + '|' +
72
- '(?:表)' + markAfterJa +
73
- ')'),
74
- //code(block)?, program
75
- "pre-code": new RegExp('^(?:' +
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 + '|' +
77
- '(?:(?:ソース)?コード|リスト|命令|プログラム|算譜|アルゴリズム|算法)' + markAfterJa +
78
- ')'),
79
- //terminal, prompt, command
80
- "pre-samp": new RegExp('^(?:' +
81
- '(?:[cC][oO][nN][sS][oO][lL][eE]|[tT][eE][rR][mM][iI][nN][aA][lL]|[pP][rR][oO][mM][pP][tT]|[cC][oO][mM]{2}[aA][nN][dD])'+ markAfterEn + '|' +
82
- '(?:端末|ターミナル|コマンド|(?:コマンド)?プロンプト)' + markAfterJa +
83
- ')'),
84
- //quote, blockquote, source
85
- "blockquote": new RegExp('^(?:' +
86
- '(?:(?:[bB][lL][oO][cC][kK])?[qQ][uU][oO][tT][eE]|[sS][oO][uU][rR][cC][eE])'+ markAfterEn + '|' +
87
- '(?:引用(?:元)?|出典)' + markAfterJa +
88
- ')'),
89
- //slide
90
- "slide": new RegExp('^(?:' +
91
- '(?:[sS][lL][iI][dD][eE])'+ markAfterEn + '|' +
92
- '(?:スライド)' + markAfterJa +
93
- ')')
94
- };
95
-
96
- const label = (hasMarkLabel, counter, isAlt) => {
97
-
98
- let label = hasMarkLabel[0]
99
- let LabelIsEn = /[a-zA-Z]/.test(label)
100
- let spaceBeforeCounter = ''
101
- if (LabelIsEn) {
102
- spaceBeforeCounter = ' '
103
- }
104
-
105
- if (hasMarkLabel[3]) {
106
- label = hasMarkLabel[0].replace(new RegExp(hasMarkLabel[3] + '$'), '')
107
- }
108
- let isLabelLastJoint = label.match(new RegExp('(' + joint +')$'))
26
+ }
109
27
 
110
- if (isLabelLastJoint) {
111
- if (isAlt) {
112
- label = label.replace(new RegExp(joint +'$'), '') + spaceBeforeCounter + counter
113
- } else {
114
- label = label.replace(new RegExp(joint +'$'), '') + spaceBeforeCounter + counter + isLabelLastJoint[1]
115
- }
116
- } else {
117
- label += counter
118
- }
119
- return label
28
+ const buildLabel = (labelInfo, counter, isAlt) => {
29
+ let label = labelInfo.markLabel + (labelInfo.needsSpace ? ' ' : '') + counter
30
+ if (!isAlt && labelInfo.joint) {
31
+ label += labelInfo.joint
120
32
  }
33
+ return label
34
+ }
121
35
 
122
36
 
123
- const setImageAltNumber = (lines, n, mark, hasMarkLabel, counter) => {
124
- let hasPrevFigureImage = false
125
- let isFigureImage
126
- const figureImageReg = /^([ \t]*\!\[) *?(.*?([0-9]*)) *?(\]\(.*?\))/
127
- let i
128
- i = n - 1
129
- //console.log('lines[n]: ' + lines[n])
130
- //console.log('CheckPrevLine')
131
- while (i >= 0) {
132
- if (/^[ \t]*$/.test(lines[i])) {
133
- i--
134
- continue
135
- }
136
- isFigureImage = lines[i].match(new RegExp(figureImageReg))
137
- if (!isFigureImage) break
138
-
139
- let j = i
140
- while (j >= 0) {
141
- if (/^[ \t]*$/.test(lines[j])) {
142
- j--
143
- continue
144
- }
145
- //console.log(isFigureImage[3], (counter.img - 1).toString())
146
- if (isFigureImage[3] === (counter.img - 1).toString()) {
147
- hasPrevFigureImage = false
148
- break
149
- }
150
- 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')
151
51
  //console.log('ChangePrevLine: ' + lines[i])
152
- hasPrevFigureImage = true
153
- break
52
+ return
154
53
  }
155
- break
156
54
  }
55
+ }
157
56
 
158
- if (hasPrevFigureImage) return
159
-
160
- //console.log('CheckNextLine')
161
- i = n + 1
162
- while (i < lines.length) {
163
- if (/^[\t ]*$/.test(lines[i])) {
164
- i++
165
- continue
166
- }
167
- isFigureImage = lines[i].match(new RegExp(figureImageReg))
168
- //console.log(isFigureImage)
169
- if (isFigureImage) {
170
- lines[i] = lines[i].replace(new RegExp(figureImageReg), '$1' + label(hasMarkLabel, counter[mark], true) + '$4')
171
- //console.log('ChangeNextLine: ' + lines[i])
172
- }
173
- 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])
174
68
  }
175
- return
176
69
  }
70
+ return
71
+ }
72
+
73
+ const setMarkdownFigureNum = (markdown, option) => {
74
+ let opt = {
75
+ img: true,
76
+ table: false,
77
+ 'pre-code': false,
78
+ 'pre-samp': false,
79
+ blockquote: false,
80
+ slide: false,
81
+ noSetAlt: true,
82
+ setNumberAlt: false,
83
+ setImgAlt: false,
84
+ }
85
+ if (option) Object.assign(opt, option)
86
+ const shouldSetAlt = opt.setNumberAlt || opt.setImgAlt || opt.noSetAlt === false
177
87
 
178
88
  let n = 0
179
89
  let lines = []
@@ -187,11 +97,11 @@ const setMarkdownFigureNum = (markdown, option) => {
187
97
  slide: 0,
188
98
  }
189
99
 
190
-
191
100
  lines = markdown.split(/\r\n|\n/)
192
101
  lineBreaks = markdown.match(/\r\n|\n/g);
193
102
  let isBackquoteCodeBlock = false
194
103
  let isTildeCodeBlock = false
104
+ let isMathBlock = false
195
105
 
196
106
  if(lines.length === 0) return markdown
197
107
 
@@ -210,20 +120,30 @@ const setMarkdownFigureNum = (markdown, option) => {
210
120
  isTildeCodeBlock = true
211
121
  }
212
122
  }
213
- if (isBackquoteCodeBlock || isTildeCodeBlock) {
123
+ if (lines[n].match(/^ *\$\$/)) {
124
+ if (isMathBlock) {
125
+ isMathBlock = false
126
+ } else {
127
+ isMathBlock = true
128
+ }
129
+ }
130
+ if (isBackquoteCodeBlock || isTildeCodeBlock || isMathBlock) {
214
131
  n++
215
132
  continue
216
133
  }
217
134
 
218
- for (let mark of Object.keys(markReg)) {
135
+ //console.log('====== n: ' + n + ' lines[n]: ' + lines[n])
136
+ for (let mark of markRegKeys) {
219
137
  const hasMarkLabel = lines[n].match(markReg[mark])
220
- //if (hasMarkLabel) console.log(hasMarkLabel)
221
138
  if (hasMarkLabel && opt[mark]) {
139
+ //console.log(hasMarkLabel)
222
140
  counter[mark]++
223
- //console.log('lines[n]: ' + lines[n])
224
- lines[n] = lines[n].replace(new RegExp('^([ \t]*)' + hasMarkLabel[0]), '$1' + label(hasMarkLabel, counter[mark]))
225
- if (mark === 'img' && !opt.noSetAlt) {
226
- setImageAltNumber(lines, n, mark, hasMarkLabel, counter)
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)
227
147
  }
228
148
  }
229
149
  }
package/package.json CHANGED
@@ -1,9 +1,14 @@
1
1
  {
2
2
  "name": "@peaceroad/markown-figure-num-setting",
3
- "version": "0.1.4",
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
  },
@@ -16,5 +21,8 @@
16
21
  "bugs": {
17
22
  "url": "https://github.com/peaceroad/markown-figure-num-setting/issues"
18
23
  },
19
- "homepage": "https://github.com/peaceroad/markown-figure-num-setting#readme"
24
+ "homepage": "https://github.com/peaceroad/markown-figure-num-setting#readme",
25
+ "dependencies": {
26
+ "p7d-markdown-it-p-captions": "^0.20.0"
27
+ }
20
28
  }
@@ -1,36 +0,0 @@
1
- [Input]
2
- 図 キャプション
3
-
4
- ![ALT-A](image.jpg)
5
-
6
- 図 キャプション
7
-
8
- ![ALT-B](image.jpg)
9
-
10
- [Output]
11
- 図1 キャプション
12
-
13
- ![ALT-A](image.jpg)
14
-
15
- 図2 キャプション
16
-
17
- ![ALT-B](image.jpg)
18
-
19
-
20
- [Input]
21
-
22
-
23
- ![ALT-A](image.jpg)
24
-
25
-
26
-
27
- ![ALT-B](image.jpg)
28
-
29
- [Output]
30
- 図1
31
-
32
- ![ALT-A](image.jpg)
33
-
34
- 図2
35
-
36
- ![ALT-B](image.jpg)
package/test/examples.txt DELETED
@@ -1,330 +0,0 @@
1
- [Input]
2
- 段落。段落。段落。
3
-
4
- 図 キャプション
5
-
6
- ![](image.jpg)
7
-
8
- 段落。段落。段落。
9
-
10
- 図 キャプション
11
-
12
- ![](image.jpg)
13
-
14
- 段落。段落。段落。
15
-
16
- [Output]
17
- 段落。段落。段落。
18
-
19
- 図1 キャプション
20
-
21
- ![図1](image.jpg)
22
-
23
- 段落。段落。段落。
24
-
25
- 図2 キャプション
26
-
27
- ![図2](image.jpg)
28
-
29
- 段落。段落。段落。
30
-
31
-
32
-
33
- [Input]
34
- 段落。段落。段落。
35
-
36
- 図1 キャプション
37
-
38
- ![](image.jpg)
39
-
40
- 段落。段落。段落。
41
-
42
- 図3 キャプション
43
-
44
- ![](image.jpg)
45
-
46
- 段落。段落。段落。
47
-
48
- [Output]
49
- 段落。段落。段落。
50
-
51
- 図1 キャプション
52
-
53
- ![図1](image.jpg)
54
-
55
- 段落。段落。段落。
56
-
57
- 図2 キャプション
58
-
59
- ![図2](image.jpg)
60
-
61
- 段落。段落。段落。
62
-
63
-
64
-
65
- [Input]
66
- 図 キャプション
67
-
68
- ![図1](image.jpg)
69
-
70
- 図 キャプション
71
-
72
- ![図2](image.jpg)
73
-
74
- [Output]
75
- 図1 キャプション
76
-
77
- ![図1](image.jpg)
78
-
79
- 図2 キャプション
80
-
81
- ![図2](image.jpg)
82
-
83
-
84
-
85
- [Input]
86
- ![図1](image.jpg)
87
-
88
- 図 キャプション
89
-
90
- ![図2](image.jpg)
91
-
92
- 図 キャプション
93
- [Output]
94
- ![図1](image.jpg)
95
-
96
- 図1 キャプション
97
-
98
- ![図2](image.jpg)
99
-
100
- 図2 キャプション
101
-
102
- [Input]
103
- 段落。段落。段落。
104
-
105
- ```
106
- 図 キャプション
107
-
108
- ![図1](image.jpg)
109
- ```
110
-
111
- ```
112
- Code. Caption
113
- ```
114
-
115
- 段落。段落。段落。
116
-
117
- [Output]
118
- 段落。段落。段落。
119
-
120
- ```
121
- 図 キャプション
122
-
123
- ![図1](image.jpg)
124
- ```
125
-
126
- ```
127
- Code. Caption
128
- ```
129
-
130
- 段落。段落。段落。
131
-
132
-
133
- [Input]
134
- 段落。段落。段落。
135
-
136
- Figure. キャプション
137
-
138
- ![](image.jpg)
139
-
140
- 段落。段落。段落。
141
-
142
- Figure. キャプション
143
-
144
- ![](image.jpg)
145
-
146
- 段落。段落。段落。
147
-
148
- [Output]
149
- 段落。段落。段落。
150
-
151
- Figure 1. キャプション
152
-
153
- ![Figure 1](image.jpg)
154
-
155
- 段落。段落。段落。
156
-
157
- Figure 2. キャプション
158
-
159
- ![Figure 2](image.jpg)
160
-
161
- 段落。段落。段落。
162
-
163
-
164
- [Input]
165
- 図 キャプション
166
-
167
- ![](image.jpg)
168
-
169
- 図 キャプション
170
-
171
- ![](image.jpg)
172
-
173
- [Output]
174
- 図1 キャプション
175
-
176
- ![図1](image.jpg)
177
-
178
- 図2 キャプション
179
-
180
- ![図2](image.jpg)
181
-
182
-
183
- [Input]
184
- ![](image.jpg)
185
-
186
- 図 キャプション
187
-
188
- ![](image.jpg)
189
-
190
- 図 キャプション
191
- [Output]
192
- ![図1](image.jpg)
193
-
194
- 図1 キャプション
195
-
196
- ![図2](image.jpg)
197
-
198
- 図2 キャプション
199
-
200
-
201
-
202
- [Input]
203
-
204
-
205
- ![](image.jpg)
206
-
207
-
208
-
209
- ![](image.jpg)
210
- [Output]
211
- 図1
212
-
213
- ![図1](image.jpg)
214
-
215
- 図2
216
-
217
- ![図2](image.jpg)
218
-
219
-
220
- [Input]
221
- 図 
222
-
223
- ![](image.jpg)
224
-
225
- 図 
226
-
227
- ![](image.jpg)
228
- [Output]
229
- 図1 
230
-
231
- ![図1](image.jpg)
232
-
233
- 図2 
234
-
235
- ![図2](image.jpg)
236
-
237
- [Input]
238
-
239
-
240
- ![](image.jpg)
241
-
242
-
243
-
244
- ![](image.jpg)
245
- [Output]
246
- 図1
247
-
248
- ![図1](image.jpg)
249
-
250
- 図2
251
-
252
- ![図2](image.jpg)
253
-
254
-
255
- [Input]
256
- 段落。段落。段落。段落。段落。段落。段落。段落。段落。
257
-
258
- 図1
259
-
260
- ![図1](Src)
261
-
262
- 段落。段落。段落。段落。段落。段落。段落。段落。段落。
263
-
264
- 図2
265
-
266
- ![図2](Src)
267
-
268
- 段落。段落。段落。段落。段落。段落。段落。段落。段落。
269
-
270
-
271
-
272
- ![図](Src)
273
-
274
- 段落。段落。段落。段落。段落。段落。段落。段落。段落。
275
-
276
- 図2
277
-
278
- ![図2](Src)
279
-
280
- 段落。段落。段落。段落。段落。段落。段落。段落。段落。
281
-
282
-
283
-
284
- ![図](Src)
285
-
286
- 段落。段落。段落。段落。段落。段落。段落。段落。段落。
287
-
288
- 図2
289
-
290
- ![図2](Src)
291
-
292
- 段落。段落。段落。段落。段落。段落。段落。段落。段落。
293
- [Output]
294
- 段落。段落。段落。段落。段落。段落。段落。段落。段落。
295
-
296
- 図1
297
-
298
- ![図1](Src)
299
-
300
- 段落。段落。段落。段落。段落。段落。段落。段落。段落。
301
-
302
- 図2
303
-
304
- ![図2](Src)
305
-
306
- 段落。段落。段落。段落。段落。段落。段落。段落。段落。
307
-
308
- 図3
309
-
310
- ![図3](Src)
311
-
312
- 段落。段落。段落。段落。段落。段落。段落。段落。段落。
313
-
314
- 図4
315
-
316
- ![図4](Src)
317
-
318
- 段落。段落。段落。段落。段落。段落。段落。段落。段落。
319
-
320
- 図5
321
-
322
- ![図5](Src)
323
-
324
- 段落。段落。段落。段落。段落。段落。段落。段落。段落。
325
-
326
- 図6
327
-
328
- ![図6](Src)
329
-
330
- 段落。段落。段落。段落。段落。段落。段落。段落。段落。
package/test/test.js DELETED
@@ -1,71 +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
- 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++
28
- }
29
- ms[n] = {
30
- inputMarkdown: mhs[0].trim(),
31
- outputMarkdown: mhs[1].trim(),
32
- };
33
- n++
34
- }
35
-
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++
60
- }
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
-