From 24658aa671e78738277c006f9a90fdd9f601bf26 Mon Sep 17 00:00:00 2001 From: Greg Ziegan Date: Thu, 11 Aug 2016 14:20:11 -0700 Subject: [PATCH 1/3] Patch for BR preservation --- src/docsSoap.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/docsSoap.js b/src/docsSoap.js index 0ebf999..b83c1e6 100644 --- a/src/docsSoap.js +++ b/src/docsSoap.js @@ -106,6 +106,8 @@ const getCleanNode = ( } else if (node.nodeName === 'P') { newWrapper = document.createElement('p'); newNode = applyBlockStyles(node); + } else if (node.nodeName === 'BR') { + newNode = node } else { newWrapper = document.createElement('span'); newNode = applyInlineStyles(node); From 9f804d105474b7c521d21252689a486a8b9b88bc Mon Sep 17 00:00:00 2001 From: Greg Ziegan Date: Thu, 11 Aug 2016 14:44:17 -0700 Subject: [PATCH 2/3] semis = the devil --- src/docsSoap.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/docsSoap.js b/src/docsSoap.js index b83c1e6..ab00519 100644 --- a/src/docsSoap.js +++ b/src/docsSoap.js @@ -107,7 +107,7 @@ const getCleanNode = ( newWrapper = document.createElement('p'); newNode = applyBlockStyles(node); } else if (node.nodeName === 'BR') { - newNode = node + newNode = node; } else { newWrapper = document.createElement('span'); newNode = applyInlineStyles(node); From 9635d2798bf5617b0cb815a45a03cc8fb01bec77 Mon Sep 17 00:00:00 2001 From: Greg Ziegan Date: Fri, 12 Aug 2016 09:34:36 -0700 Subject: [PATCH 3/3] added
test --- test/docsSoapSpec.js | 5 +++++ test/fixtures/documents.json | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/test/docsSoapSpec.js b/test/docsSoapSpec.js index 9a2ce3a..1479aab 100644 --- a/test/docsSoapSpec.js +++ b/test/docsSoapSpec.js @@ -106,4 +106,9 @@ describe('Google Docs Converter', () => { expect(doc.querySelectorAll('h3').length).toBe(1); expect(doc.querySelectorAll('h4').length).toBe(1); }); + + it('converts brs properly', () => { + const doc = parseHTML(docsSoap(documents.brs)); + expect(doc.querySelectorAll('br').length).toBe(2); + }); }); diff --git a/test/fixtures/documents.json b/test/fixtures/documents.json index 5328ae9..38b0ec3 100644 --- a/test/fixtures/documents.json +++ b/test/fixtures/documents.json @@ -3,5 +3,6 @@ "inlineStyles": "

Some bold text

Some italicized text

Some underlined text

Some strikethrough text

Some superscript

Some subscript
", "links": "

this is a link

this is a bold link

this is an italicized link

this is a bold, italicized link
", "nestedList": "
  1. Abcd
    1234

    1. In abcd

      1. Some text in italics and underline plus random stuff after

  2. xyz

    1. In xyz

      1. Last of all

  • Todo 1

  • Todo 2

    • subtodo

      • subsubsub


Asdfasdf

2. End






  1. Asdfasdfasdf

    1. Asdfasdfasdfasdf

  2. Asdfasdfasdf

    1. asdfasdfasdfasf

Asdfasdf

2. end

  1. end

  2. asdfasdf

  3. s

  4. dfa

  5. sdf

  6. eight

  7. ten


", - "headers": "

This is an H1

This is an H2

This is an H3

This is an H4

" + "headers": "

This is an H1

This is an H2

This is an H3

This is an H4

", + "brs": "

" }