Commit 80a87b1
Fix HtmlNode.ToString: preserve whitespace in elements nested inside <pre>
Elements nested multiple levels deep inside a <pre> block could have
newlines and indentation inserted between them during serialization.
This corrupted output from syntax highlighters (e.g. shiki) that emit
<pre><code><span class="line"><span>...</span></span></code></pre>.
Root cause: the serialize function did not propagate an 'insidePre'
context to descendant elements. When a non-pre element with multiple
element children (onlyText = false) appeared inside <pre>, the
canAddNewLine flag on sibling elements caused newLines to be inserted.
Fix: add an 'insidePre' parameter to serialize. When true, all
newline/indentation formatting is suppressed regardless of element type.
Closes #1509
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent d8eb38d commit 80a87b1
2 files changed
Lines changed: 19 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
117 | | - | |
| 117 | + | |
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| 138 | + | |
138 | 139 | | |
139 | | - | |
| 140 | + | |
140 | 141 | | |
141 | 142 | | |
142 | 143 | | |
| |||
157 | 158 | | |
158 | 159 | | |
159 | 160 | | |
160 | | - | |
| 161 | + | |
161 | 162 | | |
162 | 163 | | |
163 | 164 | | |
164 | 165 | | |
165 | 166 | | |
166 | | - | |
| 167 | + | |
167 | 168 | | |
168 | 169 | | |
169 | | - | |
| 170 | + | |
170 | 171 | | |
171 | 172 | | |
172 | 173 | | |
| |||
181 | 182 | | |
182 | 183 | | |
183 | 184 | | |
184 | | - | |
| 185 | + | |
185 | 186 | | |
186 | 187 | | |
187 | 188 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
869 | 869 | | |
870 | 870 | | |
871 | 871 | | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
872 | 884 | | |
873 | 885 | | |
874 | 886 | | |
| |||
0 commit comments