diff --git a/tools/markdown-to-html/docs-marked-renderer.ts b/tools/markdown-to-html/docs-marked-renderer.ts index 1ffe0ef69a84..8893af3e4784 100644 --- a/tools/markdown-to-html/docs-marked-renderer.ts +++ b/tools/markdown-to-html/docs-marked-renderer.ts @@ -4,6 +4,12 @@ import {basename, extname} from 'path'; /** Regular expression that matches example comments. */ const exampleCommentRegex = //g; +/** Marker inserted before the start of an example. */ +const exampleStartMarker = ''; + +/** Marker inserted after the end of an example. */ +const exampleEndMarker = ''; + /** * Custom renderer for marked that will be used to transform markdown files to HTML * files that can be used in the Angular Material docs. @@ -78,6 +84,8 @@ export class DocsMarkdownRenderer extends Renderer { */ html(html: string) { html = html.replace(exampleCommentRegex, (_match: string, content: string) => { + let replacement: string; + // using [\s\S]* because .* does not match line breaks if (content.match(/\{[\s\S]*\}/g)) { const {example, file, region} = JSON.parse(content.trim()) as { @@ -85,12 +93,14 @@ export class DocsMarkdownRenderer extends Renderer { file: string; region: string; }; - return `
`; } else { - return ``; + replacement = ``; } + + return `${exampleStartMarker}${replacement}${exampleEndMarker}`; }); return super.html(html); @@ -120,6 +130,16 @@ export class DocsMarkdownRenderer extends Renderer { this._slugger.seen = {}; this._referencedFragments.clear(); - return `