@cobapen/markdown 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/README.md +6 -1
- package/dist/code/fence-custom.d.ts +1 -1
- package/dist/code/fence-custom.js +37 -37
- package/dist/code/highlight.js +37 -41
- package/dist/code/info-string.d.ts +21 -21
- package/dist/code/info-string.js +121 -141
- package/dist/index.d.ts +37 -11
- package/dist/index.js +63 -51
- package/dist/link/replacelink.d.ts +8 -0
- package/dist/link/replacelink.js +41 -0
- package/dist/math/mathjax.d.ts +49 -49
- package/dist/math/mathjax.js +71 -69
- package/dist/math/mdmath.js +39 -39
- package/dist/math/mdparser.js +116 -116
- package/package.json +6 -9
package/dist/math/mdparser.js
CHANGED
|
@@ -8,141 +8,141 @@
|
|
|
8
8
|
* Assumes that there is a "$" at state.src[pos]
|
|
9
9
|
*/
|
|
10
10
|
function isValidDelim(state, pos) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
const max = state.posMax;
|
|
12
|
+
let can_open = true;
|
|
13
|
+
let can_close = true;
|
|
14
|
+
const prevChar = pos > 0 ? state.src.charCodeAt(pos - 1) : -1;
|
|
15
|
+
const nextChar = pos + 1 <= max ? state.src.charCodeAt(pos + 1) : -1;
|
|
16
|
+
// Check non-whitespace conditions for opening and closing, and
|
|
17
|
+
// check that closing delimeter isn't followed by a number
|
|
18
|
+
if (prevChar === 0x20 /* " " */ ||
|
|
19
19
|
prevChar === 0x09 /* \t */ ||
|
|
20
20
|
(nextChar >= 0x30 /* "0" */ && nextChar <= 0x39) /* "9" */) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
21
|
+
can_close = false;
|
|
22
|
+
}
|
|
23
|
+
if (nextChar === 0x20 /* " " */ || nextChar === 0x09 /* \t */) {
|
|
24
|
+
can_open = false;
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
can_open: can_open,
|
|
28
|
+
can_close: can_close,
|
|
29
|
+
};
|
|
30
30
|
}
|
|
31
31
|
export function math_inline(state, silent) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
state.pos += 1;
|
|
42
|
-
return true;
|
|
32
|
+
let match, token, res, pos;
|
|
33
|
+
if (state.src[state.pos] !== "$") {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
res = isValidDelim(state, state.pos);
|
|
37
|
+
if (!res.can_open) {
|
|
38
|
+
if (!silent) {
|
|
39
|
+
state.pending += "$";
|
|
43
40
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
match += 1;
|
|
41
|
+
state.pos += 1;
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
// First check for and bypass all properly escaped delimieters
|
|
45
|
+
// This loop will assume that the first leading backtick can not
|
|
46
|
+
// be the first character in state.src, which is known since
|
|
47
|
+
// we have found an opening delimieter already.
|
|
48
|
+
const start = state.pos + 1;
|
|
49
|
+
match = start;
|
|
50
|
+
while ((match = state.src.indexOf("$", match)) !== -1) {
|
|
51
|
+
// Found potential $, look for escapes, pos will point to
|
|
52
|
+
// first non escape when complete
|
|
53
|
+
pos = match - 1;
|
|
54
|
+
while (state.src[pos] === "\\") {
|
|
55
|
+
pos -= 1;
|
|
62
56
|
}
|
|
63
|
-
//
|
|
64
|
-
if (match
|
|
65
|
-
|
|
66
|
-
state.pending += "$";
|
|
67
|
-
}
|
|
68
|
-
state.pos = start;
|
|
69
|
-
return true;
|
|
57
|
+
// Even number of escapes, potential closing delimiter found
|
|
58
|
+
if ((match - pos) % 2 == 1) {
|
|
59
|
+
break;
|
|
70
60
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return true;
|
|
61
|
+
match += 1;
|
|
62
|
+
}
|
|
63
|
+
// No closing delimter found. Consume $ and continue.
|
|
64
|
+
if (match === -1) {
|
|
65
|
+
if (!silent) {
|
|
66
|
+
state.pending += "$";
|
|
78
67
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return true;
|
|
68
|
+
state.pos = start;
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
// Check if we have empty content, ie: $$. Do not parse.
|
|
72
|
+
if (match - start === 0) {
|
|
73
|
+
if (!silent) {
|
|
74
|
+
state.pending += "$$";
|
|
87
75
|
}
|
|
76
|
+
state.pos = start + 1;
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
// Check for valid closing delimiter
|
|
80
|
+
res = isValidDelim(state, match);
|
|
81
|
+
if (!res.can_close) {
|
|
88
82
|
if (!silent) {
|
|
89
|
-
|
|
90
|
-
token.markup = "$";
|
|
91
|
-
token.content = state.src.slice(start, match);
|
|
83
|
+
state.pending += "$";
|
|
92
84
|
}
|
|
93
|
-
state.pos =
|
|
85
|
+
state.pos = start;
|
|
94
86
|
return true;
|
|
87
|
+
}
|
|
88
|
+
if (!silent) {
|
|
89
|
+
token = state.push("math_inline", "math", 0);
|
|
90
|
+
token.markup = "$";
|
|
91
|
+
token.content = state.src.slice(start, match);
|
|
92
|
+
}
|
|
93
|
+
state.pos = match + 1;
|
|
94
|
+
return true;
|
|
95
95
|
}
|
|
96
96
|
export function math_block(state, start, end, silent) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
97
|
+
let firstLine;
|
|
98
|
+
let lastLine;
|
|
99
|
+
let next;
|
|
100
|
+
let lastPos;
|
|
101
|
+
let found = false;
|
|
102
|
+
let pos = state.bMarks[start] + state.tShift[start];
|
|
103
|
+
let max = state.eMarks[start];
|
|
104
|
+
if (pos + 2 > max) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
if (state.src.slice(pos, pos + 2) !== "$$") {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
pos += 2;
|
|
111
|
+
firstLine = state.src.slice(pos, max);
|
|
112
|
+
if (silent) {
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
if (firstLine.trim().slice(-2) === "$$") {
|
|
116
|
+
// Single line expression
|
|
117
|
+
firstLine = firstLine.trim().slice(0, -2);
|
|
118
|
+
found = true;
|
|
119
|
+
}
|
|
120
|
+
for (next = start; !found;) {
|
|
121
|
+
next++;
|
|
122
|
+
if (next >= end) {
|
|
123
|
+
break;
|
|
114
124
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
125
|
+
pos = state.bMarks[next] + state.tShift[next];
|
|
126
|
+
max = state.eMarks[next];
|
|
127
|
+
if (pos < max && state.tShift[next] < state.blkIndent) {
|
|
128
|
+
// non-empty line with negative indent should stop the list:
|
|
129
|
+
break;
|
|
119
130
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
pos = state.bMarks[next] + state.tShift[next];
|
|
126
|
-
max = state.eMarks[next];
|
|
127
|
-
if (pos < max && state.tShift[next] < state.blkIndent) {
|
|
128
|
-
// non-empty line with negative indent should stop the list:
|
|
129
|
-
break;
|
|
130
|
-
}
|
|
131
|
-
if (state.src.slice(pos, max).trim().slice(-2) === "$$") {
|
|
132
|
-
lastPos = state.src.slice(0, max).lastIndexOf("$$");
|
|
133
|
-
lastLine = state.src.slice(pos, lastPos);
|
|
134
|
-
found = true;
|
|
135
|
-
}
|
|
131
|
+
if (state.src.slice(pos, max).trim().slice(-2) === "$$") {
|
|
132
|
+
lastPos = state.src.slice(0, max).lastIndexOf("$$");
|
|
133
|
+
lastLine = state.src.slice(pos, lastPos);
|
|
134
|
+
found = true;
|
|
136
135
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
136
|
+
}
|
|
137
|
+
state.line = next + 1;
|
|
138
|
+
const token = state.push("math_block", "math", 0);
|
|
139
|
+
token.block = true;
|
|
140
|
+
token.content =
|
|
141
141
|
(firstLine && firstLine.trim() ? firstLine + "\n" : "") +
|
|
142
142
|
state.getLines(start + 1, next, state.tShift[start], true) +
|
|
143
143
|
(lastLine && lastLine.trim() ? lastLine : "");
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
144
|
+
token.map = [start, state.line];
|
|
145
|
+
token.markup = "$$";
|
|
146
|
+
return true;
|
|
147
147
|
}
|
|
148
148
|
//# sourceMappingURL=mdparser.js.map
|
package/package.json
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cobapen/markdown",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "A markdown converter for cobapen website",
|
|
5
|
+
"keywords": ["markdown"],
|
|
5
6
|
"license": "MIT",
|
|
6
7
|
"author": "yamavol",
|
|
7
8
|
"type": "module",
|
|
8
9
|
"main": "dist/index.js",
|
|
9
10
|
"types": "dist/index.d.ts",
|
|
10
|
-
"directories": {
|
|
11
|
-
"doc": "docs",
|
|
12
|
-
"test": "tests"
|
|
13
|
-
},
|
|
14
|
-
"keywords": [
|
|
15
|
-
"markdown"
|
|
16
|
-
],
|
|
17
11
|
"homepage": "https://github.com/cobapen/markdown#readme",
|
|
18
12
|
"bugs": {
|
|
19
13
|
"url": "https://github.com/cobapen/markdown/issues"
|
|
@@ -30,7 +24,10 @@
|
|
|
30
24
|
"build": "tsc",
|
|
31
25
|
"build:doc": "tsc && node docs/build.js",
|
|
32
26
|
"test": "vitest",
|
|
33
|
-
"coverage": "vitest run --coverage"
|
|
27
|
+
"coverage": "vitest run --coverage",
|
|
28
|
+
"lint": "eslint src",
|
|
29
|
+
"lint:fix": "eslint src --fix",
|
|
30
|
+
"lint:dist": "eslint dist --fix"
|
|
34
31
|
},
|
|
35
32
|
"dependencies": {
|
|
36
33
|
"highlight.js": "^11.11.1",
|