/*! * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ import {TokenizerThis, RendererThis} from 'marked'; import {CodeToken, formatCode} from './format/index.mjs'; import {FileType, removeEslintComments} from './sanitizers/eslint.mjs'; import {loadWorkspaceRelativeFile} from '../../utils.mjs'; /** Marked token for a custom docs element. */ export interface DocsCodeToken extends CodeToken { type: 'docs-code'; } // Capture group 1: all attributes on the opening tag // Capture group 2: all content between the open and close tags const singleFileCodeRule = /^\s*]*)?)*)\s*(?:\/>|>(.*?)<\/docs-code>)/s; const pathRule = /path="([^"]*)"/; const classRule = /class="([^"]*)"/; const headerRule = /header="([^"]*)"/; const linenumsRule = /linenums/; const highlightRule = /highlight="([^"]*)"/; const diffRule = /diff="([^"]*)"/; const languageRule = /language="([^"]*)"/; const visibleLinesRule = /visibleLines="([^"]*)"/; const visibleRegionRule = /visibleRegion="([^"]*)"/; const previewRule = /preview/; export const docsCodeExtension = { name: 'docs-code', level: 'block' as const, start(src: string) { return src.match(/^