@peaceroad/markdown-it-numbering-ul-regarded-as-ol 0.1.0
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/LICENSE +21 -0
- package/README.md +214 -0
- package/index.js +403 -0
- package/listTypes.json +57 -0
- package/package.json +19 -0
- package/test/examples.md +0 -0
- package/test/examples.txt +201 -0
- package/test/test.js +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 k_taka
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
# p7d-markdown-it-numbering-ul-regarded-as-ol
|
|
2
|
+
|
|
3
|
+
This regard ul element with numbering lists as ol element.
|
|
4
|
+
|
|
5
|
+
Input Markdown:
|
|
6
|
+
|
|
7
|
+
```markdown
|
|
8
|
+
- i. a
|
|
9
|
+
- ii. b
|
|
10
|
+
- iii. c
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Output HTML:
|
|
14
|
+
|
|
15
|
+
```html
|
|
16
|
+
<ol type="i" class="ol-lower-roman">
|
|
17
|
+
<li aria-label="i">a</li>
|
|
18
|
+
<li aria-label="ii">b</li>
|
|
19
|
+
<li aria-label="iii">c</li>
|
|
20
|
+
</ol>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Notice. HTML output is still unstable.
|
|
24
|
+
|
|
25
|
+
## Install
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
npm i @peacroad/markdown-it-numbering-ul-regarded-as-ol
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Example
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
[Markdown]
|
|
35
|
+
1. a
|
|
36
|
+
2. b
|
|
37
|
+
3. c
|
|
38
|
+
[HTML]
|
|
39
|
+
<ol class="ol-decimal">
|
|
40
|
+
<li>a</li>
|
|
41
|
+
<li>b</li>
|
|
42
|
+
<li>c</li>
|
|
43
|
+
</ol>
|
|
44
|
+
|
|
45
|
+
[Markdown]
|
|
46
|
+
3. a
|
|
47
|
+
4. b
|
|
48
|
+
5. c
|
|
49
|
+
[HTML]
|
|
50
|
+
<ol start="3" class="ol-decimal">
|
|
51
|
+
<li>a</li>
|
|
52
|
+
<li>b</li>
|
|
53
|
+
<li>c</li>
|
|
54
|
+
</ol>
|
|
55
|
+
|
|
56
|
+
[Markdown]
|
|
57
|
+
1. a
|
|
58
|
+
3. b
|
|
59
|
+
4. c
|
|
60
|
+
[HTML]
|
|
61
|
+
<ol class="ol-decimal">
|
|
62
|
+
<li>a</li>
|
|
63
|
+
<li value="3">b</li>
|
|
64
|
+
<li>c</li>
|
|
65
|
+
</ol>
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
[Markdown]
|
|
69
|
+
- i. a
|
|
70
|
+
- ii. b
|
|
71
|
+
- iii. c
|
|
72
|
+
[HTML]
|
|
73
|
+
<ol type="i" class="ol-lower-roman">
|
|
74
|
+
<li aria-label="i">a</li>
|
|
75
|
+
<li aria-label="ii">b</li>
|
|
76
|
+
<li aria-label="iii">c</li>
|
|
77
|
+
</ol>
|
|
78
|
+
|
|
79
|
+
[Markdown]
|
|
80
|
+
- a
|
|
81
|
+
- b
|
|
82
|
+
- c
|
|
83
|
+
[HTML]
|
|
84
|
+
<ul>
|
|
85
|
+
<li>a</li>
|
|
86
|
+
<li>b</li>
|
|
87
|
+
<li>c</li>
|
|
88
|
+
</ul>
|
|
89
|
+
|
|
90
|
+
[Markdown]
|
|
91
|
+
- ❶ a
|
|
92
|
+
- ❷ b
|
|
93
|
+
- ❸ c
|
|
94
|
+
[HTML]
|
|
95
|
+
<ol role="list" class="ol-filled-circled-decimal">
|
|
96
|
+
<li aria-label="❶">a</li>
|
|
97
|
+
<li aria-label="❷">b</li>
|
|
98
|
+
<li aria-label="❸">c</li>
|
|
99
|
+
</ol>
|
|
100
|
+
|
|
101
|
+
[Markdown]
|
|
102
|
+
2. a
|
|
103
|
+
3. b
|
|
104
|
+
4. c
|
|
105
|
+
[HTML]
|
|
106
|
+
<ol start="2" class="ol-decimal">
|
|
107
|
+
<li>a</li>
|
|
108
|
+
<li>b</li>
|
|
109
|
+
<li>c</li>
|
|
110
|
+
</ol>
|
|
111
|
+
|
|
112
|
+
[Markdown]
|
|
113
|
+
- ② a
|
|
114
|
+
- ③ b
|
|
115
|
+
- ④ c
|
|
116
|
+
[HTML]
|
|
117
|
+
<ol start="2" role="list" class="ol-circled-decimal">
|
|
118
|
+
<li aria-label="②">a</li>
|
|
119
|
+
<li aria-label="③">b</li>
|
|
120
|
+
<li aria-label="④">c</li>
|
|
121
|
+
</ol>
|
|
122
|
+
|
|
123
|
+
[Markdown]
|
|
124
|
+
- (2). a
|
|
125
|
+
- (3). b
|
|
126
|
+
- (4). c
|
|
127
|
+
[HTML]
|
|
128
|
+
<ol start="2" role="list" class="ol-decimal-with-round-round">
|
|
129
|
+
<li aria-label="(2)">a</li>
|
|
130
|
+
<li aria-label="(3)">b</li>
|
|
131
|
+
<li aria-label="(4)">c</li>
|
|
132
|
+
</ol>
|
|
133
|
+
|
|
134
|
+
[Markdown]
|
|
135
|
+
- 2). a
|
|
136
|
+
- 3). b
|
|
137
|
+
- 4). c
|
|
138
|
+
[HTML]
|
|
139
|
+
<ol start="2" role="list" class="ol-decimal-with-none-round">
|
|
140
|
+
<li aria-label="2)">a</li>
|
|
141
|
+
<li aria-label="3)">b</li>
|
|
142
|
+
<li aria-label="4)">c</li>
|
|
143
|
+
</ol>
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
[Markdown]
|
|
147
|
+
1. 項目1
|
|
148
|
+
2. 項目2
|
|
149
|
+
- i. 項目2-i
|
|
150
|
+
- ii. 項目2-ii
|
|
151
|
+
- iii. 項目2-iii
|
|
152
|
+
3. 項目3
|
|
153
|
+
[HTML]
|
|
154
|
+
<ol class="ol-decimal">
|
|
155
|
+
<li>項目1</li>
|
|
156
|
+
<li>項目2
|
|
157
|
+
<ol type="i" class="ol-lower-roman">
|
|
158
|
+
<li aria-label="i">項目2-i</li>
|
|
159
|
+
<li aria-label="ii">項目2-ii</li>
|
|
160
|
+
<li aria-label="iii">項目2-iii</li>
|
|
161
|
+
</ol>
|
|
162
|
+
</li>
|
|
163
|
+
<li>項目3</li>
|
|
164
|
+
</ol>
|
|
165
|
+
|
|
166
|
+
[Markdown]
|
|
167
|
+
- ❸項目❸
|
|
168
|
+
- ❹項目❹
|
|
169
|
+
- ②項目❹-②
|
|
170
|
+
- ③項目❹-③
|
|
171
|
+
- ④項目❹-④
|
|
172
|
+
- ❺項目❺
|
|
173
|
+
[HTML]
|
|
174
|
+
<ol start="3" role="list" class="ol-filled-circled-decimal">
|
|
175
|
+
<li aria-label="❸">項目❸</li>
|
|
176
|
+
<li aria-label="❹">項目❹
|
|
177
|
+
<ol start="2" role="list" class="ol-circled-decimal">
|
|
178
|
+
<li aria-label="②">項目❹-②</li>
|
|
179
|
+
<li aria-label="③">項目❹-③</li>
|
|
180
|
+
<li aria-label="④">項目❹-④</li>
|
|
181
|
+
</ol>
|
|
182
|
+
</li>
|
|
183
|
+
<li aria-label="❺">項目❺</li>
|
|
184
|
+
</ol>
|
|
185
|
+
|
|
186
|
+
[Markdown]
|
|
187
|
+
1. 項目1
|
|
188
|
+
2. 項目2
|
|
189
|
+
- i. 項目2-i
|
|
190
|
+
- ii. 項目2-ii
|
|
191
|
+
- a. 項目2-ii-a
|
|
192
|
+
- b. 項目2-ii-b
|
|
193
|
+
- c. 項目2-ii-c
|
|
194
|
+
- iii. 項目2-iii
|
|
195
|
+
3. 項目3
|
|
196
|
+
[HTML]
|
|
197
|
+
<ol class="ol-decimal">
|
|
198
|
+
<li>項目1</li>
|
|
199
|
+
<li>項目2
|
|
200
|
+
<ol type="i" class="ol-lower-roman">
|
|
201
|
+
<li aria-label="i">項目2-i</li>
|
|
202
|
+
<li aria-label="ii">項目2-ii
|
|
203
|
+
<ol type="a" class="ol-lower-latin">
|
|
204
|
+
<li aria-label="a">項目2-ii-a</li>
|
|
205
|
+
<li aria-label="b">項目2-ii-b</li>
|
|
206
|
+
<li aria-label="c">項目2-ii-c</li>
|
|
207
|
+
</ol>
|
|
208
|
+
</li>
|
|
209
|
+
<li aria-label="iii">項目2-iii</li>
|
|
210
|
+
</ol>
|
|
211
|
+
</li>
|
|
212
|
+
<li>項目3</li>
|
|
213
|
+
</ol>
|
|
214
|
+
```
|
package/index.js
ADDED
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function numbering_ul_regarded_as_ol_plugin(md, option) {
|
|
4
|
+
|
|
5
|
+
let opt = {
|
|
6
|
+
noChangeBulletOneOrderedList: true,
|
|
7
|
+
};
|
|
8
|
+
if (option !== undefined) {
|
|
9
|
+
for (let o in option) {
|
|
10
|
+
opt[o] = option[o];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const types = require('./listTypes.json');
|
|
15
|
+
const olTypes = [
|
|
16
|
+
['1', 'decimal'],
|
|
17
|
+
['a', 'lower-latin'], ['A', 'upper-latin'],
|
|
18
|
+
['i', 'lower-roman'], ['I', 'upper-roman'],
|
|
19
|
+
];
|
|
20
|
+
const prefixs = [
|
|
21
|
+
['(', 'round'], //parenthesis(parentheses), round bracket
|
|
22
|
+
['[', 'square'], //square bracket
|
|
23
|
+
['{', 'curly'], //curly bracket
|
|
24
|
+
['<', 'angle'], //angle bracket
|
|
25
|
+
];
|
|
26
|
+
const suffixs = [
|
|
27
|
+
[')', 'round'],
|
|
28
|
+
[']', 'square'],
|
|
29
|
+
['}', 'curly'],
|
|
30
|
+
['>', 'angle'],
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
function getSymbols(state, cn) {
|
|
34
|
+
let symbols = [];
|
|
35
|
+
const inlineToken = state.tokens[cn+2];
|
|
36
|
+
let ltn = 0;
|
|
37
|
+
while (ltn < types.length) {
|
|
38
|
+
let sn = 0;
|
|
39
|
+
const symbol = {
|
|
40
|
+
typesNum: -1,
|
|
41
|
+
typePos: -1,
|
|
42
|
+
contAll: '',
|
|
43
|
+
cont: '',
|
|
44
|
+
prefix: '',
|
|
45
|
+
suffix: '',
|
|
46
|
+
joint: '',
|
|
47
|
+
num: null,
|
|
48
|
+
}
|
|
49
|
+
let hasSymbol = null;
|
|
50
|
+
while (sn < types[ltn].symbols.length) {
|
|
51
|
+
hasSymbol = inlineToken.content.match(new RegExp('^'+ '((' + types[ltn].prefix + ')' + types[ltn].symbols[sn] + '(' + types[ltn].suffix + ')(' + types[ltn].joint + '))'));
|
|
52
|
+
if (!hasSymbol) { sn++; continue; }
|
|
53
|
+
|
|
54
|
+
symbol.typesNum = ltn;
|
|
55
|
+
symbol.contAll = hasSymbol[0];
|
|
56
|
+
symbol.cont = hasSymbol[1].replace(new RegExp('(' + types[ltn].joint + ')[ ]*$'), '');
|
|
57
|
+
symbol.prefix = hasSymbol[2];
|
|
58
|
+
symbol.suffix = hasSymbol[3].replace(new RegExp('(' + types[ltn].joint + ')[ ]*$'), '');
|
|
59
|
+
symbol.joint = hasSymbol[4].replace(/ *$/, '');
|
|
60
|
+
symbol.typePos = sn;
|
|
61
|
+
symbol.num = sn + types[ltn].start;
|
|
62
|
+
symbols.push(symbol);
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
ltn++;
|
|
66
|
+
}
|
|
67
|
+
//console.log('symbols: ' + symbols);
|
|
68
|
+
return symbols;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function processListToken (state, n, list) {
|
|
72
|
+
list.level++;
|
|
73
|
+
const flow = {
|
|
74
|
+
level: -1,
|
|
75
|
+
type: '',
|
|
76
|
+
pos: -1,
|
|
77
|
+
attrs: [],
|
|
78
|
+
psTypes: [], //psymbol symbol types.
|
|
79
|
+
symbols: [],
|
|
80
|
+
};
|
|
81
|
+
const startFlow = Object.create(flow);
|
|
82
|
+
startFlow.type = state.tokens[n].type;
|
|
83
|
+
startFlow.pos = n;
|
|
84
|
+
startFlow.level = list.level;
|
|
85
|
+
startFlow.psTypes = [];
|
|
86
|
+
list.flows.push(startFlow);
|
|
87
|
+
|
|
88
|
+
let cn = list.nextPos;
|
|
89
|
+
while (cn < state.tokens.length) {
|
|
90
|
+
const cnToken = state.tokens[cn];
|
|
91
|
+
//console.log('cn: ' + cn + ', list.level: ' + list.level + ', cnToken.type: ', cnToken.type, ', cnToken.content: ' + cnToken.content);
|
|
92
|
+
|
|
93
|
+
const isCnListOpen = cnToken.type.match(/(bullet|ordered)_list_open/);
|
|
94
|
+
const isCnListClose = cnToken.type.match(/(bullet|ordered)_list_close/);
|
|
95
|
+
|
|
96
|
+
if (isCnListClose) {
|
|
97
|
+
let stcn = list.flows.length - 1;
|
|
98
|
+
while (stcn > -1) {
|
|
99
|
+
//console.log('stcn: ' + stcn + ', list.flows[stcn].type: ' + list.flows[stcn].type);
|
|
100
|
+
list.nextPos = cn + 1;
|
|
101
|
+
if(list.flows[stcn].type.match(/(bullet|ordered)_list_open/) && list.level === list.flows[stcn].level) {
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
stcn--;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (/numbering_(?:bullet|ordered)_list_open/.test(list.flows[stcn].type)) {
|
|
108
|
+
isCnListClose[0] = 'numbering_' + isCnListClose[0];
|
|
109
|
+
cnToken.tag = 'ol';
|
|
110
|
+
}
|
|
111
|
+
list.nextPos = cn + 1;
|
|
112
|
+
const closeFlow = Object.create(flow);
|
|
113
|
+
closeFlow.type = isCnListClose[0];
|
|
114
|
+
closeFlow.pos = cn;
|
|
115
|
+
closeFlow.level = list.level;
|
|
116
|
+
list.level--;
|
|
117
|
+
list.flows.push(closeFlow);
|
|
118
|
+
if (list.level === 0) {
|
|
119
|
+
break;
|
|
120
|
+
} else {
|
|
121
|
+
cn++; continue;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (isCnListOpen) {
|
|
126
|
+
const nestStartFlow = Object.create(flow);
|
|
127
|
+
nestStartFlow.type = cnToken.type;
|
|
128
|
+
nestStartFlow.pos = cn;
|
|
129
|
+
nestStartFlow.level = list.level + 1;
|
|
130
|
+
list.level++;
|
|
131
|
+
nestStartFlow.psTypes = [];
|
|
132
|
+
list.flows.push(nestStartFlow);
|
|
133
|
+
cn++;
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (cnToken.type !== 'list_item_open') {
|
|
138
|
+
cn++; continue;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const listFlow = Object.create(flow);
|
|
142
|
+
listFlow.type = 'list_item_open';
|
|
143
|
+
listFlow.pos = cn;
|
|
144
|
+
listFlow.level = list.level;
|
|
145
|
+
listFlow.symbols = getSymbols(state, cn);
|
|
146
|
+
list.flows.push(listFlow);
|
|
147
|
+
//console.log('listFlow:' + JSON.stringify(listFlow));
|
|
148
|
+
|
|
149
|
+
//Check parent list flow number.
|
|
150
|
+
let plfn = list.flows.length - 2;
|
|
151
|
+
while (plfn > -1) {
|
|
152
|
+
if (list.flows[plfn].type.match(/(bullet|ordered)_list_open/) && listFlow.level === list.flows[plfn].level) {
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
plfn--; continue;
|
|
156
|
+
}
|
|
157
|
+
//console.log('list.flows[plfn]: ' + JSON.stringify(list.flows[plfn]));
|
|
158
|
+
|
|
159
|
+
//Set value attruibute of ordered list in listFlow.
|
|
160
|
+
const parentToken = state.tokens[list.flows[plfn].pos];
|
|
161
|
+
if (parentToken.type === 'ordered_list_open' && listFlow.symbols.length === 0) {
|
|
162
|
+
const liVal = cnToken.info;
|
|
163
|
+
|
|
164
|
+
let decimalSymbol = {
|
|
165
|
+
typesNum: 0,
|
|
166
|
+
typePos: liVal,
|
|
167
|
+
contAll: liVal + '. ',
|
|
168
|
+
cont: liVal,
|
|
169
|
+
prefix: '',
|
|
170
|
+
suffix: '',
|
|
171
|
+
joint: '. ',
|
|
172
|
+
num: liVal,
|
|
173
|
+
};
|
|
174
|
+
list.flows[list.flows.length-1].symbols.push(decimalSymbol);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
list.nextPos = cn + 1;
|
|
178
|
+
if (listFlow.symbols.length === 0) {
|
|
179
|
+
cn++; continue;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
//Set numbering type for parent list.
|
|
183
|
+
if (!/^numbering_/.test(list.flows[plfn].type)) {
|
|
184
|
+
list.flows[plfn].type = 'numbering_' + list.flows[plfn].type;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
//Set possible symbole types.
|
|
188
|
+
let sn = 0;
|
|
189
|
+
while (sn < listFlow.symbols.length) {
|
|
190
|
+
let plt = 0
|
|
191
|
+
let haslistType = false;
|
|
192
|
+
while (plt < list.flows[plfn].psTypes.length) {
|
|
193
|
+
if (list.flows[plfn].psTypes[plt].num === listFlow.symbols[sn].typesNum) {
|
|
194
|
+
list.flows[plfn].psTypes[plt].frequency++;
|
|
195
|
+
haslistType = true;
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
plt++;
|
|
199
|
+
}
|
|
200
|
+
if (list.flows[plfn].psTypes.length === 0 || !haslistType) {
|
|
201
|
+
list.flows[plfn].psTypes.push({
|
|
202
|
+
num: listFlow.symbols[sn].typesNum,
|
|
203
|
+
frequency: 1
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
sn++;
|
|
207
|
+
}
|
|
208
|
+
cn++;
|
|
209
|
+
}
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function getParentTypeNum (list, lfn) {
|
|
214
|
+
let i = 0;
|
|
215
|
+
let ptn = -1;
|
|
216
|
+
while (i < list.flows[lfn].psTypes.length) {
|
|
217
|
+
if (ptn < list.flows[lfn].psTypes[i].frequency) {
|
|
218
|
+
ptn = list.flows[lfn].psTypes[i].num;
|
|
219
|
+
}
|
|
220
|
+
i++;
|
|
221
|
+
}
|
|
222
|
+
return ptn;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function getParentNum (list, lfn) {
|
|
226
|
+
let plfn = lfn;
|
|
227
|
+
while (plfn > -1) {
|
|
228
|
+
if (/list_open$/.test(list.flows[plfn].type) && list.flows[lfn].level === list.flows[plfn].level) {
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
plfn--;
|
|
232
|
+
}
|
|
233
|
+
return plfn;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function getSymbolsNum(list, lfn, plfn) {
|
|
237
|
+
let sn = 0;
|
|
238
|
+
//console.log('list.flows[plfn].typesNum: ' + list.flows[plfn].typesNum);
|
|
239
|
+
while (sn < list.flows[lfn].symbols.length) {
|
|
240
|
+
if (+list.flows[lfn].symbols[sn].typesNum === +list.flows[plfn].typesNum) {
|
|
241
|
+
//console.log(sn, list.flows[plfn].typesNum);
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
sn++;
|
|
245
|
+
}
|
|
246
|
+
return sn;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function setNumbers(state, list) {
|
|
250
|
+
let lfn = 0;
|
|
251
|
+
while (lfn < list.flows.length) {
|
|
252
|
+
//console.log('list.flows[' + lfn + ']: '+ JSON.stringify(list.flows[lfn]));
|
|
253
|
+
|
|
254
|
+
const cn = list.flows[lfn].pos;
|
|
255
|
+
const isParent = list.flows[lfn].type.match(/(numbering_bullet|ordered)_list_open/);
|
|
256
|
+
if (isParent) {
|
|
257
|
+
if (isParent[1] === 'numbering_bullet') {
|
|
258
|
+
state.tokens[cn].type = 'ordered_list_open';
|
|
259
|
+
state.tokens[cn].tag = 'ol';
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const ptn = getParentTypeNum(list, lfn);
|
|
263
|
+
list.flows[lfn].typesNum = ptn;
|
|
264
|
+
const sn = getSymbolsNum(list, lfn+1, lfn);
|
|
265
|
+
//Set type and role attribute.
|
|
266
|
+
let isOlTypes = false;
|
|
267
|
+
let isOlTypes1 = false;
|
|
268
|
+
let otn = 0;
|
|
269
|
+
while (otn < olTypes.length) {
|
|
270
|
+
//console.log(types[ptn].name, olTypes[otn][1], olTypes[otn][0]);
|
|
271
|
+
isOlTypes = types[ptn].name === olTypes[otn][1] && !list.flows[lfn+1].symbols[sn].prefix && !list.flows[lfn+1].symbols[sn].suffix;
|
|
272
|
+
isOlTypes1 = isOlTypes && +olTypes[otn][0] === 1;
|
|
273
|
+
if (isOlTypes) {
|
|
274
|
+
if (!isOlTypes1) {
|
|
275
|
+
state.tokens[cn].attrSet('type', olTypes[otn][0]);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
otn++;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
//Set start attribute.
|
|
284
|
+
if (+list.flows[lfn+1].symbols[sn].num !== 1) {
|
|
285
|
+
state.tokens[cn].attrSet('start', list.flows[lfn+1].symbols[sn].num);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
//Set role attribute.
|
|
289
|
+
if(!isOlTypes && isParent[1] === 'numbering_bullet') {
|
|
290
|
+
state.tokens[cn].attrSet('role', 'list');
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
//Set class attribute.
|
|
294
|
+
if (ptn === -1) {
|
|
295
|
+
let hasOlClass= false;
|
|
296
|
+
let j = 0;
|
|
297
|
+
while (j < olTypes.length) {
|
|
298
|
+
if (new RegExp(olTypes[j][0]).test(state.tokens[cn].attrGet('type'))) {
|
|
299
|
+
state.tokens[cn].attrSet('class', 'ol-' + olTypes[j][1]);
|
|
300
|
+
hasOlClass = true;
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
j++;
|
|
304
|
+
}
|
|
305
|
+
if (!hasOlClass) {
|
|
306
|
+
state.tokens[cn].attrSet('class', 'ol-decimal');
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if (list.flows[lfn+1].symbols[sn] !== undefined) {
|
|
311
|
+
let prefixName = '';
|
|
312
|
+
let suffixName = '';
|
|
313
|
+
if (list.flows[lfn+1].symbols[sn].prefix) {
|
|
314
|
+
let j = 0;
|
|
315
|
+
while (j < prefixs.length) {
|
|
316
|
+
if (new RegExp('\\' + prefixs[j][0]).test(list.flows[lfn+1].symbols[sn].prefix)) {
|
|
317
|
+
prefixName = '-' + prefixs[j][1];
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
j++;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
if (list.flows[lfn+1].symbols[sn].suffix) {
|
|
324
|
+
let j = 0;
|
|
325
|
+
while (j < prefixs.length) {
|
|
326
|
+
if (new RegExp('\\' + suffixs[j][0]).test(list.flows[lfn+1].symbols[sn].suffix)) {
|
|
327
|
+
suffixName = '-' + suffixs[j][1];
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
j++;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
if(prefixName !== '' || suffixName !== '') {
|
|
334
|
+
if (prefixName === '') { prefixName = '-none'; }
|
|
335
|
+
if (suffixName === '') { suffixName = '-none'; }
|
|
336
|
+
state.tokens[cn].attrSet('class', 'ol-' + types[list.flows[lfn+1].symbols[sn].typesNum].name + '-with' + prefixName + suffixName);
|
|
337
|
+
} else {
|
|
338
|
+
state.tokens[cn].attrSet('class', 'ol-' + types[list.flows[lfn+1].symbols[sn].typesNum].name);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// list.flows[lfn].symbols.length > 0 for bullet list.
|
|
344
|
+
if (list.flows[lfn].type === 'list_item_open' && list.flows[lfn].symbols.length) {
|
|
345
|
+
const plfn = getParentNum(list, lfn);
|
|
346
|
+
//console.log('plfn: ' + plfn + ', list.flows[pn]: ' + JSON.stringify(list.flows[plfn]));
|
|
347
|
+
const sn = getSymbolsNum(list, lfn, plfn);
|
|
348
|
+
//console.log('sn: ' + sn);
|
|
349
|
+
//console.log('symbols.num: ' + +list.flows[lfn].symbols[sn].num);
|
|
350
|
+
|
|
351
|
+
//Set value attribute.
|
|
352
|
+
if (list.flows[lfn -1].type === 'list_item_open') {
|
|
353
|
+
const psn = getSymbolsNum(list, lfn - 1, plfn);
|
|
354
|
+
if (+list.flows[lfn -1].symbols[psn].num + 1 !== +list.flows[lfn].symbols[sn].num) {
|
|
355
|
+
state.tokens[cn].attrSet('value', list.flows[lfn].symbols[sn].num);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
//Set aria-label attribute and modify content.
|
|
360
|
+
if (list.flows[lfn].symbols[sn].typesNum !== 0 || list.flows[lfn].symbols[sn].prefix || list.flows[lfn].symbols[sn].suffix) {
|
|
361
|
+
state.tokens[cn].attrSet('aria-label', list.flows[lfn].symbols[sn].cont);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
//console.log('state.tokens[cn+2]: ' + JSON.stringify(state.tokens[cn+2]));
|
|
365
|
+
|
|
366
|
+
state.tokens[cn+2].content = state.tokens[cn+2].content.replace(list.flows[lfn].symbols[sn].contAll, '');
|
|
367
|
+
state.tokens[cn+2].children[0].content = state.tokens[cn+2].children[0].content.replace(list.flows[lfn].symbols[sn].contAll, '');
|
|
368
|
+
}
|
|
369
|
+
lfn++;
|
|
370
|
+
}
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function numUl (state) {
|
|
375
|
+
let n = 0;
|
|
376
|
+
|
|
377
|
+
//console.log(state.tokens);
|
|
378
|
+
while (n < state.tokens.length) {
|
|
379
|
+
const token = state.tokens[n];
|
|
380
|
+
const isListOpen = token.type.match(/(bullet|ordered)_list_open/);
|
|
381
|
+
if (!isListOpen) { n++; continue; }
|
|
382
|
+
|
|
383
|
+
let list = {
|
|
384
|
+
level: 0,
|
|
385
|
+
flows: [],
|
|
386
|
+
nextPos: n + 1,
|
|
387
|
+
};
|
|
388
|
+
processListToken(state, n, list);
|
|
389
|
+
//console.log('list: ' + JSON.stringify(list));
|
|
390
|
+
|
|
391
|
+
/*
|
|
392
|
+
if(!opt.noChangeBulletOneOrderedList) {
|
|
393
|
+
modifyBulletOneOrderedList(state, n, list);
|
|
394
|
+
}
|
|
395
|
+
*/
|
|
396
|
+
setNumbers(state, list);
|
|
397
|
+
n = list.nextPos;
|
|
398
|
+
}
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
md.core.ruler.before('linkify', 'numbering_ul', numUl);
|
|
403
|
+
};
|
package/listTypes.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
[{
|
|
2
|
+
"name": "decimal",
|
|
3
|
+
"symbolsCont": "0123456789",
|
|
4
|
+
"symbols": ["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50"],
|
|
5
|
+
"start": 0,
|
|
6
|
+
"prefix": "[(]?",
|
|
7
|
+
"suffix": "[)]?",
|
|
8
|
+
"joint": "[.] *"
|
|
9
|
+
},{
|
|
10
|
+
"name": "lower-latin",
|
|
11
|
+
"symbolsCont": "abcdefghijklmnopqrstuvwxyz",
|
|
12
|
+
"symbols": ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"],
|
|
13
|
+
"start": 1,
|
|
14
|
+
"prefix": "[(]?",
|
|
15
|
+
"suffix": "[)]?",
|
|
16
|
+
"joint": "[.] *"
|
|
17
|
+
},{
|
|
18
|
+
"name": "upper-latin",
|
|
19
|
+
"symbolsCont": "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
|
20
|
+
"symbols": ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"],
|
|
21
|
+
"start": 1,
|
|
22
|
+
"prefix": "[(]?",
|
|
23
|
+
"suffix": "[)]?",
|
|
24
|
+
"joint": "[.] *"
|
|
25
|
+
},{
|
|
26
|
+
"name": "lower-roman",
|
|
27
|
+
"symbolsCont": "ⅰⅱⅲⅳⅴⅵⅶⅷⅸⅹⅺⅻ",
|
|
28
|
+
"symbols": ["i","ii","iii","iv","v","vi","vii","viii","ix","x","xi","xii","xiii","xiv","xv","xvi","xvii","xviii","xix","xx"],
|
|
29
|
+
"start": 1,
|
|
30
|
+
"prefix": "[(]?",
|
|
31
|
+
"suffix": "[)]?",
|
|
32
|
+
"joint": "[.] *"
|
|
33
|
+
},{
|
|
34
|
+
"name": "upper-roman",
|
|
35
|
+
"symbolsCont": "ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ",
|
|
36
|
+
"symbols": ["I","II","III","IV","V","VI","VII","VIII","IX","X","XI","XII","XIII","XIV","XV","XVI","XVII","XVIII","XIX","XX"],
|
|
37
|
+
"start": 1,
|
|
38
|
+
"prefix": "[(]?",
|
|
39
|
+
"suffix": "[)]?",
|
|
40
|
+
"joint": "[.] *"
|
|
41
|
+
},{
|
|
42
|
+
"name": "filled-circled-decimal",
|
|
43
|
+
"symbolsCont": "❶❷❸❹❺❻❼❽❾❿⓫⓬⓭⓮⓯⓰⓱⓲⓳⓴",
|
|
44
|
+
"symbols": ["\u2776", "\u2777", "\u2778", "\u2779", "\u277A", "\u277B", "\u277C", "\u277D", "\u277E", "\u277F", "\u24EB", "\u24EC", "\u24ED", "\u24EE", "\u24EF", "\u24F0", "\u24F1", "\u24F2", "\u24F3", "\u24F4"],
|
|
45
|
+
"start": 1,
|
|
46
|
+
"prefix": "",
|
|
47
|
+
"suffix": "",
|
|
48
|
+
"joint": " *"
|
|
49
|
+
},{
|
|
50
|
+
"name": "circled-decimal",
|
|
51
|
+
"symbolsCont": "⓪①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮⑯⑰⑱⑲⑳㉑㉒㉓㉔㉕㉖㉗㉘㉙㉚㉛㉜㉝㉞㉟㊱㊲㊳㊴㊵㊶㊷㊸㊹㊺㊻㊼㊽㊾㊿",
|
|
52
|
+
"symbols": ["\u24EA","\u2460","\u2461","\u2462","\u2463","\u2464","\u2465","\u2466","\u2467","\u2468","\u2469","\u246A","\u246B","\u246C","\u246D","\u246E","\u246F","\u2470","\u2471","\u2472","\u2473","\u3251","\u3252","\u3253","\u3254","\u3255","\u3256","\u3257","\u3258","\u3259","\u325A","\u325B","\u325C","\u325D","\u325E","\u325F","\u32B1","\u32B2","\u32B3","\u32B4","\u32B5","\u32B6","\u32B7","\u32B8","\u32B9","\u32BA","\u32BB","\u32BC","\u32BD","\u32BE","\u32BF"],
|
|
53
|
+
"start": 0,
|
|
54
|
+
"prefix": "",
|
|
55
|
+
"suffix": "",
|
|
56
|
+
"joint": " *"
|
|
57
|
+
}]
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@peaceroad/markdown-it-numbering-ul-regarded-as-ol",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "This markdown-it plugin regard ul element with numbering lists as ol element.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "node test/test.js"
|
|
8
|
+
},
|
|
9
|
+
"repository": "https://github.com/peaceroad/p7d-markdown-it-numbering-ul-regarded-as-ol.git",
|
|
10
|
+
"author": "peaceroad <peaceroad@gmail.com>",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/peaceroad/p7d-markdown-it-numbering-ul-regarded-as-ol/issues"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/peaceroad/p7d-markdown-it-numbering-ul-regarded-as-ol#readme",
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"markdown-it": "^12.2.0"
|
|
18
|
+
}
|
|
19
|
+
}
|
package/test/examples.md
ADDED
|
File without changes
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
[Markdown]
|
|
2
|
+
1. a
|
|
3
|
+
2. b
|
|
4
|
+
3. c
|
|
5
|
+
[HTML]
|
|
6
|
+
<ol class="ol-decimal">
|
|
7
|
+
<li>a</li>
|
|
8
|
+
<li>b</li>
|
|
9
|
+
<li>c</li>
|
|
10
|
+
</ol>
|
|
11
|
+
|
|
12
|
+
[Markdown]
|
|
13
|
+
3. a
|
|
14
|
+
4. b
|
|
15
|
+
5. c
|
|
16
|
+
[HTML]
|
|
17
|
+
<ol start="3" class="ol-decimal">
|
|
18
|
+
<li>a</li>
|
|
19
|
+
<li>b</li>
|
|
20
|
+
<li>c</li>
|
|
21
|
+
</ol>
|
|
22
|
+
|
|
23
|
+
[Markdown]
|
|
24
|
+
1. a
|
|
25
|
+
3. b
|
|
26
|
+
4. c
|
|
27
|
+
[HTML]
|
|
28
|
+
<ol class="ol-decimal">
|
|
29
|
+
<li>a</li>
|
|
30
|
+
<li value="3">b</li>
|
|
31
|
+
<li>c</li>
|
|
32
|
+
</ol>
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
[Markdown]
|
|
36
|
+
- i. a
|
|
37
|
+
- ii. b
|
|
38
|
+
- iii. c
|
|
39
|
+
[HTML]
|
|
40
|
+
<ol type="i" class="ol-lower-roman">
|
|
41
|
+
<li aria-label="i">a</li>
|
|
42
|
+
<li aria-label="ii">b</li>
|
|
43
|
+
<li aria-label="iii">c</li>
|
|
44
|
+
</ol>
|
|
45
|
+
|
|
46
|
+
[Markdown]
|
|
47
|
+
- a
|
|
48
|
+
- b
|
|
49
|
+
- c
|
|
50
|
+
[HTML]
|
|
51
|
+
<ul>
|
|
52
|
+
<li>a</li>
|
|
53
|
+
<li>b</li>
|
|
54
|
+
<li>c</li>
|
|
55
|
+
</ul>
|
|
56
|
+
|
|
57
|
+
[Markdown]
|
|
58
|
+
- ❶ a
|
|
59
|
+
- ❷ b
|
|
60
|
+
- ❸ c
|
|
61
|
+
[HTML]
|
|
62
|
+
<ol role="list" class="ol-filled-circled-decimal">
|
|
63
|
+
<li aria-label="❶">a</li>
|
|
64
|
+
<li aria-label="❷">b</li>
|
|
65
|
+
<li aria-label="❸">c</li>
|
|
66
|
+
</ol>
|
|
67
|
+
|
|
68
|
+
[Markdown]
|
|
69
|
+
2. a
|
|
70
|
+
3. b
|
|
71
|
+
4. c
|
|
72
|
+
[HTML]
|
|
73
|
+
<ol start="2" class="ol-decimal">
|
|
74
|
+
<li>a</li>
|
|
75
|
+
<li>b</li>
|
|
76
|
+
<li>c</li>
|
|
77
|
+
</ol>
|
|
78
|
+
|
|
79
|
+
[Markdown]
|
|
80
|
+
- ② a
|
|
81
|
+
- ③ b
|
|
82
|
+
- ④ c
|
|
83
|
+
[HTML]
|
|
84
|
+
<ol start="2" role="list" class="ol-circled-decimal">
|
|
85
|
+
<li aria-label="②">a</li>
|
|
86
|
+
<li aria-label="③">b</li>
|
|
87
|
+
<li aria-label="④">c</li>
|
|
88
|
+
</ol>
|
|
89
|
+
|
|
90
|
+
[Markdown]
|
|
91
|
+
- (2). a
|
|
92
|
+
- (3). b
|
|
93
|
+
- (4). c
|
|
94
|
+
[HTML]
|
|
95
|
+
<ol start="2" role="list" class="ol-decimal-with-round-round">
|
|
96
|
+
<li aria-label="(2)">a</li>
|
|
97
|
+
<li aria-label="(3)">b</li>
|
|
98
|
+
<li aria-label="(4)">c</li>
|
|
99
|
+
</ol>
|
|
100
|
+
|
|
101
|
+
[Markdown]
|
|
102
|
+
- 2). a
|
|
103
|
+
- 3). b
|
|
104
|
+
- 4). c
|
|
105
|
+
[HTML]
|
|
106
|
+
<ol start="2" role="list" class="ol-decimal-with-none-round">
|
|
107
|
+
<li aria-label="2)">a</li>
|
|
108
|
+
<li aria-label="3)">b</li>
|
|
109
|
+
<li aria-label="4)">c</li>
|
|
110
|
+
</ol>
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
[Markdown]
|
|
114
|
+
1. 項目1
|
|
115
|
+
2. 項目2
|
|
116
|
+
- i. 項目2-i
|
|
117
|
+
- ii. 項目2-ii
|
|
118
|
+
- iii. 項目2-iii
|
|
119
|
+
3. 項目3
|
|
120
|
+
[HTML]
|
|
121
|
+
<ol class="ol-decimal">
|
|
122
|
+
<li>項目1</li>
|
|
123
|
+
<li>項目2
|
|
124
|
+
<ol type="i" class="ol-lower-roman">
|
|
125
|
+
<li aria-label="i">項目2-i</li>
|
|
126
|
+
<li aria-label="ii">項目2-ii</li>
|
|
127
|
+
<li aria-label="iii">項目2-iii</li>
|
|
128
|
+
</ol>
|
|
129
|
+
</li>
|
|
130
|
+
<li>項目3</li>
|
|
131
|
+
</ol>
|
|
132
|
+
|
|
133
|
+
[Markdown]
|
|
134
|
+
- i. 項目i
|
|
135
|
+
- ii. 項目ii
|
|
136
|
+
1. 項目ii-1
|
|
137
|
+
2. 項目ii-2
|
|
138
|
+
3. 項目ii-3
|
|
139
|
+
- iii. 項目iii
|
|
140
|
+
[HTML]
|
|
141
|
+
<ol type="i" class="ol-lower-roman">
|
|
142
|
+
<li aria-label="i">項目i</li>
|
|
143
|
+
<li aria-label="ii">項目ii
|
|
144
|
+
<ol class="ol-decimal">
|
|
145
|
+
<li>項目ii-1</li>
|
|
146
|
+
<li>項目ii-2</li>
|
|
147
|
+
<li>項目ii-3</li>
|
|
148
|
+
</ol>
|
|
149
|
+
</li>
|
|
150
|
+
<li aria-label="iii">項目iii</li>
|
|
151
|
+
</ol>
|
|
152
|
+
|
|
153
|
+
[Markdown]
|
|
154
|
+
- ❸項目❸
|
|
155
|
+
- ❹項目❹
|
|
156
|
+
- ②項目❹-②
|
|
157
|
+
- ③項目❹-③
|
|
158
|
+
- ④項目❹-④
|
|
159
|
+
- ❺項目❺
|
|
160
|
+
[HTML]
|
|
161
|
+
<ol start="3" role="list" class="ol-filled-circled-decimal">
|
|
162
|
+
<li aria-label="❸">項目❸</li>
|
|
163
|
+
<li aria-label="❹">項目❹
|
|
164
|
+
<ol start="2" role="list" class="ol-circled-decimal">
|
|
165
|
+
<li aria-label="②">項目❹-②</li>
|
|
166
|
+
<li aria-label="③">項目❹-③</li>
|
|
167
|
+
<li aria-label="④">項目❹-④</li>
|
|
168
|
+
</ol>
|
|
169
|
+
</li>
|
|
170
|
+
<li aria-label="❺">項目❺</li>
|
|
171
|
+
</ol>
|
|
172
|
+
|
|
173
|
+
[Markdown]
|
|
174
|
+
1. 項目1
|
|
175
|
+
2. 項目2
|
|
176
|
+
- i. 項目2-i
|
|
177
|
+
- ii. 項目2-ii
|
|
178
|
+
- a. 項目2-ii-a
|
|
179
|
+
- b. 項目2-ii-b
|
|
180
|
+
- c. 項目2-ii-c
|
|
181
|
+
- iii. 項目2-iii
|
|
182
|
+
3. 項目3
|
|
183
|
+
[HTML]
|
|
184
|
+
<ol class="ol-decimal">
|
|
185
|
+
<li>項目1</li>
|
|
186
|
+
<li>項目2
|
|
187
|
+
<ol type="i" class="ol-lower-roman">
|
|
188
|
+
<li aria-label="i">項目2-i</li>
|
|
189
|
+
<li aria-label="ii">項目2-ii
|
|
190
|
+
<ol type="a" class="ol-lower-latin">
|
|
191
|
+
<li aria-label="a">項目2-ii-a</li>
|
|
192
|
+
<li aria-label="b">項目2-ii-b</li>
|
|
193
|
+
<li aria-label="c">項目2-ii-c</li>
|
|
194
|
+
</ol>
|
|
195
|
+
</li>
|
|
196
|
+
<li aria-label="iii">項目2-iii</li>
|
|
197
|
+
</ol>
|
|
198
|
+
</li>
|
|
199
|
+
<li>項目3</li>
|
|
200
|
+
</ol>
|
|
201
|
+
|
package/test/test.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const assert = require('assert');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const md = require('markdown-it')();
|
|
4
|
+
const mdNumUl = require('../index.js');
|
|
5
|
+
|
|
6
|
+
md.use(mdNumUl);
|
|
7
|
+
|
|
8
|
+
const example = __dirname + '/examples.txt';
|
|
9
|
+
const mdPath = __dirname + '/examples.md';
|
|
10
|
+
const exampleCont = fs.readFileSync(example, 'utf-8').trim();
|
|
11
|
+
let ms = [];
|
|
12
|
+
let ms0 = exampleCont.split(/\n*\[Markdown\]\n/);
|
|
13
|
+
let n = 1;
|
|
14
|
+
while (n < ms0.length) {
|
|
15
|
+
let mhs = ms0[n].split(/\n+\[HTML[^\]]*?\]\n/);
|
|
16
|
+
let i = 1;
|
|
17
|
+
while (i < 2) {
|
|
18
|
+
if (mhs[i] === undefined) {
|
|
19
|
+
mhs[i] = '';
|
|
20
|
+
} else {
|
|
21
|
+
mhs[i] = mhs[i].replace(/$/,'\n');
|
|
22
|
+
}
|
|
23
|
+
i++;
|
|
24
|
+
}
|
|
25
|
+
ms[n] = {
|
|
26
|
+
"markdown": mhs[0],
|
|
27
|
+
"html": mhs[1],
|
|
28
|
+
};
|
|
29
|
+
n++;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
n = 1;
|
|
33
|
+
while(n < ms.length) {
|
|
34
|
+
//if (n >= 14) { n++; continue };
|
|
35
|
+
console.log('Test: ' + n + ' >>>');
|
|
36
|
+
//console.log(ms[n].markdown);
|
|
37
|
+
|
|
38
|
+
const m = ms[n].markdown;
|
|
39
|
+
const h = md.render(m);
|
|
40
|
+
try {
|
|
41
|
+
assert.strictEqual(h, ms[n].html);
|
|
42
|
+
} catch(e) {
|
|
43
|
+
console.log('incorrect: ');
|
|
44
|
+
console.log('H: ' + h +'C: ' + ms[n].html);
|
|
45
|
+
};
|
|
46
|
+
n++;
|
|
47
|
+
}
|