Skip to content

fix(markdown-to-html): use regex to match new API #19417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions tools/markdown-to-html/docs-marked-renderer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@ describe('DocsMarkdownRenderer', () => {
{
"example": "exampleName",
"file": "example-html.html",
"region": "some-region",
"region": "some-region"
}
) -->`);

// TODO(annieyw): I think DocsMarkedRenderer#html needs to be fixed for the new API?
expectEqualIgnoreLeadingWhitespace(result, `<div material-docs-example="
{
"example": "exampleName",
Expand Down
31 changes: 16 additions & 15 deletions tools/markdown-to-html/docs-marked-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class DocsMarkdownRenderer extends Renderer {
* {
* "example": "exampleName",
* "file": "example-html.html",
* "region": "some-region",
* "region": "some-region"
* }
* ) -->`
* turns into
Expand All @@ -78,20 +78,21 @@ export class DocsMarkdownRenderer extends Renderer {
* `<div material-docs-example="name"></div>`
*/
html(html: string) {
html = html.replace(exampleCommentRegex, (_match: string, content: string) => {
if (content.startsWith('{')) {
const {example, file, region} = JSON.parse(content);
return `<div material-docs-example="${example}"
file="${file}"
region="${region}"></div>`;
} else {
return `<div material-docs-example="${content}"></div>`;
}
}
);

return super.html(html);
}
html = html.replace(exampleCommentRegex, (_match: string, content: string) => {
// using [\s\S]* because .* does not match line breaks
if (content.match(/\{[\s\S]*\}/g)) {
const {example, file, region} = JSON.parse(content);
return `<div material-docs-example="${example}"
file="${file}"
region="${region}"></div>`;
} else {
return `<div material-docs-example="${content}"></div>`;
}
}
);

return super.html(html);
}

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