@@ -5,7 +5,7 @@ import {basename, extname} from 'path';
5
5
const whitespaceRegex = / \W + / g;
6
6
7
7
/** Regular expression that matches example comments. */
8
- const exampleCommentRegex = / < ! - - \W * e x a m p l e \( ( [ ^ ) ] + ) \) \W * - - > / g;
8
+ const exampleCommentRegex = / < ! - - \s * e x a m p l e \( \{ ( . * \: . * ) + \} \) \s * - - > / g;
9
9
10
10
/**
11
11
* Custom renderer for marked that will be used to transform markdown files to HTML
@@ -49,15 +49,31 @@ export class DocsMarkdownRenderer extends Renderer {
49
49
* Method that will be called whenever inline HTML is processed by marked. In that case,
50
50
* we can easily transform the example comments into real HTML elements. For example:
51
51
*
52
- * `<!-- example(name) -->` turns into `<div material-docs-example="name"></div>`
52
+ * `<!-- example(
53
+ * {
54
+ * "example": "exampleName",
55
+ * "file": "example-html.html",
56
+ * "lines": "[5, 10]",
57
+ * "expanded": "true"
58
+ * }
59
+ * ) -->`
60
+ * turns into
61
+ * `<div material-docs-example="exampleName"
62
+ * file="example-html.html"
63
+ * lines="[5, 10]"
64
+ * expanded="true"></div>`
53
65
*/
54
66
html ( html : string ) {
55
- html = html . replace ( exampleCommentRegex , ( _match : string , name : string ) =>
56
- `<div material-docs-example="${ name } "></div>`
57
- ) ;
67
+ html = html . replace ( exampleCommentRegex , ( _match : string , content : string ) =>
68
+ {
69
+ const { example, file, lines, expanded} = JSON . parse ( content ) ;
70
+ return `<div material-docs-example="${ example } " file="${ file } " lines="${ lines } " exapnded="${ ! ! expanded } "></div>` ;
71
+ }
58
72
59
- return super . html ( html ) ;
60
- }
73
+ ) ;
74
+
75
+ return super . html ( html ) ;
76
+ }
61
77
62
78
/**
63
79
* Method that will be called after a markdown file has been transformed to HTML. This method
0 commit comments