Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line breaks are missing in LibreOffice Writer #68

Closed
leovin opened this issue May 21, 2019 · 2 comments
Closed

Line breaks are missing in LibreOffice Writer #68

leovin opened this issue May 21, 2019 · 2 comments

Comments

@leovin
Copy link

leovin commented May 21, 2019

Hello,

Line breaks are missing in LibreOffice Writer (v6.1.6.3, Ubuntu) but show up in online viewer (for example https://onlinedocumentviewer.com).

Steps to reproduce:

  1. Modify test '25 Adds line breaks by default' (
    it('25 Adds line breaks by default', async () => {
    ) to output document.
  2. Open created document in latest LibreOffice Writer.

Expected result:
According to test template, there should be two line breaks starting with words 'Nullam' and 'Morbi'.

Actual:
Line breaks are missing.

@guigrpa
Copy link
Owner

guigrpa commented Aug 20, 2019

I'm afraid this library only targets MS Word. Sorry about that!

@guigrpa guigrpa closed this as completed Aug 20, 2019
@emilong
Copy link
Contributor

emilong commented Sep 11, 2019

(in case anyone read this before, I've edited it to update with a better technique)

I found a workaround that seems to work in LibreOffice and FreeOffice TextMaker:

const literalXmlDelimiter = "||";
const preserveWhitespace = string =>
  string
    .split(/[\n\r]+/) // could use different split criteria here
    .map(
      para =>
        `${literalXmlDelimiter}</w:t><w:br/>${literalXmlDelimiter}${para}${literalXmlDelimiter}<w:t>${literalXmlDelimiter}`
    )
    .join("");

In other words, make sure to terminate the preceding <w:t> that has come before the text was injected, do a <w:br/>, then resume the <w:t>.

If anyone else finds this helpful, I can make a PR... lmk!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants