tokenize source in release notes editor

related to #13049
This commit is contained in:
Joao Moreno
2016-09-30 11:06:43 +02:00
parent ea194582d6
commit 1459824cad
2 changed files with 31 additions and 2 deletions

View File

@@ -91,6 +91,10 @@ code > div {
overflow: auto;
}
.monaco-tokenized-source {
white-space: pre;
}
/** Theming */
.vscode-light {

View File

@@ -25,6 +25,8 @@ import { Keybinding } from 'vs/base/common/keybinding';
import { IRequestService } from 'vs/platform/request/common/request';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import product from 'vs/platform/product';
import { IModeService } from 'vs/editor/common/services/modeService';
import {tokenizeToString} from 'vs/editor/common/modes/textToHtmlTokenizer';
function renderBody(body: string): string {
return `<!DOCTYPE html>
@@ -52,7 +54,8 @@ export class ReleaseNotesEditor extends BaseEditor {
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IRequestService private requestService: IRequestService,
@IOpenerService private openerService: IOpenerService,
@IKeybindingService private keybindingService: IKeybindingService
@IKeybindingService private keybindingService: IKeybindingService,
@IModeService private modeService: IModeService
) {
super(ReleaseNotesEditor.ID, telemetryService);
this.disposables = [];
@@ -81,7 +84,29 @@ export class ReleaseNotesEditor extends BaseEditor {
this.loadContents(() => this.requestService.request({ url })
.then(asText)
.then(text => this.patchKeybindings(text))
.then(marked.parse)
.then(text => {
// we first need to load the modes...
const result = [];
const renderer = new marked.Renderer();
renderer.code = (code, lang) => {
const modeId = this.modeService.getModeIdForLanguageName(lang);
result.push(this.modeService.getOrCreateMode(modeId));
return '';
};
marked(text, { renderer });
return TPromise.join(result).then(() => text);
})
.then(text => {
// then we can render
const renderer = new marked.Renderer();
renderer.code = (code, lang) => {
const modeId = this.modeService.getModeIdForLanguageName(lang);
return `<code>${ tokenizeToString(code, modeId) }</code>`;
};
return marked(text, { renderer });
})
.then(renderBody)
.then<void>(body => {
const webview = new WebView(