@peaceroad/markown-figure-num-setting 0.1.2 → 0.1.3

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/index.js CHANGED
@@ -111,47 +111,55 @@ const setMarkdownFigureNum = (markdown, option) => {
111
111
 
112
112
 
113
113
  const setImageAltNumber = (lines, n, mark, hasMarkLabel, counter) => {
114
+ let hasPrevFigureImage = false
114
115
  let isFigureImage
115
- const isFigureImageReg = /^([ \t]*\!\[) *?(.*?([0-9]*)) *?(\]\(.*?\))/
116
- let hasPrevCaption
116
+ const figureImageReg = /^([ \t]*\!\[) *?(.*?([0-9]*)) *?(\]\(.*?\))/
117
117
  let i
118
118
  i = n - 1
119
+ //console.log('lines[n]: ' + lines[n])
120
+ //console.log('CheckPrevLine')
119
121
  while (i >= 0) {
120
122
  if (/^[ \t]*$/.test(lines[i])) {
121
123
  i--
122
124
  continue
123
125
  }
124
- isFigureImage = lines[i].match(new RegExp(isFigureImageReg))
125
- if (isFigureImage) {
126
- let j = i - 1
127
- while (j >= 0) {
128
- if (/^[ \t]*$/.test(lines[j])) {
129
- j--
130
- continue
131
- }
132
- if (lines[j].match(new RegExp(isFigureImageReg[2]))) {
133
- hasPrevCaption = true
134
- }
135
- if (!hasPrevCaption) {
136
- lines[i] = lines[i].replace(new RegExp(isFigureImageReg), '$1' + label(hasMarkLabel, counter[mark], true) + '$4')
137
- }
126
+ isFigureImage = lines[i].match(new RegExp(figureImageReg))
127
+ if (!isFigureImage) break
128
+ //console.log(isFigureImage)
129
+
130
+ let j = i
131
+ while (j >= 0) {
132
+ if (/^[ \t]*$/.test(lines[j])) {
133
+ j--
134
+ continue
135
+ }
136
+ //console.log(isFigureImage[3], (counter.img - 1).toString())
137
+ if (isFigureImage[3] === (counter.img - 1).toString()) {
138
+ hasPrevFigureImage = false
138
139
  break
139
140
  }
141
+ lines[i] = lines[i].replace(new RegExp(figureImageReg), '$1' + label(hasMarkLabel, counter[mark], true) + '$4')
142
+ //console.log('ChangePrevLine: ' + lines[i])
143
+ hasPrevFigureImage = true
144
+ break
140
145
  }
141
146
  break
142
147
  }
143
148
 
144
- if (isFigureImage) return
149
+ if (hasPrevFigureImage) return
145
150
 
151
+ //console.log('CheckNextLine')
146
152
  i = n + 1
147
153
  while (i < lines.length) {
148
154
  if (/^[\t ]*$/.test(lines[i])) {
149
155
  i++
150
156
  continue
151
157
  }
152
- isFigureImage = lines[i].match(new RegExp(isFigureImageReg))
158
+ isFigureImage = lines[i].match(new RegExp(figureImageReg))
159
+ //console.log(isFigureImage)
153
160
  if (isFigureImage) {
154
- lines[i] = lines[i].replace(new RegExp(isFigureImageReg), '$1' + label(hasMarkLabel, counter[mark], true) + '$4')
161
+ lines[i] = lines[i].replace(new RegExp(figureImageReg), '$1' + label(hasMarkLabel, counter[mark], true) + '$4')
162
+ //console.log('ChangeNextLine: ' + lines[i])
155
163
  }
156
164
  break
157
165
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peaceroad/markown-figure-num-setting",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Set figure number for p7d-markdown-it-p-captions.",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/test/examples.txt CHANGED
@@ -161,3 +161,38 @@ Figure 2. キャプション
161
161
  段落。段落。段落。
162
162
 
163
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 キャプション
package/test/test.js CHANGED
@@ -33,7 +33,7 @@ while(n < ms0.length) {
33
33
 
34
34
  n = 1;
35
35
  while(n < ms.length) {
36
- //if (n !== 1) { n++; continue }
36
+ //if (n !== 8) { n++; continue }
37
37
  console.log('Test: ' + n + ' >>>')
38
38
  const m = ms[n].inputMarkdown
39
39
  const h = setMarkdownFigureNum(m)