UNPKG

@theia/core

Version:

Theia is a cloud & desktop IDE framework implemented in TypeScript.

104 lines 4.76 kB
"use strict"; // ***************************************************************************** // Copyright (C) 2022 Ericsson and others. // // This program and the accompanying materials are made available under the // terms of the Eclipse Public License v. 2.0 which is available at // http://www.eclipse.org/legal/epl-2.0. // // This Source Code may also be made available under the following Secondary // Licenses when the conditions for such availability set forth in the Eclipse // Public License v. 2.0 are satisfied: GNU General Public License, version 2 // with the GNU Classpath Exception which is available at // https://www.gnu.org/software/classpath/license.html. // // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 // ***************************************************************************** Object.defineProperty(exports, "__esModule", { value: true }); exports.escapeMarkdownSyntaxTokens = exports.MarkdownStringImpl = exports.MarkdownString = exports.MarkdownStringTextNewlineStyle = void 0; const strings_1 = require("../strings"); const icon_utilities_1 = require("./icon-utilities"); const types_1 = require("../types"); var MarkdownStringTextNewlineStyle; (function (MarkdownStringTextNewlineStyle) { MarkdownStringTextNewlineStyle[MarkdownStringTextNewlineStyle["Paragraph"] = 0] = "Paragraph"; MarkdownStringTextNewlineStyle[MarkdownStringTextNewlineStyle["Break"] = 1] = "Break"; })(MarkdownStringTextNewlineStyle = exports.MarkdownStringTextNewlineStyle || (exports.MarkdownStringTextNewlineStyle = {})); var MarkdownString; (function (MarkdownString) { /** * @returns whether the candidate satisfies the interface of a markdown string */ function is(candidate) { return (0, types_1.isObject)(candidate) && (0, types_1.isString)(candidate.value); } MarkdownString.is = is; })(MarkdownString = exports.MarkdownString || (exports.MarkdownString = {})); // Copied from https://github.com/microsoft/vscode/blob/7d9b1c37f8e5ae3772782ba3b09d827eb3fdd833/src/vs/base/common/htmlContent.ts class MarkdownStringImpl { constructor(value = '', isTrustedOrOptions = false) { var _a, _b, _c; this.value = value; if (typeof this.value !== 'string') { throw new Error('Illegal value for MarkdownString. Expected string, got ' + typeof this.value); } if (typeof isTrustedOrOptions === 'boolean') { this.isTrusted = isTrustedOrOptions; this.supportThemeIcons = false; this.supportHtml = false; } else { this.isTrusted = (_a = isTrustedOrOptions.isTrusted) !== null && _a !== void 0 ? _a : undefined; this.supportThemeIcons = (_b = isTrustedOrOptions.supportThemeIcons) !== null && _b !== void 0 ? _b : false; this.supportHtml = (_c = isTrustedOrOptions.supportHtml) !== null && _c !== void 0 ? _c : false; } } appendText(value, newlineStyle = MarkdownStringTextNewlineStyle.Paragraph) { this.value += escapeMarkdownSyntaxTokens(this.supportThemeIcons ? (0, icon_utilities_1.escapeIcons)(value) : value) .replace(/([ \t]+)/g, (_match, g1) => ' '.repeat(g1.length)) .replace(/\>/gm, '\\>') .replace(/\n/g, newlineStyle === MarkdownStringTextNewlineStyle.Break ? '\\\n' : '\n\n'); return this; } appendMarkdown(value) { this.value += value; return this; } appendCodeblock(langId, code) { this.value += '\n```'; this.value += langId; this.value += '\n'; this.value += code; this.value += '\n```\n'; return this; } appendLink(target, label, title) { this.value += '['; this.value += this._escape(label, ']'); this.value += ']('; this.value += this._escape(String(target), ')'); if (title) { this.value += ` "${this._escape(this._escape(title, '"'), ')')}"`; } this.value += ')'; return this; } _escape(value, ch) { const r = new RegExp((0, strings_1.escapeRegExpCharacters)(ch), 'g'); return value.replace(r, (match, offset) => { if (value.charAt(offset - 1) !== '\\') { return `\\${match}`; } else { return match; } }); } } exports.MarkdownStringImpl = MarkdownStringImpl; function escapeMarkdownSyntaxTokens(text) { // escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash return text.replace(/[\\`*_{}[\]()#+\-!]/g, '\\$&'); } exports.escapeMarkdownSyntaxTokens = escapeMarkdownSyntaxTokens; //# sourceMappingURL=markdown-string.js.map