mathpix-markdown-it 2.0.32 → 2.0.33

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.
@@ -0,0 +1,135 @@
1
+ # PR: Fix line-break handling for nested tabular placeholders with lists
2
+
3
+ Status: Implemented
4
+ Owner: @OlgaRedozubova
5
+ Issue: #17912
6
+
7
+ ---
8
+
9
+ ## Context
10
+
11
+ After adding support for lists inside tabular cells (#17328), a regression was discovered: when a table cell contains content (like a list or text) followed by a nested tabular that itself contains list environments, the rendering would break. The block parsing mode was not properly propagated from nested sub-tabulars to their parent cells.
12
+
13
+ When parsing a tabular cell, nested tabulars are first replaced with UUID placeholders.
14
+ At this stage, child tabulars containing list environments have not yet been expanded.
15
+ Because the parent cell did not yet know that its child placeholders would expand to
16
+ block-level content, the line break before the nested tabular was trimmed.
17
+
18
+ **Impact:**
19
+ - Cells with content followed by nested tabular placeholders rendered incorrectly
20
+ - Line breaks before nested tabulars expanding to lists were removed
21
+ - Tabular environments following such placeholders were not rendered
22
+
23
+ ## Goal
24
+
25
+ - Fix rendering for cells that contain content before a nested tabular with lists
26
+ - Propagate block detection status from child sub-tabulars to parent cells
27
+ - Ensure consistent block parsing for all cells containing lists at any nesting level
28
+
29
+ ## Non-Goals
30
+
31
+ - Changing the general list-in-tabular rendering behavior
32
+ - Modifying the block detection logic for non-nested cases
33
+ - API or interface changes
34
+
35
+ ## Example
36
+
37
+ ### Input LaTeX
38
+
39
+ ```latex
40
+ \begin{tabular}{|l|}
41
+ \hline
42
+ \begin{itemize}
43
+ \item[] - First item
44
+ \end{itemize} \\
45
+ Text
46
+ \begin{tabular}{|l|}
47
+ \hline \begin{tabular}{l}
48
+ \begin{itemize}
49
+ \item[] - Item in sub table 1
50
+ \end{itemize}
51
+ \end{tabular} \\
52
+ \hline \begin{tabular}{l}
53
+ \begin{itemize}
54
+ \item[] - Item in sub table 2
55
+ \end{itemize}
56
+ \end{tabular} \\
57
+ \hline
58
+ \end{tabular}
59
+ \begin{tabular}{|l|l|}
60
+ \hline cell & \begin{itemize}
61
+ \item[] - Item in sub table 3
62
+ \end{itemize} \\
63
+ \hline
64
+ \end{tabular} \\
65
+ \hline
66
+ \end{tabular}
67
+ ```
68
+
69
+ ### Before (broken)
70
+
71
+ - **HTML**: Subtable 3 was not rendered
72
+
73
+ ### After (fixed)
74
+
75
+ - All nested tabulars render correctly
76
+ - Lists inside deeply nested tabulars are properly detected and rendered
77
+ - Block parsing is triggered for all cells containing lists at any depth
78
+
79
+ ## Why This Approach
80
+
81
+ ### Why track block status in sub-tabulars?
82
+
83
+ When a cell is parsed, nested tabulars are replaced with UUID placeholders (e.g., `<<uuid>>`). The block detection was only checking the parent cell's direct content—it would see `Text <<uuid>>` and not detect any list environment, even though the nested tabular (behind the placeholder) contained lists.
84
+
85
+ Because block status was not known at placeholder time, the parent cell was treated as inline content. This caused whitespace and line breaks around placeholders to be trimmed before child tabulars were expanded.
86
+
87
+ ### Why propagate from children to parents?
88
+
89
+ By storing an `isBlock` flag on each sub-tabular and propagating it upward when a parent references a child placeholder, we ensure that block parsing is triggered correctly regardless of nesting depth.
90
+
91
+ ## Approach
92
+
93
+ 1. **Track block status in sub-tabulars** — Add `isBlock` and `children` fields to the `TSubTabular` type to track whether a sub-tabular contains block-level content.
94
+
95
+ 2. **Propagate block status** — When pushing a new sub-tabular, check if any of its child sub-tabulars have `isBlock: true`. If so, mark the parent as `isBlock: true` as well.
96
+
97
+ 3. **Centralize detection** — Extract the block detection logic into a reusable `detectLocalBlock()` function in `common.ts`.
98
+
99
+ 4. **Use propagated status** — In `getSubTabular()`, check the stored `isBlock` flag instead of re-testing the content string.
100
+
101
+ ## Bug Fixes Included
102
+
103
+ - Fixed removal of line breaks before nested tabular placeholders that expand to lists
104
+ - Prevented subsequent tabular environments from being dropped due to placeholder trimming
105
+ - Ensured block context is propagated before placeholder expansion
106
+
107
+ ## Constraints
108
+
109
+ - List rendering outside tabular must remain unchanged
110
+ - Existing tabular tests must pass
111
+ - Parent PR (#17328) functionality must not regress
112
+
113
+ ## Testing
114
+
115
+ **New test coverage:**
116
+ - Complex nested tabular with list, text, and multiple nested sub-tabulars containing lists
117
+ - Deeply nested tabulars with itemize environments
118
+
119
+ **Commands:**
120
+ ```bash
121
+ npm test
122
+ npm run build
123
+ ```
124
+
125
+ ## Risk / Rollback
126
+
127
+ **Risk**: Low
128
+ - Minimal code changes focused on propagating existing block status
129
+ - No changes to parsing logic, only to block detection
130
+
131
+ **Rollback**: Revert PR or pin to version 2.0.32
132
+
133
+ ## Related
134
+
135
+ - Issue: #17912 — [mmd] Rendering breaks when a cell starts with text before a nested tabular with lists