mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-01 09:35:41 -05:00
30 lines
1.5 KiB
TypeScript
30 lines
1.5 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
const escapeCodiconsRegex = /(\\)?\$\([a-z0-9\-]+?(?:~[a-z0-9\-]*?)?\)/gi;
|
|
export function escapeCodicons(text: string): string {
|
|
return text.replace(escapeCodiconsRegex, (match, escaped) => escaped ? match : `\\${match}`);
|
|
}
|
|
|
|
const markdownEscapedCodiconsRegex = /\\\$\([a-z0-9\-]+?(?:~[a-z0-9\-]*?)?\)/gi;
|
|
export function markdownEscapeEscapedCodicons(text: string): string {
|
|
// Need to add an extra \ for escaping in markdown
|
|
return text.replace(markdownEscapedCodiconsRegex, match => `\\${match}`);
|
|
}
|
|
|
|
const markdownUnescapeCodiconsRegex = /(\\)?\$\\\(([a-z0-9\-]+?(?:~[a-z0-9\-]*?)?)\\\)/gi;
|
|
export function markdownUnescapeCodicons(text: string): string {
|
|
return text.replace(markdownUnescapeCodiconsRegex, (match, escaped, codicon) => escaped ? match : `$(${codicon})`);
|
|
}
|
|
|
|
const renderCodiconsRegex = /(\\)?\$\((([a-z0-9\-]+?)(?:~([a-z0-9\-]*?))?)\)/gi;
|
|
export function renderCodicons(text: string): string {
|
|
return text.replace(renderCodiconsRegex, (_, escaped, codicon, name, animation) => {
|
|
return escaped
|
|
? `$(${codicon})`
|
|
: `<span class="codicon codicon-${name}${animation ? ` codicon-animation-${animation}` : ''}"></span>`;
|
|
});
|
|
}
|