fish-lsp
Version:
LSP implementation for fish/fish-shell
119 lines (118 loc) • 3.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MarkdownBuilder = exports.md = void 0;
exports.escapeMarkdownSyntaxTokens = escapeMarkdownSyntaxTokens;
const vscode_languageserver_1 = require("vscode-languageserver");
var md;
(function (md) {
function h(text, value = 1) {
return '#'.repeat(value) + ' ' + text.trim();
}
md.h = h;
function italic(value) {
return `\*${value}\*`;
}
md.italic = italic;
function bold(value) {
return `\*\*${value}\*\*`;
}
md.bold = bold;
function boldItalic(value) {
return `\*\*\*${value}\*\*\*`;
}
md.boldItalic = boldItalic;
function separator() {
return '___';
}
md.separator = separator;
function space() {
return ' ';
}
md.space = space;
function newline() {
return ' \n';
}
md.newline = newline;
function blockQuote(value) {
return '> ' + value;
}
md.blockQuote = blockQuote;
function inlineCode(value) {
return '`' + value + '`';
}
md.inlineCode = inlineCode;
function codeBlock(language, value) {
return [
'```' + language,
value,
'```',
].join('\n');
}
md.codeBlock = codeBlock;
function li(value) {
return '- ' + value;
}
md.li = li;
function ol(value) {
return '1.' + value;
}
md.ol = ol;
function link(name, href) {
return `[${name}](${href})`;
}
md.link = link;
function filepathString(value) {
return escapeMarkdownSyntaxTokens(value);
}
md.filepathString = filepathString;
function p(...strs) {
return strs.join(space());
}
md.p = p;
})(md || (exports.md = md = {}));
class MarkdownBuilder {
value;
constructor(value = '') {
this.value = value;
}
appendText(value, newlineStyle = 0) {
this.value += escapeMarkdownSyntaxTokens(value)
.replace(/([ \t]+)/g, (_match, g1) => ' '.repeat(g1.length))
.replace(/>/gm, '\\>')
.replace(/\n/g, newlineStyle === 1 ? '\\\n' : '\n\n');
return this;
}
appendNewline() {
this.value += md.newline();
return this;
}
fromMarkdown(...values) {
this.value += values.map(item => Array.isArray(item) ? item.map(i => i.trim()).join(' ') : item.trim()).join('\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;
}
toMarkupContent() {
return {
kind: vscode_languageserver_1.MarkupKind.Markdown,
value: this.value,
};
}
toString() {
return this.value;
}
}
exports.MarkdownBuilder = MarkdownBuilder;
function escapeMarkdownSyntaxTokens(text) {
return text.replace(/[\\`*_{}[\]()#+\-!]/g, '\\$&');
}