[js] use textToMarkedString in JSON contributions

This commit is contained in:
Martin Aeschlimann
2016-09-07 16:20:14 +02:00
parent 4e235375cd
commit 757650b26e
3 changed files with 15 additions and 2 deletions

View File

@@ -8,6 +8,7 @@ import {MarkedString, CompletionItemKind, CompletionItem, DocumentSelector} from
import {IJSONContribution, ISuggestionsCollector} from './jsonContributions';
import {XHRRequest} from 'request-light';
import {Location} from 'jsonc-parser';
import {textToMarkedString} from './markedTextUtil';
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
@@ -173,7 +174,7 @@ export class BowerJSONContribution implements IJSONContribution {
htmlContent.push(localize('json.bower.package.hover', '{0}', pack));
return this.getInfo(pack).then(documentation => {
if (documentation) {
htmlContent.push({ language: 'string', value: documentation});
htmlContent.push(textToMarkedString(documentation));
}
return htmlContent;
});

View File

@@ -0,0 +1,11 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import {MarkedString} from 'vscode';
export function textToMarkedString(text: string) : MarkedString {
return text.replace(/[\\`*_{}[\]()#+\-.!]/g, '\\$&'); // escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash
}

View File

@@ -8,6 +8,7 @@ import {MarkedString, CompletionItemKind, CompletionItem, DocumentSelector} from
import {IJSONContribution, ISuggestionsCollector} from './jsonContributions';
import {XHRRequest} from 'request-light';
import {Location} from 'jsonc-parser';
import {textToMarkedString} from './markedTextUtil';
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
@@ -214,7 +215,7 @@ export class PackageJSONContribution implements IJSONContribution {
htmlContent.push(localize('json.npm.package.hover', '{0}', pack));
return this.getInfo(pack).then(infos => {
infos.forEach(info => {
htmlContent.push({language: 'string', value: info});
htmlContent.push(textToMarkedString(info));
});
return htmlContent;
});