mathpix-markdown-it 2.0.37 → 2.0.38
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/doc/changelog.md +16 -0
- package/es5/bundle.js +1 -1
- package/es5/index.js +1 -1
- package/lib/markdown/md-inline-rule/diagbox-inline.js +46 -46
- package/lib/markdown/md-inline-rule/diagbox-inline.js.map +1 -1
- package/lib/markdown/md-inline-rule/mmd-icon.js +42 -46
- package/lib/markdown/md-inline-rule/mmd-icon.js.map +1 -1
- package/package.json +1 -1
- package/pr-specs/2026-03-fix-silent-mode-state-pos.md +103 -0
|
@@ -46,55 +46,55 @@ var inlineDiagbox = function (state, silent) {
|
|
|
46
46
|
match = consts_1.reDiagbox.exec(str);
|
|
47
47
|
if (!match)
|
|
48
48
|
return false;
|
|
49
|
-
if (silent)
|
|
50
|
-
return true;
|
|
51
49
|
var index = match.index;
|
|
52
|
-
var options = match[2] || '';
|
|
53
|
-
var isSW = false;
|
|
54
|
-
if (match[1] === 'slashbox') {
|
|
55
|
-
isSW = true;
|
|
56
|
-
}
|
|
57
|
-
var attributes = (0, parse_attribures_1.parseAttributes)(options);
|
|
58
|
-
if ((attributes === null || attributes === void 0 ? void 0 : attributes.dir) === 'SW' || (attributes === null || attributes === void 0 ? void 0 : attributes.dir) === 'NE') {
|
|
59
|
-
isSW = true;
|
|
60
|
-
}
|
|
61
50
|
var _a = tslib_1.__read((0, sub_cell_1.extractNextBraceContent)(str, index + match[0].length), 2), left = _a[0], newIndex = _a[1];
|
|
62
51
|
var _b = tslib_1.__read((0, sub_cell_1.extractNextBraceContent)(str, newIndex), 2), right = _b[0], endIndex = _b[1];
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
token.
|
|
84
|
-
|
|
85
|
-
var
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
52
|
+
if (!silent) {
|
|
53
|
+
var options = match[2] || '';
|
|
54
|
+
var isSW = false;
|
|
55
|
+
if (match[1] === 'slashbox') {
|
|
56
|
+
isSW = true;
|
|
57
|
+
}
|
|
58
|
+
var attributes = (0, parse_attribures_1.parseAttributes)(options);
|
|
59
|
+
if ((attributes === null || attributes === void 0 ? void 0 : attributes.dir) === 'SW' || (attributes === null || attributes === void 0 ? void 0 : attributes.dir) === 'NE') {
|
|
60
|
+
isSW = true;
|
|
61
|
+
}
|
|
62
|
+
left = left ? (0, sub_math_1.getSubMath)(left) : '';
|
|
63
|
+
right = right ? (0, sub_math_1.getSubMath)(right) : '';
|
|
64
|
+
left = left.split('\n').join('').trim();
|
|
65
|
+
right = right.split('\n').join('').trim();
|
|
66
|
+
left = left.split('\\\\').join('\n');
|
|
67
|
+
right = right.split('\\\\').join('\n');
|
|
68
|
+
var token = isSW ? state.push('slashbox', '', 0) : state.push('backslashbox', '', 0);
|
|
69
|
+
token.attrJoin('class', "diagonal-cell");
|
|
70
|
+
token.attrJoin('style', 'grid-template-columns: repeat(2, 1fr); padding: 0;');
|
|
71
|
+
token.content = '';
|
|
72
|
+
token.latex = match[0];
|
|
73
|
+
token.children = [];
|
|
74
|
+
var leftContent = processContent(left);
|
|
75
|
+
var rightContent = processContent(right);
|
|
76
|
+
var tokenLeft = createDiagboxItemToken(state, leftContent);
|
|
77
|
+
var tokenRight = createDiagboxItemToken(state, rightContent);
|
|
78
|
+
if (isSW) {
|
|
79
|
+
tokenLeft.attrJoin('class', "cell-item diagonal-cell-topLeft");
|
|
80
|
+
var styleTopLeft = ['grid-row-start: 1;', 'grid-column-start: 1;', 'text-align: left; white-space: nowrap; min-height: 1.5em;'];
|
|
81
|
+
tokenLeft.attrJoin('style', styleTopLeft.join(' '));
|
|
82
|
+
token.children.push(tokenLeft);
|
|
83
|
+
tokenRight.attrJoin('class', "cell-item diagonal-cell-bottomRight");
|
|
84
|
+
var styleBottomRight = ['grid-row-start: 2;', 'grid-column-start: 2;', 'text-align: right; white-space: nowrap; min-height: 1.5em; margin-top: auto;'];
|
|
85
|
+
tokenRight.attrJoin('style', styleBottomRight.join(' '));
|
|
86
|
+
token.children.push(tokenRight);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
tokenRight.attrJoin('class', "cell-item diagonal-cell-topRight");
|
|
90
|
+
var styleTopRight = ['grid-row-start: 1;', 'grid-column-start: 2;', 'text-align: right; white-space: nowrap; min-height: 1.5em;'];
|
|
91
|
+
tokenRight.attrJoin('style', styleTopRight.join(' '));
|
|
92
|
+
token.children.push(tokenRight);
|
|
93
|
+
tokenLeft.attrJoin('class', "cell-item diagonal-cell-bottomLeft");
|
|
94
|
+
var styleBottomLeft = ['grid-row-start: 2;', 'grid-column-start: 1;', 'text-align: left; white-space: nowrap; min-height: 1.5em; margin-top: auto;'];
|
|
95
|
+
tokenLeft.attrJoin('style', styleBottomLeft.join(' '));
|
|
96
|
+
token.children.push(tokenLeft);
|
|
97
|
+
}
|
|
98
98
|
}
|
|
99
99
|
state.pos += endIndex;
|
|
100
100
|
return true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagbox-inline.js","sourceRoot":"","sources":["../../../src/markdown/md-inline-rule/diagbox-inline.ts"],"names":[],"mappings":";;;;AACA,oEAAkF;AAClF,0EAA2E;AAC3E,oEAA0F;AAC1F,gEAAmE;AACnE,2CAA6C;AAE7C,+DAA6D;AAC7D,oEAAuF;AAEvF,IAAM,cAAc,GAAG,UAAC,OAAe;IACrC,IAAI;QACF,IAAM,SAAS,GAAW,IAAA,8BAAmB,E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CAAC;aACjC;iBAAM;gBACL,UAAU,CAAC,QAAQ,CAAC,OAAO,EAAE,kCAAkC,CAAC,CAAC;gBACjE,IAAI,aAAa,GAAa,CAAC,oBAAoB,EAAE,uBAAuB,EAAE,4DAA4D,CAAC,CAAC;gBAC5I,UAAU,CAAC,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;gBACtD,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;gBAEhC,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,oCAAoC,CAAC,CAAC;gBAClE,IAAI,eAAe,GAAa,CAAC,oBAAoB,EAAE,uBAAuB,EAAE,6EAA6E,CAAC,CAAC;gBAC/J,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;gBACvD,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;aAChC;SACF;QAED,KAAK,CAAC,GAAG,IAAI,QAAQ,CAAC;QACtB,OAAO,IAAI,CAAC;KACb;IAAC,OAAO,GAAG,EAAE;QACZ,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAAC;QACjD,OAAO,KAAK,CAAC;KACd;AACH,CAAC,CAAC;AA1EW,QAAA,aAAa,iBA0ExB"}
|
|
@@ -6,60 +6,56 @@ var inlineMmdIcon = function (state, silent) {
|
|
|
6
6
|
var _a, _b;
|
|
7
7
|
try {
|
|
8
8
|
var pos = state.pos, src = state.src;
|
|
9
|
-
var match = void 0;
|
|
10
9
|
if (src.charCodeAt(pos) !== 0x5c /* \ */) {
|
|
11
10
|
return false;
|
|
12
11
|
}
|
|
13
12
|
var reIcon = /^(?:\\icon\{([^}]*)\})/;
|
|
14
|
-
match = src.slice(pos).match(reIcon);
|
|
13
|
+
var match = src.slice(pos).match(reIcon);
|
|
15
14
|
if (!match)
|
|
16
15
|
return false;
|
|
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
|
-
|
|
16
|
+
var endPos = pos + match.index + match[0].length;
|
|
17
|
+
if (!silent) {
|
|
18
|
+
var iconName = ((_a = match[1]) === null || _a === void 0 ? void 0 : _a.trim()) || '';
|
|
19
|
+
var token = void 0;
|
|
20
|
+
if (!iconName) {
|
|
21
|
+
token = state.push('text', '', 0);
|
|
22
|
+
token.content = '';
|
|
23
|
+
token.latex = match[0];
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
var _c = (0, icons_1.findIcon)(iconName), _d = _c.icon, icon = _d === void 0 ? null : _d, _e = _c.name, name_1 = _e === void 0 ? '' : _e, _f = _c.color, color = _f === void 0 ? '' : _f, _g = _c.isSquared, isSquared = _g === void 0 ? false : _g;
|
|
27
|
+
if (!name_1) {
|
|
28
|
+
token = state.push('text', '', 0);
|
|
29
|
+
token.content = '';
|
|
30
|
+
token.latex = match[0];
|
|
31
|
+
}
|
|
32
|
+
else if (!icon) {
|
|
33
|
+
token = state.push('text_error', '', 0);
|
|
34
|
+
token.content = "The icon name \"".concat(iconName, "\" can't be found.");
|
|
35
|
+
}
|
|
36
|
+
else if (isSquared) {
|
|
37
|
+
token = state.push('text_icon', '', 0);
|
|
38
|
+
token.attrJoin('style', "border: 1px solid; width: 1em; height: 1em; display: inline-block; text-align: center; line-height: 1em;");
|
|
39
|
+
if (color) {
|
|
40
|
+
token.attrJoin('style', "color: ".concat(color, ";"));
|
|
41
|
+
}
|
|
42
|
+
token.content = icon.symbol;
|
|
43
|
+
token.latex = match[0];
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
token = state.push('text_icon', '', 0);
|
|
47
|
+
token.content = icon.symbol;
|
|
48
|
+
if (color) {
|
|
49
|
+
token.attrJoin('style', "color: ".concat(color, ";"));
|
|
50
|
+
}
|
|
51
|
+
if (((_b = icon.name) === null || _b === void 0 ? void 0 : _b.indexOf('fa_')) !== -1) {
|
|
52
|
+
token.attrJoin('style', 'vertical-align: middle;');
|
|
53
|
+
}
|
|
54
|
+
token.latex = match[0];
|
|
55
|
+
}
|
|
47
56
|
}
|
|
48
|
-
token.content = icon.symbol;
|
|
49
|
-
token.latex = match[0];
|
|
50
|
-
state.pos = pos + match.index + match[0].length;
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
token = state.push('text_icon', '', 0);
|
|
54
|
-
token.content = icon.symbol;
|
|
55
|
-
if (color) {
|
|
56
|
-
token.attrJoin('style', "color: ".concat(color, ";"));
|
|
57
|
-
}
|
|
58
|
-
if (((_b = icon.name) === null || _b === void 0 ? void 0 : _b.indexOf('fa_')) !== -1) {
|
|
59
|
-
token.attrJoin('style', 'vertical-align: middle;');
|
|
60
57
|
}
|
|
61
|
-
|
|
62
|
-
state.pos = pos + match.index + match[0].length;
|
|
58
|
+
state.pos = endPos;
|
|
63
59
|
return true;
|
|
64
60
|
}
|
|
65
61
|
catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mmd-icon.js","sourceRoot":"","sources":["../../../src/markdown/md-inline-rule/mmd-icon.ts"],"names":[],"mappings":";;;AACA,6CAA+C;AAExC,IAAM,aAAa,GAAe,UAAC,KAAK,EAAE,MAAM;;IACrD,IAAI;QACM,IAAA,GAAG,GAAU,KAAK,IAAf,EAAE,GAAG,GAAK,KAAK,IAAV,CAAW;QAC3B,IAAI,
|
|
1
|
+
{"version":3,"file":"mmd-icon.js","sourceRoot":"","sources":["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ClD;oBACD,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;iBACxB;aACF;SACF;QAED,KAAK,CAAC,GAAG,GAAG,MAAM,CAAC;QACnB,OAAO,IAAI,CAAC;KAEb;IAAC,OAAO,GAAG,EAAE;QACZ,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAAC;QACjD,OAAO,KAAK,CAAC;KACd;AACH,CAAC,CAAA;AA1DY,QAAA,aAAa,iBA0DzB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mathpix-markdown-it",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.38",
|
|
4
4
|
"description": "Mathpix-markdown-it is an open source implementation of the mathpix-markdown spec written in Typescript. It relies on the following open source libraries: MathJax v3 (to render math with SVGs), markdown-it (for standard Markdown parsing)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MathJax",
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# PR: Fix infinite loop in `inlineMmdIcon` and `inlineDiagbox` silent mode
|
|
2
|
+
|
|
3
|
+
Status: Implemented
|
|
4
|
+
Owner: @OlgaRedozubova
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Context
|
|
9
|
+
|
|
10
|
+
Issue [#18088](https://github.com/Mathpix/monorepo/issues/18088) reported that typing `\icon{unknown}` after a `[` character (e.g. `[\icon{unknown}]`) causes the page to freeze. The root cause is in markdown-it's inline rule pipeline: when `parseLinkLabel` encounters content inside `[…]`, it calls `skipToken`, which invokes each inline rule in **silent mode** (`silent = true`). If a rule returns `true` without advancing `state.pos`, `skipToken` caches `pos → pos` (a no-op) and loops forever.
|
|
11
|
+
|
|
12
|
+
Same bug class as the v2.0.34 `latexListEnvInline` fix.
|
|
13
|
+
|
|
14
|
+
This was originally patched in `zenpix/` and `ocr-api/` node_modules (monorepo commit `e9f9ca2`). This PR is the permanent upstream fix in the `mathpix-markdown-it` package.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Root Cause
|
|
19
|
+
|
|
20
|
+
Two inline rules returned `true` in silent mode without advancing `state.pos`:
|
|
21
|
+
|
|
22
|
+
1. **`inlineMmdIcon`** (`src/markdown/md-inline-rule/mmd-icon.ts:16`):
|
|
23
|
+
```ts
|
|
24
|
+
if (silent) return true; // state.pos not advanced → infinite loop
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
2. **`inlineDiagbox`** (`src/markdown/md-inline-rule/diagbox-inline.ts:48`):
|
|
28
|
+
```ts
|
|
29
|
+
if (silent) return true; // state.pos not advanced → infinite loop
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
When markdown-it's `parseLinkLabel` → `skipToken` calls these rules in silent mode, the position never changes, causing an infinite loop.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Fix
|
|
37
|
+
|
|
38
|
+
Refactored both rules to follow the same `if (!silent) { ... } state.pos = endPos; return true;` pattern used by all other inline rules in the codebase (e.g. `setCounterSection`, `inlineMathML`, `inlineTabular`).
|
|
39
|
+
|
|
40
|
+
### `mmd-icon.ts`
|
|
41
|
+
|
|
42
|
+
- Compute `endPos = pos + match.index + match[0].length` once after regex match
|
|
43
|
+
- Wrap all token-creation logic in `if (!silent) { ... }`
|
|
44
|
+
- Single `state.pos = endPos; return true;` at the end
|
|
45
|
+
- Eliminates 6 duplicated `state.pos = pos + match.index + match[0].length` assignments
|
|
46
|
+
|
|
47
|
+
### `diagbox-inline.ts`
|
|
48
|
+
|
|
49
|
+
- Extract brace contents (`extractNextBraceContent`) before the silent check so `endIndex` is available in both modes
|
|
50
|
+
- Wrap all token-creation and content-processing logic in `if (!silent) { ... }`
|
|
51
|
+
- Single `state.pos += endIndex; return true;` at the end
|
|
52
|
+
- In silent mode, `extractNextBraceContent` is lightweight (just brace matching), so no performance concern
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Codebase Audit
|
|
57
|
+
|
|
58
|
+
Audited all 34 `RuleInline` implementations across the codebase. No other rules exhibit this bug pattern — all correctly advance `state.pos` before returning `true`.
|
|
59
|
+
|
|
60
|
+
| Pattern | Count | Status |
|
|
61
|
+
|---|---|---|
|
|
62
|
+
| `if (!silent) { ... } state.pos = X; return true;` | 28 | Safe |
|
|
63
|
+
| `if (silent) return false;` | 6 | Safe (never returns true in silent) |
|
|
64
|
+
| `if (silent) return true;` without pos advance | 0 | Fixed (was 2) |
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Files Changed
|
|
69
|
+
|
|
70
|
+
- `src/markdown/md-inline-rule/mmd-icon.ts` — refactored to `if (!silent)` pattern
|
|
71
|
+
- `src/markdown/md-inline-rule/diagbox-inline.ts` — refactored to `if (!silent)` pattern
|
|
72
|
+
- `tests/_data/_icon/_data.js` — 4 new test cases
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Tests Added
|
|
77
|
+
|
|
78
|
+
| Input | Triggers |
|
|
79
|
+
|---|---|
|
|
80
|
+
| `[\icon{unknown}](http://example.com)` | `parseLinkLabel` on icon inside link |
|
|
81
|
+
| `[\diagbox{A}{B}](http://example.com)` | `parseLinkLabel` on diagbox inside link |
|
|
82
|
+
| `[\icon{unknown}] text` | `parseLinkLabel` on icon inside bare brackets |
|
|
83
|
+
| `[\diagbox{A}{B}] text` | `parseLinkLabel` on diagbox inside bare brackets |
|
|
84
|
+
|
|
85
|
+
All 4 cases caused infinite loops before the fix. All 27 icon tests and 114 tabular tests pass after the fix.
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## Observability
|
|
90
|
+
|
|
91
|
+
- Type `[\icon{unknown}]` — page must not freeze
|
|
92
|
+
- Type `[\diagbox{A}{B}](http://example.com)` — page must not freeze
|
|
93
|
+
- Existing `\icon{star}`, `\icon{unknown}`, `\diagbox{A}{B}` in normal context — render unchanged
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## Done When
|
|
98
|
+
|
|
99
|
+
- [x] `[\icon{unknown}]` does not freeze the page
|
|
100
|
+
- [x] `[\diagbox{A}{B}]` does not freeze the page
|
|
101
|
+
- [x] Both rules follow the `if (!silent)` pattern consistent with all other inline rules
|
|
102
|
+
- [x] All existing icon and tabular tests pass
|
|
103
|
+
- [x] Full codebase audit confirms no other rules have this bug
|