@peaceroad/markdown-it-table-ex 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 +136 -0
- package/index.js +149 -0
- package/package.json +18 -0
- package/test/examples.txt +411 -0
- package/test/examples_wrapper.txt +119 -0
- package/test/examples_wrapper_with_caption.txt +141 -0
- package/test/test.js +117 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 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,136 @@
|
|
|
1
|
+
# p7d-markdown-it-table-ex
|
|
2
|
+
|
|
3
|
+
A markdown-it plugin. For table processing, this plugin plus some extended syntax.
|
|
4
|
+
|
|
5
|
+
- matrix (enabled by default.)
|
|
6
|
+
- wrapper (option.)
|
|
7
|
+
|
|
8
|
+
Notice. This is intended to be used in conjunction with [markdown-it-multimd-table](https://github.com/redbug312/markdown-it-multimd-table) enabled the option: headerless, multiline, rowspan.
|
|
9
|
+
|
|
10
|
+
## Use
|
|
11
|
+
|
|
12
|
+
```js
|
|
13
|
+
import mdit from 'markdown-it'
|
|
14
|
+
import mditMultimdTable from 'markdown-it-multimd-table'
|
|
15
|
+
import mditTableEx from '@peaceroad/markdown-it-table-ex'
|
|
16
|
+
|
|
17
|
+
const md = mdit({ html: true }).use(mditMultimdTable, {
|
|
18
|
+
headerless: true,
|
|
19
|
+
multiline: true,
|
|
20
|
+
rowspan: true,
|
|
21
|
+
}).use(mditTableEx)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
wrapper will be enabled as follows:
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
const md = mdit({ html: true }).use(mditMultimdTable, {
|
|
28
|
+
headerless: true,
|
|
29
|
+
multiline: true,
|
|
30
|
+
rowspan: true,
|
|
31
|
+
}).use(mditTableEx, {
|
|
32
|
+
wrapper: true,
|
|
33
|
+
})
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
## Extended notation
|
|
38
|
+
|
|
39
|
+
### matrix
|
|
40
|
+
|
|
41
|
+
If the leftmost cell of the table is surrounded by `**`, it will be converted to a th element. Note that the first cell of thead can be empty.
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
[Markdown]
|
|
45
|
+
| | hh1 | hh2 |
|
|
46
|
+
| ------- | ---- | ---- |
|
|
47
|
+
| **vh1** | 11 | 12 |
|
|
48
|
+
| **vh2** | 21 | 22 |
|
|
49
|
+
[HTML]
|
|
50
|
+
<table>
|
|
51
|
+
<thead>
|
|
52
|
+
<tr>
|
|
53
|
+
<th scope="col"></th>
|
|
54
|
+
<th scope="col">hh1</th>
|
|
55
|
+
<th scope="col">hh2</th>
|
|
56
|
+
</tr>
|
|
57
|
+
</thead>
|
|
58
|
+
<tbody>
|
|
59
|
+
<tr>
|
|
60
|
+
<th scope="row">vh1</th>
|
|
61
|
+
<td>11</td>
|
|
62
|
+
<td>12</td>
|
|
63
|
+
</tr>
|
|
64
|
+
<tr>
|
|
65
|
+
<th scope="row">vh2</th>
|
|
66
|
+
<td>21</td>
|
|
67
|
+
<td>22</td>
|
|
68
|
+
</tr>
|
|
69
|
+
</tbody>
|
|
70
|
+
</table>
|
|
71
|
+
|
|
72
|
+
[Markdown]
|
|
73
|
+
| **hh0** | hh1 | hh2 |
|
|
74
|
+
| ------- | ---- | ---- |
|
|
75
|
+
| **vh1** | 11 | 12 |
|
|
76
|
+
| **vh2** | 21 | 22 |
|
|
77
|
+
[HTML]
|
|
78
|
+
<table>
|
|
79
|
+
<thead>
|
|
80
|
+
<tr>
|
|
81
|
+
<th scope="col">hh0</th>
|
|
82
|
+
<th scope="col">hh1</th>
|
|
83
|
+
<th scope="col">hh2</th>
|
|
84
|
+
</tr>
|
|
85
|
+
</thead>
|
|
86
|
+
<tbody>
|
|
87
|
+
<tr>
|
|
88
|
+
<th scope="row">vh1</th>
|
|
89
|
+
<td>11</td>
|
|
90
|
+
<td>12</td>
|
|
91
|
+
</tr>
|
|
92
|
+
<tr>
|
|
93
|
+
<th scope="row">vh2</th>
|
|
94
|
+
<td>21</td>
|
|
95
|
+
<td>22</td>
|
|
96
|
+
</tr>
|
|
97
|
+
</tbody>
|
|
98
|
+
</table>
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### wrapper
|
|
102
|
+
|
|
103
|
+
The table is wrapped in a div.table-wrapper element.
|
|
104
|
+
I think this is useful for moving the table left and right when the screen width is narrow.
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
[Markdown]
|
|
108
|
+
| hh0 | hh1 | hh2 |
|
|
109
|
+
| --- | ---- | ---- |
|
|
110
|
+
| vh1 | 11 | 12 |
|
|
111
|
+
| vh2 | 21 | 22 |
|
|
112
|
+
[HTML]
|
|
113
|
+
<div class="table-wrapper">
|
|
114
|
+
<table>
|
|
115
|
+
<thead>
|
|
116
|
+
<tr>
|
|
117
|
+
<th scope="col">hh0</th>
|
|
118
|
+
<th scope="col">hh1</th>
|
|
119
|
+
<th scope="col">hh2</th>
|
|
120
|
+
</tr>
|
|
121
|
+
</thead>
|
|
122
|
+
<tbody>
|
|
123
|
+
<tr>
|
|
124
|
+
<td>vh1</td>
|
|
125
|
+
<td>11</td>
|
|
126
|
+
<td>12</td>
|
|
127
|
+
</tr>
|
|
128
|
+
<tr>
|
|
129
|
+
<td>vh2</td>
|
|
130
|
+
<td>21</td>
|
|
131
|
+
<td>22</td>
|
|
132
|
+
</tr>
|
|
133
|
+
</tbody>
|
|
134
|
+
</table>
|
|
135
|
+
</div>
|
|
136
|
+
```
|
package/index.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
const checkedTdReg = /^\*\*(?!.*\*\*.*\*\*)[\s\S]*?\*\*$/
|
|
2
|
+
|
|
3
|
+
const addTheadThScope = (state, theadVar) => {
|
|
4
|
+
let isEmpty = false
|
|
5
|
+
let firstThPos = theadVar.pos
|
|
6
|
+
let j = theadVar.i + 2
|
|
7
|
+
//if (state.tokens[theadVar.i + 1].type !== 'tr_open') return threadVar
|
|
8
|
+
while (j < state.tokens.length) {
|
|
9
|
+
if (state.tokens[j].type === 'th_open') {
|
|
10
|
+
state.tokens[j].attrPush(['scope', 'col']);
|
|
11
|
+
if (j === theadVar.i + 2) {
|
|
12
|
+
isEmpty = state.tokens[j+1].content === ''
|
|
13
|
+
let isStrong = checkedTdReg.test(state.tokens[j+1].content)
|
|
14
|
+
if (isStrong || isEmpty) firstThPos = j
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
if (state.tokens[j].type === 'tr_close') break
|
|
18
|
+
j++
|
|
19
|
+
}
|
|
20
|
+
return {i: j, firstThPos: firstThPos, isEmpty: isEmpty}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
const changeTdToTh = (state, tdPoses, hasThead) => {
|
|
25
|
+
let j = 0
|
|
26
|
+
while(j < tdPoses.length) {
|
|
27
|
+
//console.log('tdPos: ' + tdPoses[j] + ', state.tokens[j].type: ' + state.tokens[tdPoses[j]].type)
|
|
28
|
+
const pos = tdPoses[j]
|
|
29
|
+
if (j > 0 || (!hasThead && j === 0)) {
|
|
30
|
+
state.tokens[pos].type = 'th_open';
|
|
31
|
+
state.tokens[pos].tag = 'th';
|
|
32
|
+
state.tokens[pos].attrPush(['scope', 'row']);
|
|
33
|
+
state.tokens[pos + 2].type = 'th_close';
|
|
34
|
+
state.tokens[pos + 2].tag = 'th';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let ci = 0
|
|
38
|
+
while (ci < state.tokens[pos + 1].children.length) {
|
|
39
|
+
if (state.tokens[pos + 1].children[ci].type === 'strong_open') {
|
|
40
|
+
state.tokens[pos + 1].children.splice(ci, 1)
|
|
41
|
+
break
|
|
42
|
+
}
|
|
43
|
+
ci++
|
|
44
|
+
}
|
|
45
|
+
ci = state.tokens[pos + 1].children.length - 1
|
|
46
|
+
while (0 < ci) {
|
|
47
|
+
if (state.tokens[pos + 1].children[ci].type === 'strong_close') {
|
|
48
|
+
state.tokens[pos + 1].children.splice(ci, 1)
|
|
49
|
+
break
|
|
50
|
+
}
|
|
51
|
+
ci--
|
|
52
|
+
}
|
|
53
|
+
j++
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const checkTbody = (state, tbodyVar) => {
|
|
58
|
+
let isAllFirstTh = true
|
|
59
|
+
let tbodyFirstThPoses = []
|
|
60
|
+
let j = tbodyVar.i + 1
|
|
61
|
+
while (j < state.tokens.length) {
|
|
62
|
+
if (state.tokens[j].type === 'tr_open') {
|
|
63
|
+
j++
|
|
64
|
+
if (state.tokens[j].type === 'td_open' && state.tokens[j + 1].content.match(checkedTdReg)) {
|
|
65
|
+
tbodyFirstThPoses.push(j)
|
|
66
|
+
} else {
|
|
67
|
+
isAllFirstTh = false
|
|
68
|
+
break
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (state.tokens[j].type === 'tbody_close') break
|
|
72
|
+
j++
|
|
73
|
+
}
|
|
74
|
+
return { i: j ,isAllFirstTh: isAllFirstTh, tbodyFirstThPoses: tbodyFirstThPoses}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const tableEx = (state, opt) => {
|
|
78
|
+
let idx = 0
|
|
79
|
+
while (idx < state.tokens.length) {
|
|
80
|
+
if (state.tokens[idx].type !== 'table_open') { idx++; continue; }
|
|
81
|
+
if (opt.wrapper) {
|
|
82
|
+
const wrapperStartToken = new state.Token('div_open', 'div', 1)
|
|
83
|
+
wrapperStartToken.attrPush(['class', 'table-wrapper'])
|
|
84
|
+
const linebreakToken = new state.Token('text', '', 0)
|
|
85
|
+
linebreakToken.content = '\n'
|
|
86
|
+
state.tokens.splice(idx, 0, wrapperStartToken, linebreakToken)
|
|
87
|
+
idx = idx + 2
|
|
88
|
+
}
|
|
89
|
+
let theadVar = {
|
|
90
|
+
i : idx + 1,
|
|
91
|
+
firstThPos: -1,
|
|
92
|
+
isEmpty: false,
|
|
93
|
+
}
|
|
94
|
+
//console.log(theadVar.i, state.tokens[theadVar.i].type)
|
|
95
|
+
const hasThead = state.tokens[theadVar.i].type === 'thead_open'
|
|
96
|
+
if (hasThead) {
|
|
97
|
+
theadVar = addTheadThScope(state, theadVar)
|
|
98
|
+
idx = theadVar.i + 1
|
|
99
|
+
}
|
|
100
|
+
//console.log('theadVar: ' + JSON.stringify(theadVar) + ', hasThead: ' + hasThead)
|
|
101
|
+
let tbodyVar = {
|
|
102
|
+
i: idx + 1,
|
|
103
|
+
isAllFirstTh: false,
|
|
104
|
+
tbodyFirstThPoses: [],
|
|
105
|
+
}
|
|
106
|
+
//console.log(tbodyVar.i, state.tokens[tbodyVar.i].type)
|
|
107
|
+
const hasTbody = state.tokens[tbodyVar.i].type === 'tbody_open'
|
|
108
|
+
if (hasTbody) {
|
|
109
|
+
tbodyVar = checkTbody(state, tbodyVar)
|
|
110
|
+
idx = tbodyVar.i + 1
|
|
111
|
+
}
|
|
112
|
+
//console.log('tbodyVar: ' + JSON.stringify(tbodyVar) + ', hasTbody: ' + hasTbody)
|
|
113
|
+
if (theadVar.firstThPos && tbodyVar.isAllFirstTh) {
|
|
114
|
+
let firstTdPoses = [...tbodyVar.tbodyFirstThPoses]
|
|
115
|
+
if (hasThead) {
|
|
116
|
+
firstTdPoses.splice(0, 0, theadVar.firstThPos)
|
|
117
|
+
}
|
|
118
|
+
if (opt.matrix) changeTdToTh(state, firstTdPoses, hasThead, theadVar)
|
|
119
|
+
}
|
|
120
|
+
while (idx < state.tokens.length) {
|
|
121
|
+
if (state.tokens[idx].type === 'table_close') {
|
|
122
|
+
if (opt.wrapper) {
|
|
123
|
+
const wrapperEndToken = new state.Token('div_close', 'div', -1)
|
|
124
|
+
const linebreakToken = new state.Token('text', '', 0)
|
|
125
|
+
linebreakToken.content = '\n'
|
|
126
|
+
state.tokens.splice(idx + 1, 0, wrapperEndToken, linebreakToken)
|
|
127
|
+
idx = idx + 2
|
|
128
|
+
}
|
|
129
|
+
break
|
|
130
|
+
}
|
|
131
|
+
idx++
|
|
132
|
+
}
|
|
133
|
+
idx++
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const mditTableEx = (md, option) => {
|
|
138
|
+
let opt = {
|
|
139
|
+
matrix: true,
|
|
140
|
+
wrapper: false,
|
|
141
|
+
}
|
|
142
|
+
for (let key in option) {
|
|
143
|
+
opt[key] = option[key]
|
|
144
|
+
}
|
|
145
|
+
md.core.ruler.after('replacements', 'table-ex', (state) => {
|
|
146
|
+
tableEx(state, opt)
|
|
147
|
+
})
|
|
148
|
+
}
|
|
149
|
+
export default mditTableEx
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@peaceroad/markdown-it-table-ex",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A markdown-it plugin. Add matrix and wrapper notation for table processing.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "node test/test.js"
|
|
9
|
+
},
|
|
10
|
+
"repository": "https://github.com/peaceroad/p7d-markdown-it-table-ex.git",
|
|
11
|
+
"author": "peaceroad <peaceroad@gmail.com>",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"markdown-it-multimd-table": "^4.2.3",
|
|
15
|
+
"@peaceroad/markdown-it-figure-with-p-caption": "^0.10.0",
|
|
16
|
+
"markdown-it": "^14.1.0"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
[Markdown]
|
|
2
|
+
| hh0 | hh1 | hh2 |
|
|
3
|
+
| --- | ---- | ---- |
|
|
4
|
+
| vh1 | 11 | 12 |
|
|
5
|
+
| vh2 | 21 | 22 |
|
|
6
|
+
[HTML]
|
|
7
|
+
<table>
|
|
8
|
+
<thead>
|
|
9
|
+
<tr>
|
|
10
|
+
<th scope="col">hh0</th>
|
|
11
|
+
<th scope="col">hh1</th>
|
|
12
|
+
<th scope="col">hh2</th>
|
|
13
|
+
</tr>
|
|
14
|
+
</thead>
|
|
15
|
+
<tbody>
|
|
16
|
+
<tr>
|
|
17
|
+
<td>vh1</td>
|
|
18
|
+
<td>11</td>
|
|
19
|
+
<td>12</td>
|
|
20
|
+
</tr>
|
|
21
|
+
<tr>
|
|
22
|
+
<td>vh2</td>
|
|
23
|
+
<td>21</td>
|
|
24
|
+
<td>22</td>
|
|
25
|
+
</tr>
|
|
26
|
+
</tbody>
|
|
27
|
+
</table>
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
[Markdown]
|
|
31
|
+
| | hh1 | hh2 |
|
|
32
|
+
| --- | ---- | ---- |
|
|
33
|
+
| vh1 | 11 | 12 |
|
|
34
|
+
| vh2 | 21 | 22 |
|
|
35
|
+
[HTML]
|
|
36
|
+
<table>
|
|
37
|
+
<thead>
|
|
38
|
+
<tr>
|
|
39
|
+
<th scope="col"></th>
|
|
40
|
+
<th scope="col">hh1</th>
|
|
41
|
+
<th scope="col">hh2</th>
|
|
42
|
+
</tr>
|
|
43
|
+
</thead>
|
|
44
|
+
<tbody>
|
|
45
|
+
<tr>
|
|
46
|
+
<td>vh1</td>
|
|
47
|
+
<td>11</td>
|
|
48
|
+
<td>12</td>
|
|
49
|
+
</tr>
|
|
50
|
+
<tr>
|
|
51
|
+
<td>vh2</td>
|
|
52
|
+
<td>21</td>
|
|
53
|
+
<td>22</td>
|
|
54
|
+
</tr>
|
|
55
|
+
</tbody>
|
|
56
|
+
</table>
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
[Markdown]
|
|
60
|
+
| | hh1 | hh2 |
|
|
61
|
+
| ------- | ---- | ---- |
|
|
62
|
+
| **vh1** | 11 | 12 |
|
|
63
|
+
| **vh2** | 21 | 22 |
|
|
64
|
+
[HTML]
|
|
65
|
+
<table>
|
|
66
|
+
<thead>
|
|
67
|
+
<tr>
|
|
68
|
+
<th scope="col"></th>
|
|
69
|
+
<th scope="col">hh1</th>
|
|
70
|
+
<th scope="col">hh2</th>
|
|
71
|
+
</tr>
|
|
72
|
+
</thead>
|
|
73
|
+
<tbody>
|
|
74
|
+
<tr>
|
|
75
|
+
<th scope="row">vh1</th>
|
|
76
|
+
<td>11</td>
|
|
77
|
+
<td>12</td>
|
|
78
|
+
</tr>
|
|
79
|
+
<tr>
|
|
80
|
+
<th scope="row">vh2</th>
|
|
81
|
+
<td>21</td>
|
|
82
|
+
<td>22</td>
|
|
83
|
+
</tr>
|
|
84
|
+
</tbody>
|
|
85
|
+
</table>
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
[Markdown]
|
|
89
|
+
| **hh0** | hh1 | hh2 |
|
|
90
|
+
| ------- | ---- | ---- |
|
|
91
|
+
| **vh1** | 11 | 12 |
|
|
92
|
+
| **vh2** | 21 | 22 |
|
|
93
|
+
[HTML]
|
|
94
|
+
<table>
|
|
95
|
+
<thead>
|
|
96
|
+
<tr>
|
|
97
|
+
<th scope="col">hh0</th>
|
|
98
|
+
<th scope="col">hh1</th>
|
|
99
|
+
<th scope="col">hh2</th>
|
|
100
|
+
</tr>
|
|
101
|
+
</thead>
|
|
102
|
+
<tbody>
|
|
103
|
+
<tr>
|
|
104
|
+
<th scope="row">vh1</th>
|
|
105
|
+
<td>11</td>
|
|
106
|
+
<td>12</td>
|
|
107
|
+
</tr>
|
|
108
|
+
<tr>
|
|
109
|
+
<th scope="row">vh2</th>
|
|
110
|
+
<td>21</td>
|
|
111
|
+
<td>22</td>
|
|
112
|
+
</tr>
|
|
113
|
+
</tbody>
|
|
114
|
+
</table>
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
[Markdown]
|
|
118
|
+
| **hh0** | hh1 | hh2 |
|
|
119
|
+
| ------- | ---- | ---- |
|
|
120
|
+
| **vh1** | 11 | 12 |
|
|
121
|
+
| **vh2** | 21 | 22 |
|
|
122
|
+
[HTML]
|
|
123
|
+
<table>
|
|
124
|
+
<thead>
|
|
125
|
+
<tr>
|
|
126
|
+
<th scope="col">hh0</th>
|
|
127
|
+
<th scope="col">hh1</th>
|
|
128
|
+
<th scope="col">hh2</th>
|
|
129
|
+
</tr>
|
|
130
|
+
</thead>
|
|
131
|
+
<tbody>
|
|
132
|
+
<tr>
|
|
133
|
+
<th scope="row">vh1</th>
|
|
134
|
+
<td>11</td>
|
|
135
|
+
<td>12</td>
|
|
136
|
+
</tr>
|
|
137
|
+
<tr>
|
|
138
|
+
<th scope="row">vh2</th>
|
|
139
|
+
<td>21</td>
|
|
140
|
+
<td>22</td>
|
|
141
|
+
</tr>
|
|
142
|
+
</tbody>
|
|
143
|
+
</table>
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
[Markdown]
|
|
147
|
+
| **hh0** | hh1 | hh2 |
|
|
148
|
+
| ------- | ---- | ---- |
|
|
149
|
+
| v1 | 11 | 12 |
|
|
150
|
+
| **vh2** | 21 | 22 |
|
|
151
|
+
[HTML]
|
|
152
|
+
<table>
|
|
153
|
+
<thead>
|
|
154
|
+
<tr>
|
|
155
|
+
<th scope="col"><strong>hh0</strong></th>
|
|
156
|
+
<th scope="col">hh1</th>
|
|
157
|
+
<th scope="col">hh2</th>
|
|
158
|
+
</tr>
|
|
159
|
+
</thead>
|
|
160
|
+
<tbody>
|
|
161
|
+
<tr>
|
|
162
|
+
<td>v1</td>
|
|
163
|
+
<td>11</td>
|
|
164
|
+
<td>12</td>
|
|
165
|
+
</tr>
|
|
166
|
+
<tr>
|
|
167
|
+
<td><strong>vh2</strong></td>
|
|
168
|
+
<td>21</td>
|
|
169
|
+
<td>22</td>
|
|
170
|
+
</tr>
|
|
171
|
+
</tbody>
|
|
172
|
+
</table>
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
[Markdown]
|
|
176
|
+
| hh0 | hh1 | hh2 |
|
|
177
|
+
| ------- | ---- | ---- |
|
|
178
|
+
| **vh1** | 11 | 12 |
|
|
179
|
+
| **vh2** | 21 | 22 |
|
|
180
|
+
[HTML]
|
|
181
|
+
<table>
|
|
182
|
+
<thead>
|
|
183
|
+
<tr>
|
|
184
|
+
<th scope="col">hh0</th>
|
|
185
|
+
<th scope="col">hh1</th>
|
|
186
|
+
<th scope="col">hh2</th>
|
|
187
|
+
</tr>
|
|
188
|
+
</thead>
|
|
189
|
+
<tbody>
|
|
190
|
+
<tr>
|
|
191
|
+
<td><strong>vh1</strong></td>
|
|
192
|
+
<td>11</td>
|
|
193
|
+
<td>12</td>
|
|
194
|
+
</tr>
|
|
195
|
+
<tr>
|
|
196
|
+
<td><strong>vh2</strong></td>
|
|
197
|
+
<td>21</td>
|
|
198
|
+
<td>22</td>
|
|
199
|
+
</tr>
|
|
200
|
+
</tbody>
|
|
201
|
+
</table>
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
[Markdown]
|
|
205
|
+
| ------- | ---- | ---- |
|
|
206
|
+
| **vh1** | 11 | 12 |
|
|
207
|
+
| **vh2** | 21 | 22 |
|
|
208
|
+
[HTML]
|
|
209
|
+
<table>
|
|
210
|
+
<tbody>
|
|
211
|
+
<tr>
|
|
212
|
+
<th scope="row">vh1</th>
|
|
213
|
+
<td>11</td>
|
|
214
|
+
<td>12</td>
|
|
215
|
+
</tr>
|
|
216
|
+
<tr>
|
|
217
|
+
<th scope="row">vh2</th>
|
|
218
|
+
<td>21</td>
|
|
219
|
+
<td>22</td>
|
|
220
|
+
</tr>
|
|
221
|
+
</tbody>
|
|
222
|
+
</table>
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
[Markdown]
|
|
227
|
+
| **hh0** | hh1 | hh2 |
|
|
228
|
+
| ------- | ---- | ---- |
|
|
229
|
+
| **vh1** | 11 | 12 |
|
|
230
|
+
| **vh2** | 21 | 22 |
|
|
231
|
+
|
|
232
|
+
<!-- -->
|
|
233
|
+
|
|
234
|
+
| **hh0** | hh1 | hh2 |
|
|
235
|
+
| ------- | ---- | ---- |
|
|
236
|
+
| **vh1** | 11 | 12 |
|
|
237
|
+
| **vh2** | 21 | 22 |
|
|
238
|
+
[HTML]
|
|
239
|
+
<table>
|
|
240
|
+
<thead>
|
|
241
|
+
<tr>
|
|
242
|
+
<th scope="col">hh0</th>
|
|
243
|
+
<th scope="col">hh1</th>
|
|
244
|
+
<th scope="col">hh2</th>
|
|
245
|
+
</tr>
|
|
246
|
+
</thead>
|
|
247
|
+
<tbody>
|
|
248
|
+
<tr>
|
|
249
|
+
<th scope="row">vh1</th>
|
|
250
|
+
<td>11</td>
|
|
251
|
+
<td>12</td>
|
|
252
|
+
</tr>
|
|
253
|
+
<tr>
|
|
254
|
+
<th scope="row">vh2</th>
|
|
255
|
+
<td>21</td>
|
|
256
|
+
<td>22</td>
|
|
257
|
+
</tr>
|
|
258
|
+
</tbody>
|
|
259
|
+
</table>
|
|
260
|
+
<!-- -->
|
|
261
|
+
<table>
|
|
262
|
+
<thead>
|
|
263
|
+
<tr>
|
|
264
|
+
<th scope="col">hh0</th>
|
|
265
|
+
<th scope="col">hh1</th>
|
|
266
|
+
<th scope="col">hh2</th>
|
|
267
|
+
</tr>
|
|
268
|
+
</thead>
|
|
269
|
+
<tbody>
|
|
270
|
+
<tr>
|
|
271
|
+
<th scope="row">vh1</th>
|
|
272
|
+
<td>11</td>
|
|
273
|
+
<td>12</td>
|
|
274
|
+
</tr>
|
|
275
|
+
<tr>
|
|
276
|
+
<th scope="row">vh2</th>
|
|
277
|
+
<td>21</td>
|
|
278
|
+
<td>22</td>
|
|
279
|
+
</tr>
|
|
280
|
+
</tbody>
|
|
281
|
+
</table>
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
[Markdown]
|
|
286
|
+
| ------- | ---- | ---- |
|
|
287
|
+
| **vh1** | 11 | 12 |
|
|
288
|
+
| **vh2** | 21 | 22 |
|
|
289
|
+
|
|
290
|
+
<!-- -->
|
|
291
|
+
|
|
292
|
+
| ------- | ---- | ---- |
|
|
293
|
+
| **vh1** | 11 | 12 |
|
|
294
|
+
| **vh2** | 21 | 22 |
|
|
295
|
+
[HTML]
|
|
296
|
+
<table>
|
|
297
|
+
<tbody>
|
|
298
|
+
<tr>
|
|
299
|
+
<th scope="row">vh1</th>
|
|
300
|
+
<td>11</td>
|
|
301
|
+
<td>12</td>
|
|
302
|
+
</tr>
|
|
303
|
+
<tr>
|
|
304
|
+
<th scope="row">vh2</th>
|
|
305
|
+
<td>21</td>
|
|
306
|
+
<td>22</td>
|
|
307
|
+
</tr>
|
|
308
|
+
</tbody>
|
|
309
|
+
</table>
|
|
310
|
+
<!-- -->
|
|
311
|
+
<table>
|
|
312
|
+
<tbody>
|
|
313
|
+
<tr>
|
|
314
|
+
<th scope="row">vh1</th>
|
|
315
|
+
<td>11</td>
|
|
316
|
+
<td>12</td>
|
|
317
|
+
</tr>
|
|
318
|
+
<tr>
|
|
319
|
+
<th scope="row">vh2</th>
|
|
320
|
+
<td>21</td>
|
|
321
|
+
<td>22</td>
|
|
322
|
+
</tr>
|
|
323
|
+
</tbody>
|
|
324
|
+
</table>
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
[Markdown]
|
|
328
|
+
| **h*h*0** | hh1 | hh2 |
|
|
329
|
+
| ------- | ---- | ---- |
|
|
330
|
+
| **vh1** | 11 | 12 |
|
|
331
|
+
| **vh2** | 21 | 22 |
|
|
332
|
+
[HTML]
|
|
333
|
+
<table>
|
|
334
|
+
<thead>
|
|
335
|
+
<tr>
|
|
336
|
+
<th scope="col">h<em>h</em>0</th>
|
|
337
|
+
<th scope="col">hh1</th>
|
|
338
|
+
<th scope="col">hh2</th>
|
|
339
|
+
</tr>
|
|
340
|
+
</thead>
|
|
341
|
+
<tbody>
|
|
342
|
+
<tr>
|
|
343
|
+
<th scope="row">vh1</th>
|
|
344
|
+
<td>11</td>
|
|
345
|
+
<td>12</td>
|
|
346
|
+
</tr>
|
|
347
|
+
<tr>
|
|
348
|
+
<th scope="row">vh2</th>
|
|
349
|
+
<td>21</td>
|
|
350
|
+
<td>22</td>
|
|
351
|
+
</tr>
|
|
352
|
+
</tbody>
|
|
353
|
+
</table>
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
[Markdown]
|
|
357
|
+
| **h**h**0** | hh1 | hh2 |
|
|
358
|
+
| ------- | ---- | ---- |
|
|
359
|
+
| **v**h**1** | 11 | 12 |
|
|
360
|
+
| **vh2** | 21 | 22 |
|
|
361
|
+
[HTML]
|
|
362
|
+
<table>
|
|
363
|
+
<thead>
|
|
364
|
+
<tr>
|
|
365
|
+
<th scope="col"><strong>h</strong>h<strong>0</strong></th>
|
|
366
|
+
<th scope="col">hh1</th>
|
|
367
|
+
<th scope="col">hh2</th>
|
|
368
|
+
</tr>
|
|
369
|
+
</thead>
|
|
370
|
+
<tbody>
|
|
371
|
+
<tr>
|
|
372
|
+
<td><strong>v</strong>h<strong>1</strong></td>
|
|
373
|
+
<td>11</td>
|
|
374
|
+
<td>12</td>
|
|
375
|
+
</tr>
|
|
376
|
+
<tr>
|
|
377
|
+
<td><strong>vh2</strong></td>
|
|
378
|
+
<td>21</td>
|
|
379
|
+
<td>22</td>
|
|
380
|
+
</tr>
|
|
381
|
+
</tbody>
|
|
382
|
+
</table>
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
[Markdown]
|
|
386
|
+
| **h**h**0** | hh1 | hh2 |
|
|
387
|
+
| ------- | ---- | ---- |
|
|
388
|
+
| **v**h**1**c**d** | 11 | 12 |
|
|
389
|
+
| **vh2** | 21 | 22 |
|
|
390
|
+
[HTML]
|
|
391
|
+
<table>
|
|
392
|
+
<thead>
|
|
393
|
+
<tr>
|
|
394
|
+
<th scope="col"><strong>h</strong>h<strong>0</strong></th>
|
|
395
|
+
<th scope="col">hh1</th>
|
|
396
|
+
<th scope="col">hh2</th>
|
|
397
|
+
</tr>
|
|
398
|
+
</thead>
|
|
399
|
+
<tbody>
|
|
400
|
+
<tr>
|
|
401
|
+
<td><strong>v</strong>h<strong>1</strong>c<strong>d</strong></td>
|
|
402
|
+
<td>11</td>
|
|
403
|
+
<td>12</td>
|
|
404
|
+
</tr>
|
|
405
|
+
<tr>
|
|
406
|
+
<td><strong>vh2</strong></td>
|
|
407
|
+
<td>21</td>
|
|
408
|
+
<td>22</td>
|
|
409
|
+
</tr>
|
|
410
|
+
</tbody>
|
|
411
|
+
</table>
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
[Markdown]
|
|
2
|
+
| hh0 | hh1 | hh2 |
|
|
3
|
+
| --- | ---- | ---- |
|
|
4
|
+
| vh1 | 11 | 12 |
|
|
5
|
+
| vh2 | 21 | 22 |
|
|
6
|
+
[HTML]
|
|
7
|
+
<div class="table-wrapper">
|
|
8
|
+
<table>
|
|
9
|
+
<thead>
|
|
10
|
+
<tr>
|
|
11
|
+
<th scope="col">hh0</th>
|
|
12
|
+
<th scope="col">hh1</th>
|
|
13
|
+
<th scope="col">hh2</th>
|
|
14
|
+
</tr>
|
|
15
|
+
</thead>
|
|
16
|
+
<tbody>
|
|
17
|
+
<tr>
|
|
18
|
+
<td>vh1</td>
|
|
19
|
+
<td>11</td>
|
|
20
|
+
<td>12</td>
|
|
21
|
+
</tr>
|
|
22
|
+
<tr>
|
|
23
|
+
<td>vh2</td>
|
|
24
|
+
<td>21</td>
|
|
25
|
+
<td>22</td>
|
|
26
|
+
</tr>
|
|
27
|
+
</tbody>
|
|
28
|
+
</table>
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
[Markdown]
|
|
32
|
+
| | hh1 | hh2 |
|
|
33
|
+
| --- | ---- | ---- |
|
|
34
|
+
| vh1 | 11 | 12 |
|
|
35
|
+
| vh2 | 21 | 22 |
|
|
36
|
+
[HTML]
|
|
37
|
+
<div class="table-wrapper">
|
|
38
|
+
<table>
|
|
39
|
+
<thead>
|
|
40
|
+
<tr>
|
|
41
|
+
<th scope="col"></th>
|
|
42
|
+
<th scope="col">hh1</th>
|
|
43
|
+
<th scope="col">hh2</th>
|
|
44
|
+
</tr>
|
|
45
|
+
</thead>
|
|
46
|
+
<tbody>
|
|
47
|
+
<tr>
|
|
48
|
+
<td>vh1</td>
|
|
49
|
+
<td>11</td>
|
|
50
|
+
<td>12</td>
|
|
51
|
+
</tr>
|
|
52
|
+
<tr>
|
|
53
|
+
<td>vh2</td>
|
|
54
|
+
<td>21</td>
|
|
55
|
+
<td>22</td>
|
|
56
|
+
</tr>
|
|
57
|
+
</tbody>
|
|
58
|
+
</table>
|
|
59
|
+
</div>
|
|
60
|
+
|
|
61
|
+
[Markdown]
|
|
62
|
+
| | hh1 | hh2 |
|
|
63
|
+
| ------- | ---- | ---- |
|
|
64
|
+
| **vh1** | 11 | 12 |
|
|
65
|
+
| **vh2** | 21 | 22 |
|
|
66
|
+
[HTML]
|
|
67
|
+
<div class="table-wrapper">
|
|
68
|
+
<table>
|
|
69
|
+
<thead>
|
|
70
|
+
<tr>
|
|
71
|
+
<th scope="col"></th>
|
|
72
|
+
<th scope="col">hh1</th>
|
|
73
|
+
<th scope="col">hh2</th>
|
|
74
|
+
</tr>
|
|
75
|
+
</thead>
|
|
76
|
+
<tbody>
|
|
77
|
+
<tr>
|
|
78
|
+
<th scope="row">vh1</th>
|
|
79
|
+
<td>11</td>
|
|
80
|
+
<td>12</td>
|
|
81
|
+
</tr>
|
|
82
|
+
<tr>
|
|
83
|
+
<th scope="row">vh2</th>
|
|
84
|
+
<td>21</td>
|
|
85
|
+
<td>22</td>
|
|
86
|
+
</tr>
|
|
87
|
+
</tbody>
|
|
88
|
+
</table>
|
|
89
|
+
</div>
|
|
90
|
+
|
|
91
|
+
[Markdown]
|
|
92
|
+
| **hh0** | hh1 | hh2 |
|
|
93
|
+
| ------- | ---- | ---- |
|
|
94
|
+
| **vh1** | 11 | 12 |
|
|
95
|
+
| **vh2** | 21 | 22 |
|
|
96
|
+
[HTML]
|
|
97
|
+
<div class="table-wrapper">
|
|
98
|
+
<table>
|
|
99
|
+
<thead>
|
|
100
|
+
<tr>
|
|
101
|
+
<th scope="col">hh0</th>
|
|
102
|
+
<th scope="col">hh1</th>
|
|
103
|
+
<th scope="col">hh2</th>
|
|
104
|
+
</tr>
|
|
105
|
+
</thead>
|
|
106
|
+
<tbody>
|
|
107
|
+
<tr>
|
|
108
|
+
<th scope="row">vh1</th>
|
|
109
|
+
<td>11</td>
|
|
110
|
+
<td>12</td>
|
|
111
|
+
</tr>
|
|
112
|
+
<tr>
|
|
113
|
+
<th scope="row">vh2</th>
|
|
114
|
+
<td>21</td>
|
|
115
|
+
<td>22</td>
|
|
116
|
+
</tr>
|
|
117
|
+
</tbody>
|
|
118
|
+
</table>
|
|
119
|
+
</div>
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
[Markdown]
|
|
2
|
+
Table 1. A caption.
|
|
3
|
+
|
|
4
|
+
| hh0 | hh1 | hh2 |
|
|
5
|
+
| --- | ---- | ---- |
|
|
6
|
+
| vh1 | 11 | 12 |
|
|
7
|
+
| vh2 | 21 | 22 |
|
|
8
|
+
[HTML]
|
|
9
|
+
<figure class="f-table">
|
|
10
|
+
<figcaption><span class="f-table-label">Table 1<span class="f-table-label-joint">.</span></span> A caption.</figcaption>
|
|
11
|
+
<div class="table-wrapper">
|
|
12
|
+
<table>
|
|
13
|
+
<thead>
|
|
14
|
+
<tr>
|
|
15
|
+
<th scope="col">hh0</th>
|
|
16
|
+
<th scope="col">hh1</th>
|
|
17
|
+
<th scope="col">hh2</th>
|
|
18
|
+
</tr>
|
|
19
|
+
</thead>
|
|
20
|
+
<tbody>
|
|
21
|
+
<tr>
|
|
22
|
+
<td>vh1</td>
|
|
23
|
+
<td>11</td>
|
|
24
|
+
<td>12</td>
|
|
25
|
+
</tr>
|
|
26
|
+
<tr>
|
|
27
|
+
<td>vh2</td>
|
|
28
|
+
<td>21</td>
|
|
29
|
+
<td>22</td>
|
|
30
|
+
</tr>
|
|
31
|
+
</tbody>
|
|
32
|
+
</table>
|
|
33
|
+
</div>
|
|
34
|
+
</figure>
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
[Markdown]
|
|
38
|
+
| hh0 | hh1 | hh2 |
|
|
39
|
+
| --- | ---- | ---- |
|
|
40
|
+
| vh1 | 11 | 12 |
|
|
41
|
+
| vh2 | 21 | 22 |
|
|
42
|
+
|
|
43
|
+
Table 1. A caption.
|
|
44
|
+
[HTML]
|
|
45
|
+
<figure class="f-table">
|
|
46
|
+
<div class="table-wrapper">
|
|
47
|
+
<table>
|
|
48
|
+
<thead>
|
|
49
|
+
<tr>
|
|
50
|
+
<th scope="col">hh0</th>
|
|
51
|
+
<th scope="col">hh1</th>
|
|
52
|
+
<th scope="col">hh2</th>
|
|
53
|
+
</tr>
|
|
54
|
+
</thead>
|
|
55
|
+
<tbody>
|
|
56
|
+
<tr>
|
|
57
|
+
<td>vh1</td>
|
|
58
|
+
<td>11</td>
|
|
59
|
+
<td>12</td>
|
|
60
|
+
</tr>
|
|
61
|
+
<tr>
|
|
62
|
+
<td>vh2</td>
|
|
63
|
+
<td>21</td>
|
|
64
|
+
<td>22</td>
|
|
65
|
+
</tr>
|
|
66
|
+
</tbody>
|
|
67
|
+
</table>
|
|
68
|
+
</div>
|
|
69
|
+
<figcaption><span class="f-table-label">Table 1<span class="f-table-label-joint">.</span></span> A caption.</figcaption>
|
|
70
|
+
</figure>
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
[Markdown]
|
|
74
|
+
| **hh0** | hh1 | hh2 |
|
|
75
|
+
| ------- | ---- | ---- |
|
|
76
|
+
| **vh1** | 11 | 12 |
|
|
77
|
+
| **vh2** | 21 | 22 |
|
|
78
|
+
|
|
79
|
+
Table 1. A caption.
|
|
80
|
+
|
|
81
|
+
Table 2. A caption.
|
|
82
|
+
|
|
83
|
+
| **hh0** | hh1 | hh2 |
|
|
84
|
+
| ------- | ---- | ---- |
|
|
85
|
+
| **vh1** | 11 | 12 |
|
|
86
|
+
| **vh2** | 21 | 22 |
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
[HTML]
|
|
90
|
+
<figure class="f-table">
|
|
91
|
+
<div class="table-wrapper">
|
|
92
|
+
<table>
|
|
93
|
+
<thead>
|
|
94
|
+
<tr>
|
|
95
|
+
<th scope="col">hh0</th>
|
|
96
|
+
<th scope="col">hh1</th>
|
|
97
|
+
<th scope="col">hh2</th>
|
|
98
|
+
</tr>
|
|
99
|
+
</thead>
|
|
100
|
+
<tbody>
|
|
101
|
+
<tr>
|
|
102
|
+
<th scope="row">vh1</th>
|
|
103
|
+
<td>11</td>
|
|
104
|
+
<td>12</td>
|
|
105
|
+
</tr>
|
|
106
|
+
<tr>
|
|
107
|
+
<th scope="row">vh2</th>
|
|
108
|
+
<td>21</td>
|
|
109
|
+
<td>22</td>
|
|
110
|
+
</tr>
|
|
111
|
+
</tbody>
|
|
112
|
+
</table>
|
|
113
|
+
</div>
|
|
114
|
+
<figcaption><span class="f-table-label">Table 1<span class="f-table-label-joint">.</span></span> A caption.</figcaption>
|
|
115
|
+
</figure>
|
|
116
|
+
<figure class="f-table">
|
|
117
|
+
<figcaption><span class="f-table-label">Table 2<span class="f-table-label-joint">.</span></span> A caption.</figcaption>
|
|
118
|
+
<div class="table-wrapper">
|
|
119
|
+
<table>
|
|
120
|
+
<thead>
|
|
121
|
+
<tr>
|
|
122
|
+
<th scope="col">hh0</th>
|
|
123
|
+
<th scope="col">hh1</th>
|
|
124
|
+
<th scope="col">hh2</th>
|
|
125
|
+
</tr>
|
|
126
|
+
</thead>
|
|
127
|
+
<tbody>
|
|
128
|
+
<tr>
|
|
129
|
+
<th scope="row">vh1</th>
|
|
130
|
+
<td>11</td>
|
|
131
|
+
<td>12</td>
|
|
132
|
+
</tr>
|
|
133
|
+
<tr>
|
|
134
|
+
<th scope="row">vh2</th>
|
|
135
|
+
<td>21</td>
|
|
136
|
+
<td>22</td>
|
|
137
|
+
</tr>
|
|
138
|
+
</tbody>
|
|
139
|
+
</table>
|
|
140
|
+
</div>
|
|
141
|
+
</figure>
|
package/test/test.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import assert from 'assert'
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
import path from 'path'
|
|
4
|
+
import mdit from 'markdown-it'
|
|
5
|
+
import mditFigureWithPCaption from '@peaceroad/markdown-it-figure-with-p-caption'
|
|
6
|
+
import mditMultimdTable from 'markdown-it-multimd-table'
|
|
7
|
+
|
|
8
|
+
import mditTableEx from '../index.js'
|
|
9
|
+
|
|
10
|
+
const md = mdit({ html: true }).use(mditMultimdTable, {
|
|
11
|
+
headerless: true,
|
|
12
|
+
multiline: true,
|
|
13
|
+
rowspan: true,
|
|
14
|
+
}).use(mditTableEx)
|
|
15
|
+
const mdWrapper = mdit({ html: true }).use(mditMultimdTable, {
|
|
16
|
+
headerless: true,
|
|
17
|
+
multiline: true,
|
|
18
|
+
rowspan: true,
|
|
19
|
+
}).use(mditTableEx, { wrapper: true })
|
|
20
|
+
const mdWrapperWithCaption = mdit({ html: true }).use(mditFigureWithPCaption).use(mditMultimdTable, {
|
|
21
|
+
headerless: true,
|
|
22
|
+
multiline: true,
|
|
23
|
+
rowspan: true,
|
|
24
|
+
}).use(mditTableEx, { wrapper: true })
|
|
25
|
+
|
|
26
|
+
let __dirname = path.dirname(new URL(import.meta.url).pathname)
|
|
27
|
+
const isWindows = (process.platform === 'win32')
|
|
28
|
+
if (isWindows) {
|
|
29
|
+
__dirname = __dirname.replace(/^\/+/, '').replace(/\//g, '\\')
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const testData = {
|
|
33
|
+
noOption: __dirname + path.sep + 'examples.txt',
|
|
34
|
+
wrapper: __dirname + path.sep + 'examples_wrapper.txt',
|
|
35
|
+
wrapperWithCaption: __dirname + path.sep + 'examples_wrapper_with_caption.txt',
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const getTestData = (pat) => {
|
|
39
|
+
let ms = [];
|
|
40
|
+
if(!fs.existsSync(pat)) {
|
|
41
|
+
console.log('No exist: ' + pat)
|
|
42
|
+
return ms
|
|
43
|
+
}
|
|
44
|
+
const exampleCont = fs.readFileSync(pat, 'utf-8').trim();
|
|
45
|
+
|
|
46
|
+
let ms0 = exampleCont.split(/\n*\[Markdown\]\n/);
|
|
47
|
+
let n = 1;
|
|
48
|
+
while(n < ms0.length) {
|
|
49
|
+
let mhs = ms0[n].split(/\n+\[HTML[^\]]*?\]\n/);
|
|
50
|
+
let i = 1;
|
|
51
|
+
while (i < 2) {
|
|
52
|
+
if (mhs[i] === undefined) {
|
|
53
|
+
mhs[i] = '';
|
|
54
|
+
} else {
|
|
55
|
+
mhs[i] = mhs[i].replace(/$/,'\n');
|
|
56
|
+
}
|
|
57
|
+
i++;
|
|
58
|
+
}
|
|
59
|
+
ms[n] = {
|
|
60
|
+
"markdown": mhs[0],
|
|
61
|
+
"html": mhs[1],
|
|
62
|
+
};
|
|
63
|
+
n++;
|
|
64
|
+
}
|
|
65
|
+
return ms
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const runTest = (process, pat, pass, testId) => {
|
|
69
|
+
console.log('===========================================================')
|
|
70
|
+
console.log(pat)
|
|
71
|
+
let ms = getTestData(pat)
|
|
72
|
+
if (ms.length === 0) return
|
|
73
|
+
let n = 1;
|
|
74
|
+
let end = ms.length - 1
|
|
75
|
+
if(testId) {
|
|
76
|
+
if (testId[0]) n = testId[0]
|
|
77
|
+
if (testId[1]) {
|
|
78
|
+
if (ms.length >= testId[1]) {
|
|
79
|
+
end = testId[1]
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
//console.log(n, end)
|
|
84
|
+
|
|
85
|
+
while(n <= end) {
|
|
86
|
+
|
|
87
|
+
if (!ms[n]
|
|
88
|
+
// || n != 3
|
|
89
|
+
) {
|
|
90
|
+
n++
|
|
91
|
+
continue
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const m = ms[n].markdown;
|
|
95
|
+
const h = process.render(m)
|
|
96
|
+
console.log('Test: ' + n + ' >>>');
|
|
97
|
+
try {
|
|
98
|
+
assert.strictEqual(h, ms[n].html);
|
|
99
|
+
} catch(e) {
|
|
100
|
+
pass = false
|
|
101
|
+
//console.log('Test: ' + n + ' >>>');
|
|
102
|
+
//console.log(opt);
|
|
103
|
+
console.log(ms[n].markdown);
|
|
104
|
+
console.log('incorrect:');
|
|
105
|
+
console.log('H: ' + h +'C: ' + ms[n].html);
|
|
106
|
+
}
|
|
107
|
+
n++;
|
|
108
|
+
}
|
|
109
|
+
return pass
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
let pass = true
|
|
113
|
+
pass = runTest(md, testData.noOption, pass)
|
|
114
|
+
pass = runTest(mdWrapper, testData.wrapper, pass)
|
|
115
|
+
pass = runTest(mdWrapperWithCaption, testData.wrapperWithCaption, pass)
|
|
116
|
+
|
|
117
|
+
if (pass) console.log('Passed all test.')
|