From e849d1d57f63dae86d5a980ddb0083e759259dff Mon Sep 17 00:00:00 2001 From: Yuki Hattori Date: Tue, 5 Mar 2019 19:11:04 +0900 Subject: [PATCH 1/4] Add failed test case for keeping whitespaces in highlighted fence --- test/index.tsx | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/index.tsx b/test/index.tsx index e8a4549..e0a1ccd 100644 --- a/test/index.tsx +++ b/test/index.tsx @@ -39,6 +39,27 @@ class: lead expect(marp.find('figure')).toHaveLength(1) }) + it('renders highlighted fence correctly', () => { + const markdown = ` +\`\`\`js +test({ + foo: 0, + bar: 1, +}); +\`\`\` +`.trim() + + const marp = mount() + expect(marp.text().trim()).toBe( + ` +test({ + foo: 0, + bar: 1, +}); +`.trim() + ) + }) + it('injects global style for rendering Marp slide', () => { mount() expect(document.head.querySelector('style[id^="marp-style"]')).toBeTruthy() From 73ffee37113d4673f78906ac35540b53edab06d6 Mon Sep 17 00:00:00 2001 From: Yuki Hattori Date: Tue, 5 Mar 2019 19:13:46 +0900 Subject: [PATCH 2/4] Update HTML parser to convert line breaks into expression --- src/utils/parse.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/utils/parse.ts b/src/utils/parse.ts index c3109f9..fd1d630 100644 --- a/src/utils/parse.ts +++ b/src/utils/parse.ts @@ -33,5 +33,8 @@ const html = htm.bind((type: string, props, ...children) => { }) export default function parse(htmlStr: string) { - return html([htmlStr]) + const lines = htmlStr.split('\n') + const breaks = [...Array(lines.length - 1)].map(() => '\n') + + return html(lines, ...breaks) } From ff8018dd6afbf12f118eb3aeb3e2ef67cb5689c7 Mon Sep 17 00:00:00 2001 From: Yuki Hattori Date: Tue, 5 Mar 2019 19:16:17 +0900 Subject: [PATCH 3/4] Fix existed failing test --- test/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/index.tsx b/test/index.tsx index e0a1ccd..9cfca25 100644 --- a/test/index.tsx +++ b/test/index.tsx @@ -185,7 +185,7 @@ describe('MarpWorker', () => { act(() => { worker.interrupt(false) }) - expect(marp.text()).toBe('3') + expect(marp.text().trim()).toBe('3') // 2nd rendering will be skipped expect(worker.postQueue).not.toBeCalledWith(expect.arrayContaining(['2'])) From 8c10d69ca2d1c811400fe2df52ed9c8f02a78db6 Mon Sep 17 00:00:00 2001 From: Yuki Hattori Date: Thu, 7 Mar 2019 11:57:01 +0900 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b40b1bd..41dd4ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Fixed + +- Fix ignored whitespaces and line breaks in fenced code ([#4](https://github.com/marp-team/marp-react/issues/4), [#5](https://github.com/marp-team/marp-react/pull/5)) + ## v0.0.2 - 2019-03-03 ### Changed