Skip to content

Commit f580928

Browse files
committed
fix(markdown-to-html): use regex to match new API
1 parent d952a22 commit f580928

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

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

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class DocsMarkdownRenderer extends Renderer {
6464
* {
6565
* "example": "exampleName",
6666
* "file": "example-html.html",
67-
* "region": "some-region",
67+
* "region": "some-region"
6868
* }
6969
* ) -->`
7070
* turns into
@@ -78,20 +78,21 @@ export class DocsMarkdownRenderer extends Renderer {
7878
* `<div material-docs-example="name"></div>`
7979
*/
8080
html(html: string) {
81-
html = html.replace(exampleCommentRegex, (_match: string, content: string) => {
82-
if (content.startsWith('{')) {
83-
const {example, file, region} = JSON.parse(content);
84-
return `<div material-docs-example="${example}"
85-
file="${file}"
86-
region="${region}"></div>`;
87-
} else {
88-
return `<div material-docs-example="${content}"></div>`;
89-
}
90-
}
91-
);
92-
93-
return super.html(html);
94-
}
81+
html = html.replace(exampleCommentRegex, (_match: string, content: string) => {
82+
if (content.match(/\{[\s\S]*\}/g)) {
83+
// using [\s\S]* because .* does not match line breaks
84+
const {example, file, region} = JSON.parse(content);
85+
return `<div material-docs-example="${example}"
86+
file="${file}"
87+
region="${region}"></div>`;
88+
} else {
89+
return `<div material-docs-example="${content}"></div>`;
90+
}
91+
}
92+
);
93+
94+
return super.html(html);
95+
}
9596

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

0 commit comments

Comments
 (0)