Skip to content

Commit 324cd2a

Browse files
authored
Remove Unused Html Content Renderer Extensibility (microsoft#28760)
* Remove Unused Html Content Renderer Extensibility Removes a few options from the html content renderer that are currently not used * Fix messageList
1 parent 528682c commit 324cd2a

6 files changed

Lines changed: 11 additions & 103 deletions

File tree

src/vs/base/browser/htmlContentRenderer.ts

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function renderMarkedString(markedString: MarkedString, options: RenderOp
3333
*/
3434
export function renderHtml(content: RenderableContent, options: RenderOptions = {}): Node {
3535
if (typeof content === 'string') {
36-
return _renderHtml({ isText: true, text: content }, options);
36+
return document.createTextNode(content);
3737
} else if (Array.isArray(content)) {
3838
return _renderHtml({ children: content }, options);
3939
} else if (content) {
@@ -46,11 +46,7 @@ function _renderHtml(content: IHTMLContentElement, options: RenderOptions = {}):
4646

4747
let { codeBlockRenderer, actionCallback } = options;
4848

49-
if (content.isText) {
50-
return document.createTextNode(content.text);
51-
}
52-
53-
var tagName = getSafeTagName(content.tagName) || 'div';
49+
var tagName = content.inline ? 'span' : 'div';
5450
var element = document.createElement(tagName);
5551

5652
if (content.className) {
@@ -59,14 +55,6 @@ function _renderHtml(content: IHTMLContentElement, options: RenderOptions = {}):
5955
if (content.text) {
6056
element.textContent = content.text;
6157
}
62-
if (content.style) {
63-
element.setAttribute('style', content.style);
64-
}
65-
if (content.customStyle) {
66-
Object.keys(content.customStyle).forEach((key) => {
67-
element.style[key] = content.customStyle[key];
68-
});
69-
}
7058
if (content.children) {
7159
content.children.forEach((child) => {
7260
element.appendChild(renderHtml(child, options));
@@ -191,45 +179,6 @@ function _renderHtml(content: IHTMLContentElement, options: RenderOptions = {}):
191179
return element;
192180
}
193181

194-
var SAFE_TAG_NAMES = {
195-
a: true,
196-
b: true,
197-
blockquote: true,
198-
code: true,
199-
del: true,
200-
dd: true,
201-
div: true,
202-
dl: true,
203-
dt: true,
204-
em: true,
205-
h1h2h3i: true,
206-
img: true,
207-
kbd: true,
208-
li: true,
209-
ol: true,
210-
p: true,
211-
pre: true,
212-
s: true,
213-
span: true,
214-
sup: true,
215-
sub: true,
216-
strong: true,
217-
strike: true,
218-
ul: true,
219-
br: true,
220-
hr: true,
221-
};
222-
223-
function getSafeTagName(tagName: string): string {
224-
if (!tagName) {
225-
return null;
226-
}
227-
if (SAFE_TAG_NAMES.hasOwnProperty(tagName)) {
228-
return tagName;
229-
}
230-
return null;
231-
}
232-
233182
// --- formatted string parsing
234183

235184
class StringStream {

src/vs/base/browser/ui/inputbox/inputBox.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ export class InputBox extends Widget {
382382
layout();
383383

384384
let renderOptions: IHTMLContentElement = {
385-
tagName: 'span',
385+
inline: true,
386386
className: 'monaco-inputbox-message',
387387
};
388388

src/vs/base/common/htmlContent.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,8 @@ export interface IHTMLContentElement {
8585
formattedText?: string;
8686
text?: string;
8787
className?: string;
88-
style?: string;
89-
customStyle?: any;
90-
tagName?: string;
88+
inline?: boolean;
9189
children?: IHTMLContentElement[];
92-
isText?: boolean;
93-
role?: string;
9490
markdown?: string;
9591
code?: IHTMLContentElementCode;
9692
}
@@ -113,11 +109,7 @@ function htmlContentElementEqual(a: IHTMLContentElement, b: IHTMLContentElement)
113109
a.formattedText === b.formattedText
114110
&& a.text === b.text
115111
&& a.className === b.className
116-
&& a.style === b.style
117-
&& a.customStyle === b.customStyle
118-
&& a.tagName === b.tagName
119-
&& a.isText === b.isText
120-
&& a.role === b.role
112+
&& a.inline === b.inline
121113
&& a.markdown === b.markdown
122114
&& htmlContentElementCodeEqual(a.code, b.code)
123115
&& htmlContentElementArrEquals(a.children, b.children)

src/vs/base/test/browser/htmlContent.test.ts

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,10 @@ import { renderHtml } from 'vs/base/browser/htmlContentRenderer';
1010

1111
suite('HtmlContent', () => {
1212
test('render text', () => {
13-
var result = renderHtml({
14-
text: 'testing',
15-
isText: true
16-
});
13+
var result = renderHtml('testing');
1714
assert.strictEqual(result.nodeType, document.TEXT_NODE);
1815
});
1916

20-
test('cannot render script tag', function () {
21-
var host = document.createElement('div');
22-
document.body.appendChild(host);
23-
host.appendChild(renderHtml({
24-
tagName: 'script',
25-
text: 'alert(\'owned -- injected script tag via htmlContent!\')'
26-
}));
27-
assert(true);
28-
document.body.removeChild(host);
29-
});
30-
31-
3217
test('render simple element', () => {
3318
var result: HTMLElement = <any>renderHtml({
3419
text: 'testing'
@@ -47,24 +32,6 @@ suite('HtmlContent', () => {
4732
assert.strictEqual(result.className, 'testClass');
4833
});
4934

50-
test('render element with style', () => {
51-
var result: HTMLElement = <any>renderHtml({
52-
text: 'testing',
53-
style: 'width: 100px;'
54-
});
55-
assert.strictEqual(result.getAttribute('style'), 'width: 100px;');
56-
});
57-
58-
test('render element with custom style', () => {
59-
var result: HTMLElement = <any>renderHtml({
60-
text: 'testing',
61-
customStyle: {
62-
'width': '100px'
63-
}
64-
});
65-
assert.strictEqual(result.style.width, '100px');
66-
});
67-
6835
test('render element with children', () => {
6936
var result: HTMLElement = <any>renderHtml({
7037
className: 'parent',

src/vs/workbench/services/keybinding/test/keyboardMapperTestUtils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,24 @@ function _htmlPieces(pieces: string[], OS: OperatingSystem): IHTMLContentElement
5656
let children: IHTMLContentElement[] = [];
5757
for (let i = 0, len = pieces.length; i < len; i++) {
5858
if (i !== 0 && OS !== OperatingSystem.Macintosh) {
59-
children.push({ tagName: 'span', text: '+' });
59+
children.push({ inline: true, text: '+' });
6060
}
61-
children.push({ tagName: 'span', className: 'monaco-kbkey', text: pieces[i] });
61+
children.push({ inline: true, className: 'monaco-kbkey', text: pieces[i] });
6262
}
6363
return children;
6464
}
6565

6666
export function simpleHTMLLabel(pieces: string[], OS: OperatingSystem): IHTMLContentElement {
6767
return {
68-
tagName: 'span',
68+
inline: true,
6969
className: 'monaco-kb',
7070
children: _htmlPieces(pieces, OS)
7171
};
7272
}
7373

7474
export function chordHTMLLabel(firstPart: string[], chordPart: string[], OS: OperatingSystem): IHTMLContentElement {
7575
return {
76-
tagName: 'span',
76+
inline: true,
7777
className: 'monaco-kb',
7878
children: [].concat(
7979
_htmlPieces(firstPart, OS),

src/vs/workbench/services/message/browser/messageList.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ export class MessageList {
335335

336336
// Error message
337337
const messageContentElement = htmlRenderer.renderHtml({
338-
tagName: 'span',
338+
inline: true,
339339
className: 'message-left-side',
340340
formattedText: text
341341
});

0 commit comments

Comments
 (0)