f59b4ec1ecb3159d29b826c6d2e6bd29c658ee5d1dee6b839fbebbf88574ced75fe31c6772ba006ac172b2d9667af4008533686d183ae6bf62e96da7f8d82d 1.3 KB

12345678910111213141516171819202122232425262728
  1. /*---------------------------------------------------------------------------------------------
  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. import * as dom from '../../dom.js';
  6. import { CSSIcon } from '../../../common/codicons.js';
  7. const labelWithIconsRegex = new RegExp(`(\\\\)?\\$\\((${CSSIcon.iconNameExpression}(?:${CSSIcon.iconModifierExpression})?)\\)`, 'g');
  8. export function renderLabelWithIcons(text) {
  9. const elements = new Array();
  10. let match;
  11. let textStart = 0, textStop = 0;
  12. while ((match = labelWithIconsRegex.exec(text)) !== null) {
  13. textStop = match.index || 0;
  14. elements.push(text.substring(textStart, textStop));
  15. textStart = (match.index || 0) + match[0].length;
  16. const [, escaped, codicon] = match;
  17. elements.push(escaped ? `$(${codicon})` : renderIcon({ id: codicon }));
  18. }
  19. if (textStart < text.length) {
  20. elements.push(text.substring(textStart));
  21. }
  22. return elements;
  23. }
  24. export function renderIcon(icon) {
  25. const node = dom.$(`span`);
  26. node.classList.add(...CSSIcon.asClassNameArray(icon));
  27. return node;
  28. }