Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continue html renderer cleanup #28913

Merged
merged 1 commit into from
Jun 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 2 additions & 9 deletions src/vs/base/browser/htmlContentRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ 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;
codeBlockRenderer?: (modeId: string, value: string) => string | TPromise<string>;
}

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);
}

Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
52 changes: 1 addition & 51 deletions src/vs/base/common/htmlContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
12 changes: 0 additions & 12 deletions src/vs/base/test/browser/htmlContent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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**'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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();
Expand Down