From 8cc4634fadde1e6b4ef4f8d05f6191a3861e18ae Mon Sep 17 00:00:00 2001 From: Annie Wang Date: Thu, 21 May 2020 14:01:37 -0700 Subject: [PATCH 1/2] fix(markdown-to-html): use regex to match new API --- .../markdown-to-html/docs-marked-renderer.ts | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/tools/markdown-to-html/docs-marked-renderer.ts b/tools/markdown-to-html/docs-marked-renderer.ts index 46752b6a8f72..4d11c1a1098b 100644 --- a/tools/markdown-to-html/docs-marked-renderer.ts +++ b/tools/markdown-to-html/docs-marked-renderer.ts @@ -64,7 +64,7 @@ export class DocsMarkdownRenderer extends Renderer { * { * "example": "exampleName", * "file": "example-html.html", - * "region": "some-region", + * "region": "some-region" * } * ) -->` * turns into @@ -78,20 +78,21 @@ export class DocsMarkdownRenderer extends Renderer { * `
` */ html(html: string) { - html = html.replace(exampleCommentRegex, (_match: string, content: string) => { - if (content.startsWith('{')) { - const {example, file, region} = JSON.parse(content); - return `
`; - } else { - return `
`; - } - } - ); - - return super.html(html); - } + html = html.replace(exampleCommentRegex, (_match: string, content: string) => { + if (content.match(/\{[\s\S]*\}/g)) { + // using [\s\S]* because .* does not match line breaks + const {example, file, region} = JSON.parse(content); + return `
`; + } else { + return `
`; + } + } + ); + + return super.html(html); + } /** * Method that will be called after a markdown file has been transformed to HTML. This method From b23f5fdfd7102221d520198ea8f45688f3e13460 Mon Sep 17 00:00:00 2001 From: Annie Wang Date: Wed, 27 May 2020 10:19:42 -0700 Subject: [PATCH 2/2] fix test to reflect change --- tools/markdown-to-html/docs-marked-renderer.spec.ts | 4 +--- tools/markdown-to-html/docs-marked-renderer.ts | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tools/markdown-to-html/docs-marked-renderer.spec.ts b/tools/markdown-to-html/docs-marked-renderer.spec.ts index 139fb5a750aa..8f78b8e125c2 100644 --- a/tools/markdown-to-html/docs-marked-renderer.spec.ts +++ b/tools/markdown-to-html/docs-marked-renderer.spec.ts @@ -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, `
{ + // using [\s\S]* because .* does not match line breaks if (content.match(/\{[\s\S]*\}/g)) { - // using [\s\S]* because .* does not match line breaks const {example, file, region} = JSON.parse(content); return `