@peaceroad/markdown-it-table-ex 0.1.0 → 0.3.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/test/test.js DELETED
@@ -1,117 +0,0 @@
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.')