Path: blob/main/src/vs/base/browser/ui/iconLabel/iconLabels.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import * as dom from '../../dom.js';6import { ThemeIcon } from '../../../common/themables.js';78const labelWithIconsRegex = new RegExp(`(\\\\)?\\$\\((${ThemeIcon.iconNameExpression}(?:${ThemeIcon.iconModifierExpression})?)\\)`, 'g');9export function renderLabelWithIcons(text: string): Array<HTMLSpanElement | string> {10const elements = new Array<HTMLSpanElement | string>();11let match: RegExpExecArray | null;1213let textStart = 0, textStop = 0;14while ((match = labelWithIconsRegex.exec(text)) !== null) {15textStop = match.index || 0;16if (textStart < textStop) {17elements.push(text.substring(textStart, textStop));18}19textStart = (match.index || 0) + match[0].length;2021const [, escaped, codicon] = match;22elements.push(escaped ? `$(${codicon})` : renderIcon({ id: codicon }));23}2425if (textStart < text.length) {26elements.push(text.substring(textStart));27}28return elements;29}3031export function renderIcon(icon: ThemeIcon): HTMLSpanElement {32const node = dom.$(`span`);33node.classList.add(...ThemeIcon.asClassNameArray(icon));34return node;35}363738