Skip to content

Commit b07044e

Browse files
committed
update example comment api in md to html renderer
1 parent 658896f commit b07044e

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

tools/markdown-to-html/docs-marked-renderer.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {basename, extname} from 'path';
55
const whitespaceRegex = /\W+/g;
66

77
/** Regular expression that matches example comments. */
8-
const exampleCommentRegex = /<!--\W*example\(([^)]+)\)\W*-->/g;
8+
const exampleCommentRegex = /<!--\W*example\(\{(.*\:.*)+\}\)\W*-->/g;
99

1010
/**
1111
* Custom renderer for marked that will be used to transform markdown files to HTML
@@ -52,12 +52,16 @@ export class DocsMarkdownRenderer extends Renderer {
5252
* `<!-- example(name) -->` turns into `<div material-docs-example="name"></div>`
5353
*/
5454
html(html: string) {
55-
html = html.replace(exampleCommentRegex, (_match: string, name: string) =>
56-
`<div material-docs-example="${name}"></div>`
57-
);
55+
html = html.replace(exampleCommentRegex, (_match: string, content: string) =>
56+
{
57+
const parsedContent = JSON.parse(content);
58+
return `<div material-docs-example="${parsedContent['example']}" file="${parsedContent['file']}" lines="${parsedContent['lines']}"></div>`;
59+
}
5860

59-
return super.html(html);
60-
}
61+
);
62+
63+
return super.html(html);
64+
}
6165

6266
/**
6367
* Method that will be called after a markdown file has been transformed to HTML. This method

0 commit comments

Comments
 (0)