@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 +27 -19
- package/package.json +1 -1
- package/test/examples.txt +35 -0
- package/test/test.js +1 -1
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
|
|
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(
|
|
125
|
-
if (isFigureImage)
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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 (
|
|
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(
|
|
158
|
+
isFigureImage = lines[i].match(new RegExp(figureImageReg))
|
|
159
|
+
//console.log(isFigureImage)
|
|
153
160
|
if (isFigureImage) {
|
|
154
|
-
lines[i] = lines[i].replace(new RegExp(
|
|
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
package/test/examples.txt
CHANGED
|
@@ -161,3 +161,38 @@ Figure 2. キャプション
|
|
|
161
161
|
段落。段落。段落。
|
|
162
162
|
|
|
163
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 キャプション
|
package/test/test.js
CHANGED