@cobapen/markdown 0.3.1 → 0.4.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.
@@ -8,141 +8,140 @@
8
8
  * Assumes that there is a "$" at state.src[pos]
9
9
  */
10
10
  function isValidDelim(state, pos) {
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 /* " " */ ||
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
- 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
- };
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
- 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 += "$";
32
+ let match, token, res, pos;
33
+ if (state.src[state.pos] !== "$") {
34
+ return false;
40
35
  }
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;
36
+ res = isValidDelim(state, state.pos);
37
+ if (!res.can_open) {
38
+ if (!silent) {
39
+ state.pending += "$";
40
+ }
41
+ state.pos += 1;
42
+ return true;
56
43
  }
57
- // Even number of escapes, potential closing delimiter found
58
- if ((match - pos) % 2 == 1) {
59
- break;
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;
56
+ }
57
+ // Even number of escapes, potential closing delimiter found
58
+ if ((match - pos) % 2 == 1) {
59
+ break;
60
+ }
61
+ match += 1;
60
62
  }
61
- match += 1;
62
- }
63
- // No closing delimter found. Consume $ and continue.
64
- if (match === -1) {
65
- if (!silent) {
66
- state.pending += "$";
63
+ // No closing delimter found. Consume $ and continue.
64
+ if (match === -1) {
65
+ if (!silent) {
66
+ state.pending += "$";
67
+ }
68
+ state.pos = start;
69
+ return true;
67
70
  }
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 += "$$";
71
+ // Check if we have empty content, ie: $$. Do not parse.
72
+ if (match - start === 0) {
73
+ if (!silent) {
74
+ state.pending += "$$";
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) {
82
+ if (!silent) {
83
+ state.pending += "$";
84
+ }
85
+ state.pos = start;
86
+ return true;
75
87
  }
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) {
82
88
  if (!silent) {
83
- state.pending += "$";
89
+ token = state.push("math_inline", "math", 0);
90
+ token.markup = "$";
91
+ token.content = state.src.slice(start, match);
84
92
  }
85
- state.pos = start;
93
+ state.pos = match + 1;
86
94
  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
- 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;
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;
124
106
  }
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;
107
+ if (state.src.slice(pos, pos + 2) !== "$$") {
108
+ return false;
130
109
  }
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;
110
+ pos += 2;
111
+ firstLine = state.src.slice(pos, max);
112
+ if (silent) {
113
+ return true;
135
114
  }
136
- }
137
- state.line = next + 1;
138
- const token = state.push("math_block", "math", 0);
139
- token.block = true;
140
- token.content =
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;
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
+ }
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
- token.map = [start, state.line];
145
- token.markup = "$$";
146
- return true;
144
+ token.map = [start, state.line];
145
+ token.markup = "$$";
146
+ return true;
147
147
  }
148
- //# sourceMappingURL=mdparser.js.map
package/package.json CHANGED
@@ -1,8 +1,10 @@
1
1
  {
2
2
  "name": "@cobapen/markdown",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "A markdown converter for cobapen website",
5
- "keywords": ["markdown"],
5
+ "keywords": [
6
+ "markdown"
7
+ ],
6
8
  "license": "MIT",
7
9
  "author": "yamavol",
8
10
  "type": "module",
@@ -20,8 +22,12 @@
20
22
  "dist/**/*.js",
21
23
  "dist/**/*.d.ts"
22
24
  ],
25
+ "engines": {
26
+ "node": ">=20.11.0 <21 || >=21.2.0"
27
+ },
23
28
  "scripts": {
24
29
  "build": "tsc",
30
+ "build:dist": "tsc --build tsconfig.dist.json",
25
31
  "build:doc": "tsc && node docs/build.js",
26
32
  "test": "vitest",
27
33
  "coverage": "vitest run --coverage",
@@ -34,6 +40,7 @@
34
40
  "katex": "^0.16.22",
35
41
  "lodash-es": "^4.17.21",
36
42
  "markdown-it": "^14.1.0",
43
+ "markdown-it-adv-table": "^0.1.1",
37
44
  "markdown-it-anchor": "^9.2.0",
38
45
  "markdown-it-cjk-breaks": "^2.0.0",
39
46
  "markdown-it-deflist": "^3.0.0",
@@ -50,6 +57,7 @@
50
57
  "@types/node": "^22.14.1",
51
58
  "@vitest/coverage-v8": "^3.1.1",
52
59
  "eslint": "^9.24.0",
60
+ "eslint-plugin-import": "^2.31.0",
53
61
  "mustache": "^4.2.0",
54
62
  "typescript": "^5.8.3",
55
63
  "typescript-eslint": "^8.29.1",