mathpix-markdown-it 2.0.34 → 2.0.35
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 +10 -0
- package/es5/bundle.js +1 -1
- package/es5/index.js +1 -1
- package/lib/markdown/common/render-table-cell-content.js +14 -8
- package/lib/markdown/common/render-table-cell-content.js.map +1 -1
- package/package.json +1 -1
- package/pr-specs/2026-02-formd-delegate-image-rendering-in-table-cells.md +126 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.renderTableCellContent = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
4
5
|
var tsv_1 = require("./tsv");
|
|
5
6
|
var csv_1 = require("./csv");
|
|
6
7
|
var table_markdown_1 = require("./table-markdown");
|
|
@@ -22,7 +23,7 @@ var escapeHtml = require('markdown-it/lib/common/utils').escapeHtml;
|
|
|
22
23
|
* @returns Combined render outputs for this cell.
|
|
23
24
|
*/
|
|
24
25
|
var renderTableCellContent = function (token, isSubTable, options, env, slf) {
|
|
25
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
26
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
26
27
|
var content = '';
|
|
27
28
|
var tsvCell = '';
|
|
28
29
|
var csvCell = '';
|
|
@@ -55,9 +56,12 @@ var renderTableCellContent = function (token, isSubTable, options, env, slf) {
|
|
|
55
56
|
continue;
|
|
56
57
|
}
|
|
57
58
|
}
|
|
59
|
+
if (options === null || options === void 0 ? void 0 : options.forMD) {
|
|
60
|
+
child.meta = tslib_1.__assign(tslib_1.__assign({}, ((_a = child.meta) !== null && _a !== void 0 ? _a : {})), { isTableCell: true });
|
|
61
|
+
}
|
|
58
62
|
var rendered = slf.renderInline([child], options, env);
|
|
59
63
|
var smoothedRendered = Array.isArray(child.tableSmoothed)
|
|
60
|
-
? ((
|
|
64
|
+
? ((_b = child.tableSmoothed) === null || _b === void 0 ? void 0 : _b.length) > 0
|
|
61
65
|
? child.tableSmoothed.map(function (item) { return typeof item === 'string' ? item : item.join(' '); }).join(' <br> ')
|
|
62
66
|
: ''
|
|
63
67
|
: rendered;
|
|
@@ -72,7 +76,7 @@ var renderTableCellContent = function (token, isSubTable, options, env, slf) {
|
|
|
72
76
|
csvCell += csvAscii;
|
|
73
77
|
}
|
|
74
78
|
else if (token.type === 'subTabular') {
|
|
75
|
-
if (((
|
|
79
|
+
if (((_c = token.parents) === null || _c === void 0 ? void 0 : _c.length) || ["backslashbox", "slashbox"].includes(child.type)) {
|
|
76
80
|
tsvCell += tsvData;
|
|
77
81
|
csvCell += csvData;
|
|
78
82
|
}
|
|
@@ -122,7 +126,9 @@ var renderTableCellContent = function (token, isSubTable, options, env, slf) {
|
|
|
122
126
|
var src = child.attrGet('src');
|
|
123
127
|
tsvCell += src;
|
|
124
128
|
csvCell += src;
|
|
125
|
-
mdCell +=
|
|
129
|
+
mdCell += (options === null || options === void 0 ? void 0 : options.forMD)
|
|
130
|
+
? rendered
|
|
131
|
+
: ".concat(src, ")").replace(/\|/g, '\\|');
|
|
126
132
|
continue;
|
|
127
133
|
}
|
|
128
134
|
case 'code':
|
|
@@ -151,25 +157,25 @@ var renderTableCellContent = function (token, isSubTable, options, env, slf) {
|
|
|
151
157
|
case 'out_close':
|
|
152
158
|
continue;
|
|
153
159
|
}
|
|
154
|
-
if ((
|
|
160
|
+
if ((_e = child.tableMd) === null || _e === void 0 ? void 0 : _e.length) {
|
|
155
161
|
mdCell += child.tableMd.map(function (item) { return (typeof item === 'string' ? item : item.join(' ')); }).join(' <br> ');
|
|
156
162
|
continue;
|
|
157
163
|
}
|
|
158
164
|
mdCell += (0, table_markdown_1.getMdForChild)(child);
|
|
159
165
|
if (child.latex) {
|
|
160
166
|
var outMath = options.outMath;
|
|
161
|
-
if (((
|
|
167
|
+
if (((_f = outMath === null || outMath === void 0 ? void 0 : outMath.table_markdown) === null || _f === void 0 ? void 0 : _f.math_as_ascii) && ascii) {
|
|
162
168
|
mdCell += child.ascii_md || ascii;
|
|
163
169
|
continue;
|
|
164
170
|
}
|
|
165
171
|
var begin_math_inline_delimiters = '$';
|
|
166
172
|
var end_math_inline_delimiters = '$';
|
|
167
|
-
if (((
|
|
173
|
+
if (((_j = (_h = (_g = options.outMath) === null || _g === void 0 ? void 0 : _g.table_markdown) === null || _h === void 0 ? void 0 : _h.math_inline_delimiters) === null || _j === void 0 ? void 0 : _j.length) > 1) {
|
|
168
174
|
begin_math_inline_delimiters = options.outMath.table_markdown.math_inline_delimiters[0];
|
|
169
175
|
end_math_inline_delimiters = options.outMath.table_markdown.math_inline_delimiters[1];
|
|
170
176
|
}
|
|
171
177
|
var mdContent = consts_1.mathTokenTypes.includes(child.type)
|
|
172
|
-
? begin_math_inline_delimiters + ((
|
|
178
|
+
? begin_math_inline_delimiters + ((_k = child.content) === null || _k === void 0 ? void 0 : _k.trim()) + end_math_inline_delimiters
|
|
173
179
|
: child.latex;
|
|
174
180
|
mdCell += mdContent
|
|
175
181
|
.replace(/\|/g, '\\|')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-table-cell-content.js","sourceRoot":"","sources":["../../../src/markdown/common/render-table-cell-content.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"render-table-cell-content.js","sourceRoot":"","sources":["../../../src/markdown/common/render-table-cell-content.ts"],"names":[],"mappings":";;;;AAAA,6BAAgC;AAChC,6BAAgC;AAChC,mDAA4D;AAC5D,mCAA0C;AAC1C,oCAAyC;AACzC,IAAM,UAAU,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAAC,UAAU,CAAC;AAetE;;;;;;;;;;;;;GAaG;AACI,IAAM,sBAAsB,GAAG,UACpC,KAAK,EACL,UAAmB,EACnB,OAAO,EACP,GAAG,EACH,GAAG;;IAEH,IAAI,OAAO,GAAW,EAAE,CAAC;IACzB,IAAI,OAAO,GAAG,E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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,126 @@
|
|
|
1
|
+
# PR: Delegate image rendering in table cells when `forMD` is set
|
|
2
|
+
|
|
3
|
+
Status: Active
|
|
4
|
+
Owner: @OlgaRedozubova
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Context
|
|
9
|
+
|
|
10
|
+
`renderTableCellContent()` hardcodes `` markdown for `image` and `includegraphics` tokens, bypassing any custom render rules the caller has registered on the markdown-it renderer. The function already calls `slf.renderInline([child])` for every child token and stores the result in `rendered`, but for images this result is discarded.
|
|
11
|
+
|
|
12
|
+
This means callers that register custom image render rules (e.g., to resolve CDN URLs to local paths, apply sizing, or add custom formatting) have no way to control how images inside table cells are rendered in the markdown output.
|
|
13
|
+
|
|
14
|
+
## Goal
|
|
15
|
+
|
|
16
|
+
When `options.forMD` is true, `renderTableCellContent` should use the renderer's output for `image`/`includegraphics` tokens instead of hardcoding ``. This allows callers (like mmd-converter) to resolve image paths, apply custom formatting, and handle pipe escaping through their own render rules.
|
|
17
|
+
|
|
18
|
+
## Non-Goals
|
|
19
|
+
|
|
20
|
+
- Changing HTML, TSV, CSV, or DOCX/PPTX rendering of table images
|
|
21
|
+
- Changing behavior when `forMD` is not set (default path is unchanged)
|
|
22
|
+
- Adding image resolution logic to mathpix-markdown-it itself (that stays in mmd-converter)
|
|
23
|
+
|
|
24
|
+
## Current Behavior
|
|
25
|
+
|
|
26
|
+
In `renderTableCellContent()`, every child token is rendered via `slf.renderInline([child])` and the result is stored in `rendered`. However, for `image`/`includegraphics` tokens, the `mdCell` output ignores `rendered` and constructs markdown manually:
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
case 'image':
|
|
30
|
+
case 'includegraphics': {
|
|
31
|
+
const src = child.attrGet('src');
|
|
32
|
+
mdCell += ``.replace(/\|/g, '\\|');
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Custom render rules registered on the renderer instance are never used for table cell markdown.
|
|
38
|
+
|
|
39
|
+
## Desired Behavior
|
|
40
|
+
|
|
41
|
+
When `options.forMD` is true:
|
|
42
|
+
|
|
43
|
+
1. Set `child.meta.isTableCell = true` before calling `slf.renderInline([child])` — this lets render rules know the token is inside a table cell (e.g., to escape pipe characters in alt text).
|
|
44
|
+
|
|
45
|
+
2. For `image`/`includegraphics` tokens, use the `rendered` output (from `slf.renderInline`) instead of hardcoded markdown:
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
case 'image':
|
|
49
|
+
case 'includegraphics': {
|
|
50
|
+
const src = child.attrGet('src');
|
|
51
|
+
tsvCell += src;
|
|
52
|
+
csvCell += src;
|
|
53
|
+
mdCell += options?.forMD
|
|
54
|
+
? rendered
|
|
55
|
+
: ``.replace(/\|/g, '\\|');
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
When `forMD` is false/undefined, behavior is identical to before.
|
|
61
|
+
|
|
62
|
+
## Files Changed
|
|
63
|
+
|
|
64
|
+
| File | Change |
|
|
65
|
+
|------|--------|
|
|
66
|
+
| `src/markdown/common/render-table-cell-content.ts` | Add `isTableCell` meta tagging when `forMD` is set; use `rendered` for image tokens when `forMD` is set |
|
|
67
|
+
| `tests/_data/_table-markdown/_data.js` | Add test case (id: 50) for `\includegraphics` inside tabular |
|
|
68
|
+
|
|
69
|
+
## Why This Approach
|
|
70
|
+
|
|
71
|
+
### Why use the existing `rendered` variable instead of a new code path?
|
|
72
|
+
|
|
73
|
+
`renderTableCellContent` already calls `slf.renderInline([child])` for every child token and stores the result in `rendered`. For most token types, `rendered` is used for the `content` (HTML) output. For images, it was being discarded in favor of hardcoded markdown. Using `rendered` for `mdCell` when `forMD` is set is the minimal change — no new rendering logic, just using what's already computed.
|
|
74
|
+
|
|
75
|
+
### Why gate on `forMD` instead of always delegating?
|
|
76
|
+
|
|
77
|
+
The default (`forMD: false`) path produces standard `` markdown that works for all existing consumers (HTML rendering, DOCX, PPTX). Changing the default would risk regressions in those paths. `forMD` is only set by mmd-converter's markdown export pipeline, which is exactly where custom render rules need to participate.
|
|
78
|
+
|
|
79
|
+
### Why set `isTableCell` on token meta?
|
|
80
|
+
|
|
81
|
+
Render rules need to know when a token is inside a table cell so they can escape pipe characters (`|` → `\|`) in alt text. Without this, a pipe in alt text would break the markdown table structure. The meta flag is a clean way to communicate this without adding parameters to the render rule signature.
|
|
82
|
+
|
|
83
|
+
## Constraints
|
|
84
|
+
|
|
85
|
+
- Default behavior (when `forMD` is not set) must not change
|
|
86
|
+
- TSV and CSV output must not change (they still use raw `src`)
|
|
87
|
+
- HTML output (`content`) must not change (it already uses `rendered`)
|
|
88
|
+
- DOCX/PPTX output (`tableSmoothed`) must not change
|
|
89
|
+
- All existing tests must pass
|
|
90
|
+
|
|
91
|
+
## Testing
|
|
92
|
+
|
|
93
|
+
New test case (id: 50) in `_table-markdown/_data.js`:
|
|
94
|
+
|
|
95
|
+
```javascript
|
|
96
|
+
{
|
|
97
|
+
id: 50,
|
|
98
|
+
latex: '\\begin{tabular}{|l|l|}\\n\\hline\\n\\textbf{Case} & \\textbf{Image} \\\\\\n\\hline\\n' +
|
|
99
|
+
'LaTeX image without options (should be resolved) &\\n' +
|
|
100
|
+
'\\includegraphics{https://mathpix-ocr-examples.s3.amazonaws.com/cases_printed_1.jpg}\\\\\\n' +
|
|
101
|
+
'\\hline\\n\\end{tabular}',
|
|
102
|
+
table_markdown: '| **Case** | **Image** |\\n| :--- | :--- |\\n' +
|
|
103
|
+
'| LaTeX image without options (should be resolved) | ' +
|
|
104
|
+
' |'
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Note: this test verifies the default (non-`forMD`) behavior produces standard markdown. The `forMD` rendering is tested in mmd-converter's `06-tabular-with-images` test case, which exercises the full pipeline with `renderImageRule` and `renderIncludeGraphics`.
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
npm run build
|
|
112
|
+
npm test
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Risk / Rollback
|
|
116
|
+
|
|
117
|
+
**Risk**: Low
|
|
118
|
+
- Gated behind `forMD` option — only mmd-converter's markdown export path is affected
|
|
119
|
+
- Default rendering path is unchanged
|
|
120
|
+
- Two-line change in the source file
|
|
121
|
+
|
|
122
|
+
**Rollback**: Revert PR or pin to previous version
|
|
123
|
+
|
|
124
|
+
## Related
|
|
125
|
+
|
|
126
|
+
- Issue: [#18320](https://github.com/Mathpix/monorepo/pull/18320)
|