From cd73dc6d9994870fd609cfba9d4fe97cfd5adbf9 Mon Sep 17 00:00:00 2001 From: Milena Dimovska Date: Thu, 12 Oct 2017 14:03:23 +0200 Subject: [PATCH 1/4] Fix line breaks for
  • elements: - add line break only if addLineBreaks is true - add line breaks only between
  • elements (do not set a line break for the last
  • ) --- htmlToElement.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htmlToElement.js b/htmlToElement.js index d570f8e..fc9151d 100644 --- a/htmlToElement.js +++ b/htmlToElement.js @@ -137,7 +137,9 @@ export default function htmlToElement(rawHtml, customOpts = {}, done) { {opts.bullet} ); } - linebreakAfter = opts.lineBreak; + if (opts.addLineBreaks && index < list.length - 1) { + linebreakAfter = opts.lineBreak; + } } const {NodeComponent, styles} = opts; From 965a4c9d7f7c8e91233250323d2eafcbfcee187a Mon Sep 17 00:00:00 2001 From: Milena Dimovska Date: Thu, 12 Oct 2017 14:15:32 +0200 Subject: [PATCH 2/4] Fix snapshots and formatting --- __tests__/HTMLView-test.js | 6 +----- __tests__/__snapshots__/HTMLView-test.js.snap | 4 ---- example/Example.js | 4 +--- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/__tests__/HTMLView-test.js b/__tests__/HTMLView-test.js index 146996d..7f56daa 100644 --- a/__tests__/HTMLView-test.js +++ b/__tests__/HTMLView-test.js @@ -134,11 +134,7 @@ describe('', () => { function renderNode(node, index) { if (node.name == 'thing') { - return ( - - {node.attribs.b} - - ); + return {node.attribs.b}; } } diff --git a/__tests__/__snapshots__/HTMLView-test.js.snap b/__tests__/__snapshots__/HTMLView-test.js.snap index 6312fac..fb6be27 100644 --- a/__tests__/__snapshots__/HTMLView-test.js.snap +++ b/__tests__/__snapshots__/HTMLView-test.js.snap @@ -826,8 +826,6 @@ exports[` should render ol numbers 1`] = ` > b - - @@ -1274,8 +1272,6 @@ exports[` should render ul bullets 1`] = ` > b - - diff --git a/example/Example.js b/example/Example.js index c349e93..a3acf8c 100644 --- a/example/Example.js +++ b/example/Example.js @@ -6,9 +6,7 @@ function renderNode(node, index) { if (node.name == 'iframe') { return ( - - {node.attribs.src} - + {node.attribs.src} ); } From 15acace0b6e0528005a01baa2d9068e20ede5bb7 Mon Sep 17 00:00:00 2001 From: Milena Dimovska Date: Mon, 16 Oct 2017 11:06:13 +0200 Subject: [PATCH 3/4] Fix linter issues --- __tests__/HTMLView-test.js | 6 +++++- example/Example.js | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/__tests__/HTMLView-test.js b/__tests__/HTMLView-test.js index 7f56daa..146996d 100644 --- a/__tests__/HTMLView-test.js +++ b/__tests__/HTMLView-test.js @@ -134,7 +134,11 @@ describe('', () => { function renderNode(node, index) { if (node.name == 'thing') { - return {node.attribs.b}; + return ( + + {node.attribs.b} + + ); } } diff --git a/example/Example.js b/example/Example.js index a3acf8c..c349e93 100644 --- a/example/Example.js +++ b/example/Example.js @@ -6,7 +6,9 @@ function renderNode(node, index) { if (node.name == 'iframe') { return ( - {node.attribs.src} + + {node.attribs.src} + ); } From bdaead9dc6af9733ba045fc42a4ca42d9cb6c83c Mon Sep 17 00:00:00 2001 From: Milena Dimovska Date: Tue, 17 Oct 2017 00:30:12 +0200 Subject: [PATCH 4/4] Add a snapshot test for the exclusion of line breaks in list items --- __tests__/HTMLView-test.js | 10 ++ __tests__/__snapshots__/HTMLView-test.js.snap | 93 +++++++++++++++++++ 2 files changed, 103 insertions(+) diff --git a/__tests__/HTMLView-test.js b/__tests__/HTMLView-test.js index 146996d..0e20fad 100644 --- a/__tests__/HTMLView-test.js +++ b/__tests__/HTMLView-test.js @@ -125,6 +125,16 @@ describe('', () => { ).toMatchSnapshot(); }); + it('should not render extra linebreaks in list items if configured not to', () => { + const htmlContent = '
    • a
    • b
    '; + + expect( + renderer + .create() + .toJSON() + ).toMatchSnapshot(); + }); + it('can use a custom renderer', () => { const htmlContent = `
    diff --git a/__tests__/__snapshots__/HTMLView-test.js.snap b/__tests__/__snapshots__/HTMLView-test.js.snap index fb6be27..e040fdb 100644 --- a/__tests__/__snapshots__/HTMLView-test.js.snap +++ b/__tests__/__snapshots__/HTMLView-test.js.snap @@ -557,6 +557,99 @@ exports[` should not render extra linebreaks if configured not to 1`] `; +exports[` should not render extra linebreaks in list items if configured not to 1`] = ` + + + + + • + + + a + + + + + • + + + b + + + + +`; + exports[` should render an with set width/height 1`] = `