Skip to content

Commit fb816db

Browse files
committed
feat: handle soft lines breaks
1 parent 3cee5c8 commit fb816db

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
},
1818
},
1919
rules: {
20+
"no-control-regex": 0,
2021
"react/prop-types": "off",
2122
"react/display-name": "off",
2223
},

__tests__/__snapshots__/converter-markdown.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ text with **space bold after** and _space italic before_.
190190
indented text
191191
192192
193-
verticalindent
193+
vertical<br/>indent
194194
195195
196196
[Link](https://github.com/cedricdelpoux/gatsby-source-google-docs)

__tests__/__snapshots__/converter-object.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ Object {
361361
},
362362
Object {
363363
"type": "p",
364-
"value": "verticalindent",
364+
"value": "vertical<br/>indent",
365365
},
366366
Object {
367367
"type": "p",

__tests__/__snapshots__/options.js.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ text with **space bold after** and _space italic before_.
4545
indented text
4646
4747
48-
verticalindent
48+
vertical<br/>indent
4949
5050
5151
[Link](https://github.com/cedricdelpoux/gatsby-source-google-docs)
@@ -106,7 +106,7 @@ text with **space bold after** and _space italic before_.
106106
indented text
107107
108108
109-
verticalindent
109+
vertical<br/>indent
110110
111111
112112
[Link](https://github.com/cedricdelpoux/gatsby-source-google-docs)
@@ -167,7 +167,7 @@ text with **space bold after** and _space italic before_.
167167
indented text
168168
169169
170-
verticalindent
170+
vertical<br/>indent
171171
172172
173173
[Link](https://github.com/cedricdelpoux/gatsby-source-google-docs)
@@ -242,7 +242,7 @@ text with **space bold after** and _space italic before_.
242242
indented text
243243
244244
245-
verticalindent
245+
vertical<br/>indent
246246
247247
248248
[Link](https://github.com/cedricdelpoux/gatsby-source-google-docs)

utils/google-document.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class GoogleDocument {
5353
let text = el.textRun.content
5454
.replace(/\n$/, "") // Remove new lines
5555
.replace(/|/g, '"') // Replace smart quotes by double quotes
56+
.replace(/\u000b/g, "<br/>") // Replace soft lines breaks, vertical tabs
5657
const contentMatch = text.match(/^(\s*)(\S+(?:[ \t\v]*\S+)*)(\s*)$/) // Match "text", "before" and "after"
5758

5859
if (contentMatch) {
@@ -211,7 +212,6 @@ class GoogleDocument {
211212
return content
212213
.map(({paragraph}) => paragraph.elements.map(this.formatText).join(""))
213214
.join("")
214-
.replace(/\n/g, "<br/>") // Replace newline characters by <br/> to avoid multi-paragraphs
215215
}
216216

217217
indentText(text, level) {
@@ -408,10 +408,10 @@ class GoogleDocument {
408408
.map(({paragraph}) =>
409409
paragraph.elements.map((el) => el.textRun.content).join("")
410410
)
411-
.join("")
412-
.replace(/\x0B/g, "\n") //eslint-disable-line no-control-regex
413-
.replace(/^\n|\n$/g, "")
414-
.split("\n")
411+
.join("") // Transform to string
412+
.replace(/\x0B/g, "\n") // Replace vertical tabs
413+
.replace(/^\n|\n$/g, "") // Remove new lines characters at the beginning and end of line
414+
.split("\n") // Transform to array
415415

416416
// "".split() -> [""]
417417
if (codeContent.length === 1 && codeContent[0] === "") return

0 commit comments

Comments
 (0)