@@ -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 = / < ! - - \s * e x a m p l e \( \{ ( . * \: . * ) + \} \) \s * - - > / 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
@@ -47,29 +47,40 @@ export class DocsMarkdownRenderer extends Renderer {
47
47
48
48
/**
49
49
* Method that will be called whenever inline HTML is processed by marked. In that case,
50
- * we can easily transform the example comments into real HTML elements. For example:
51
- *
50
+ * we can easily transform the example comments into real HTML elements.
51
+ * For example:
52
+ * (New API)
52
53
* `<!-- example(
53
54
* {
54
55
* "example": "exampleName",
55
56
* "file": "example-html.html",
56
- * "lines": " [5, 10]" ,
57
- * "expanded": " true"
57
+ * "lines": [5, 10],
58
+ * "expanded": true
58
59
* }
59
60
* ) -->`
60
61
* turns into
61
62
* `<div material-docs-example="exampleName"
62
63
* file="example-html.html"
63
- * lines="[5, 10]"
64
- * expanded="true"></div>`
64
+ * [lines]="[5, 10]"
65
+ * [expanded]="true"></div>`
66
+ *
67
+ * (old API)
68
+ * `<!-- example(name) -->`
69
+ * turns into
70
+ * `<div material-docs-example="name"></div>`
65
71
*/
66
72
html ( html : string ) {
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 } " expanded="${ ! ! expanded } "></div>` ;
71
- }
72
-
73
+ html = html . replace ( exampleCommentRegex , ( _match : string , content : string ) => {
74
+ if ( content . startsWith ( '{' ) ) {
75
+ const { example, file, lines, expanded} = JSON . parse ( content ) ;
76
+ return `<div material-docs-example="${ example } "
77
+ file="${ file } "
78
+ [lines]="${ lines } "
79
+ [expanded]="${ ! ! expanded } "></div>` ;
80
+ } else {
81
+ return `<div material-docs-example="${ content } "></div>` ;
82
+ }
83
+ }
73
84
) ;
74
85
75
86
return super . html ( html ) ;
0 commit comments