提交 54b8d4d9 编写于 作者: M Matt Bierner 提交者: GitHub

Continue html renderer cleanup (#28913)

* Removes the `child` option for `IHTMLContentElement`. This is only used internally
* Delete some unused functions
上级 bba6037b
......@@ -13,7 +13,7 @@ import { IHTMLContentElement, MarkedString, removeMarkdownEscapes } from 'vs/bas
import { marked } from 'vs/base/common/marked/marked';
import { IMouseEvent } from 'vs/base/browser/mouseEvent';
export type RenderableContent = string | IHTMLContentElement | IHTMLContentElement[];
export type RenderableContent = string | IHTMLContentElement;
export interface RenderOptions {
actionCallback?: (content: string, event?: IMouseEvent) => void;
......@@ -21,7 +21,7 @@ export interface RenderOptions {
}
export function renderMarkedString(markedString: MarkedString, options: RenderOptions = {}): Node {
const htmlContentElement = typeof markedString === 'string' ? { markdown: markedString } : { code: markedString };
const htmlContentElement: IHTMLContentElement = typeof markedString === 'string' ? { markdown: markedString } : { code: markedString };
return renderHtml(htmlContentElement, options);
}
......@@ -34,8 +34,6 @@ export function renderMarkedString(markedString: MarkedString, options: RenderOp
export function renderHtml(content: RenderableContent, options: RenderOptions = {}): Node {
if (typeof content === 'string') {
return document.createTextNode(content);
} else if (Array.isArray(content)) {
return _renderHtml({ children: content }, options);
} else if (content) {
return _renderHtml(content, options);
}
......@@ -55,11 +53,6 @@ function _renderHtml(content: IHTMLContentElement, options: RenderOptions = {}):
if (content.text) {
element.textContent = content.text;
}
if (content.children) {
content.children.forEach((child) => {
element.appendChild(renderHtml(child, options));
});
}
if (content.formattedText) {
renderFormattedText(element, parseFormattedText(content.formattedText), actionCallback);
}
......
......@@ -86,56 +86,6 @@ export interface IHTMLContentElement {
text?: string;
className?: string;
inline?: boolean;
children?: IHTMLContentElement[];
markdown?: string;
code?: IHTMLContentElementCode;
}
function htmlContentElementCodeEqual(a: IHTMLContentElementCode, b: IHTMLContentElementCode): boolean {
if (!a && !b) {
return true;
}
if (!a || !b) {
return false;
}
return (
a.language === b.language
&& a.value === b.value
);
}
function htmlContentElementEqual(a: IHTMLContentElement, b: IHTMLContentElement): boolean {
return (
a.formattedText === b.formattedText
&& a.text === b.text
&& a.className === b.className
&& a.inline === b.inline
&& a.markdown === b.markdown
&& htmlContentElementCodeEqual(a.code, b.code)
&& htmlContentElementArrEquals(a.children, b.children)
);
}
export function htmlContentElementArrEquals(a: IHTMLContentElement[], b: IHTMLContentElement[]): boolean {
if (!a && !b) {
return true;
}
if (!a || !b) {
return false;
}
let aLen = a.length,
bLen = b.length;
if (aLen !== bLen) {
return false;
}
for (let i = 0; i < aLen; i++) {
if (!htmlContentElementEqual(a[i], b[i])) {
return false;
}
}
return true;
}
}
\ No newline at end of file
......@@ -32,18 +32,6 @@ suite('HtmlContent', () => {
assert.strictEqual(result.className, 'testClass');
});
test('render element with children', () => {
var result: HTMLElement = <any>renderHtml({
className: 'parent',
children: [{
text: 'child'
}]
});
assert.strictEqual(result.children.length, 1);
assert.strictEqual(result.className, 'parent');
assert.strictEqual(result.firstChild.textContent, 'child');
});
test('simple formatting', () => {
var result: HTMLElement = <any>renderHtml({
formattedText: '**bold**'
......
......@@ -6,12 +6,10 @@
'use strict';
import * as assert from 'assert';
import { IHTMLContentElement } from 'vs/base/common/htmlContent';
import { IKeyboardMapper } from 'vs/workbench/services/keybinding/common/keyboardMapper';
import { Keybinding, ResolvedKeybinding, SimpleKeybinding } from 'vs/base/common/keyCodes';
import { TPromise } from 'vs/base/common/winjs.base';
import { readFile, writeFile } from 'vs/base/node/pfs';
import { OperatingSystem } from 'vs/base/common/platform';
import { IKeyboardEvent } from 'vs/platform/keybinding/common/keybinding';
import { ScanCodeBinding } from 'vs/workbench/services/keybinding/common/scanCode';
......@@ -52,37 +50,6 @@ export function assertResolveUserBinding(mapper: IKeyboardMapper, firstPart: Sim
assert.deepEqual(actual, expected);
}
function _htmlPieces(pieces: string[], OS: OperatingSystem): IHTMLContentElement[] {
let children: IHTMLContentElement[] = [];
for (let i = 0, len = pieces.length; i < len; i++) {
if (i !== 0 && OS !== OperatingSystem.Macintosh) {
children.push({ inline: true, text: '+' });
}
children.push({ inline: true, className: 'monaco-kbkey', text: pieces[i] });
}
return children;
}
export function simpleHTMLLabel(pieces: string[], OS: OperatingSystem): IHTMLContentElement {
return {
inline: true,
className: 'monaco-kb',
children: _htmlPieces(pieces, OS)
};
}
export function chordHTMLLabel(firstPart: string[], chordPart: string[], OS: OperatingSystem): IHTMLContentElement {
return {
inline: true,
className: 'monaco-kb',
children: [].concat(
_htmlPieces(firstPart, OS),
[{ tagName: 'span', text: ' ' }],
_htmlPieces(chordPart, OS)
)
};
}
export function readRawMapping<T>(file: string): TPromise<T> {
return readFile(require.toUrl(`vs/workbench/services/keybinding/test/${file}.js`)).then((buff) => {
let contents = buff.toString();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册