/*! * @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 {Tokens, Token, TokenizerThis, RendererThis} from 'marked'; import {JSDOM} from 'jsdom'; /** Marked token for a multifile custom docs element. */ export interface DocsCodeMultifileToken extends Tokens.Generic { type: 'docs-code-multifile'; // The example path used for linking to Stackblitz or rendering a preview path: string | undefined; // The raw nested Markdown of examples in the multifile example panes: string; // The DocsCodeToken of the nested examples paneTokens: Token[]; // True if we should display preview preview: boolean; } // Capture group 1: all attributes on the opening tag // Capture group 2: all content between the open and close tags const multiFileCodeRule = /^\s*(.*?)<\/docs-code-multifile>/s; const pathRule = /path="([^"]*)"/; const previewRule = /preview/; export const docsCodeMultifileExtension = { name: 'docs-code-multifile', level: 'block' as const, start(src: string) { return src.match(/^\s* ${this.parser.parse(token.paneTokens)} `).firstElementChild!; if (token.path) { el.setAttribute('path', token.path); } if (token.preview) { el.setAttribute('preview', `${token.preview}`); } return el.outerHTML; }, };