1
>
/*---------------------------------------------------------------------------------------------
iconLabels.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { IMatch, matchesFuzzy } from './filters.js';
7
>
import { ltrim } from './strings.js';
8
>
import { ThemeIcon } from './themables.js';
9
>
10
>
const iconStartMarker = '$(';
11
>
12
>
const iconsRegex = new RegExp(`\\$\\(${ThemeIcon.iconNameExpression}(?:${ThemeIcon.iconModifierExpression})?\\)`, 'g'); // no capturing groups
13
>
14
>
const escapeIconsRegex = new RegExp(`(\\\\)?${iconsRegex.source}`, 'g');
15
>
export function escapeIcons(text: string): string {
16
return text.replace(escapeIconsRegex, (match, escaped) => escaped ? match : `\\${match}`);
17
}
19
>
const markdownEscapedIconsRegex = new RegExp(`\\\\${iconsRegex.source}`, 'g');
20
>
export function markdownEscapeEscapedIcons(text: string): string {
21
// Need to add an extra \ for escaping in markdown
22
return text.replace(markdownEscapedIconsRegex, match => `\\${match}`);
23
}
25
>
const stripIconsRegex = new RegExp(`(\\s)?(\\\\)?${iconsRegex.source}(\\s)?`, 'g');
26
>
27
>
/**
28
>
* Takes a label with icons (`$(iconId)xyz`) and strips the icons out (`xyz`)
29
>
*/
30
>
export function stripIcons(text: string): string {
31
if (text.indexOf(iconStartMarker) === -1) {
32
return text;