Skip to content

Commit a2f5b4a

Browse files
authored
Make sure all text nodes in chat markdown are wrapped in elements (#264049)
For #264043 I'm pretty sure the tests where showing bugs where top level text nodes weren't being replaces
1 parent 752c99b commit a2f5b4a

6 files changed

+15
-14
lines changed

src/vs/workbench/contrib/chat/browser/chatMarkdownRenderer.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,14 @@ export class ChatMarkdownRenderer extends MarkdownRenderer {
9797
: markdown;
9898
const result = super.render(mdWithBody, options, outElement);
9999

100-
// In some cases, the renderer can return text that is not inside a <p>,
101-
// but our CSS expects text to be in a <p> for margin to be applied properly.
100+
// In some cases, the renderer can return top level text nodes but our CSS expects
101+
// all text to be in a <p> for margin to be applied properly.
102102
// So just normalize it.
103103
result.element.normalize();
104-
const lastChild = result.element.lastChild;
105-
if (lastChild?.nodeType === Node.TEXT_NODE && lastChild.textContent?.trim()) {
106-
lastChild.replaceWith($('p', undefined, lastChild.textContent));
104+
for (const child of result.element.childNodes) {
105+
if (child.nodeType === Node.TEXT_NODE && child.textContent?.trim()) {
106+
child.replaceWith($('p', undefined, child.textContent));
107+
}
107108
}
108109
return this.attachCustomHover(result);
109110
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<div class="rendered-markdown">
1+
<div class="rendered-markdown"><p>
22

3-
&lt;!-- comment1 &lt;div&gt;&lt;/div&gt; --&gt;<div>content</div><p>&lt;!-- comment2 --&gt;</p></div>
3+
&lt;!-- comment1 &lt;div&gt;&lt;/div&gt; --&gt;</p><div>content</div><p>&lt;!-- comment2 --&gt;</p></div>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<div class="rendered-markdown">
22

3-
<p>1&lt;canvas&gt;2&lt;/canvas&gt;</p>&lt;details&gt;3&lt;/details&gt;4<p></p></div>
3+
<p>1&lt;canvas&gt;2&lt;/canvas&gt;</p><p>&lt;details&gt;3&lt;/details&gt;4</p><p></p></div>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<div class="rendered-markdown">
22

3-
<p>1</p>&lt;details id="id1" style="display: none"&gt;2&lt;details id="my id 2"&gt;3&lt;/details&gt;&lt;/details&gt;4<p></p></div>
3+
<p>1</p><p>&lt;details id="id1" style="display: none"&gt;2&lt;details id="my id 2"&gt;3&lt;/details&gt;&lt;/details&gt;4</p><p></p></div>
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<div class="rendered-markdown">
22

33

4-
<h1>heading</h1>
4+
<h1>heading</h1><p>
55
&lt;details&gt;
6-
<ul>
6+
</p><ul>
77
<li><span>&lt;details&gt;<i>1</i>&lt;/details&gt;</span></li>
88
<li><b>hi</b></li>
9-
</ul>
9+
</ul><p>
1010
&lt;/details&gt;
11-
<pre>&lt;canvas&gt;canvas here&lt;/canvas&gt;</pre><p>&lt;details&gt;&lt;/details&gt;</p></div>
11+
</p><pre>&lt;canvas&gt;canvas here&lt;/canvas&gt;</pre><p>&lt;details&gt;&lt;/details&gt;</p></div>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<div class="rendered-markdown">
22

3-
<p>&lt;area&gt;</p><hr><br>&lt;input value="test" type="text"&gt;<p></p></div>
3+
<p>&lt;area&gt;</p><hr><br><p>&lt;input value="test" type="text"&gt;</p><p></p></div>

0 commit comments

Comments
 (0)