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

Pretty printing for mixed content moves text to a new line and introduces spaces. #163

Open
frederik opened this issue Mar 31, 2023 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@frederik
Copy link

Describe the bug

With end({ prettyPrint: true }) mixed inline content is written to a new line, introducing spaces in XML viewers. (e.g. a text will render as "It's bold ." instead of "It's bold.")

To Reproduce
Given the following XML

<sec sec-type="chapter"><title>Introduction</title><p>It's <b>bold</b>.</p></sec>

calling end({ prettyPrint: true }) results in the following output:

<title> Introduction </title>

It's bold .

Expected behavior

I would have expected the p element to keep all inline content

<sec sec-type="chapter">
    <title>Introduction</title>
    <p>It's <b>bold</b>.</p>
</sec>

There is a test for mixed content that tests for the current behavior, I am unsure whether that is correct (Oxygen XML and other editors format the text as expected).

Version:

  • node.js: 16.x
  • xmlbuilder2 3.0.1

Additional context
Highly appreciate this straightforward library! I hope the issue makes sense.

@frederik frederik added the bug Something isn't working label Mar 31, 2023
@universalhandle
Copy link
Collaborator

Hello, @frederik! Sorry I missed this bug report! Can you reproduce this in v3.1.0?

@javadev
Copy link

javadev commented May 12, 2023

It may be stored in this structure

{
  "sec": {
    "-sec-type": "chapter",
    "title": "Introduction",
    "p": {
      "#text": "It's ",
      "b": "bold",
      "#text1": "."
    }
  },
  "#omit-xml-declaration": "yes"
}

@frederik
Copy link
Author

hey @universalhandle,

I can reproduce it on 3.1.1 (confirmed this on a node:latest container just to be sure it was only 16)

const fs = require('fs');
const { create } = require('xmlbuilder2');

const doc = create({ version: '1.0' })
    .ele('p').txt("It's ").ele('b').txt('bold').up().txt('.').up()
    .doc();

fs.writeFileSync('test.xml', doc.end({ prettyPrint: true }), 'utf8');

package-lock

"node_modules/xmlbuilder2": {
      "version": "3.1.1",
      "resolved": "https://registry.npmjs.org/xmlbuilder2/-/xmlbuilder2-3.1.1.tgz",
      "integrity": "sha512-WCSfbfZnQDdLQLiMdGUQpMxxckeQ4oZNMNhLVkcekTu7xhD4tuUDyAPoY8CwXvBYE6LwBHd6QW2WZXlOWr1vCw==",
      "dependencies": {
        "@oozcitak/dom": "1.15.10",
        "@oozcitak/infra": "1.0.8",
        "@oozcitak/util": "8.3.8",
        "js-yaml": "3.14.1"
      },
      "engines": {
        "node": ">=12.0"
      }
    }

produces:

<?xml version="1.0"?>
<p>
  It's 
  <b>bold</b>
  .
</p>

@mdovhopo
Copy link

mdovhopo commented Jun 4, 2024

i did open a PR #180 that fixes the other issue #94 , I believe it should also fix this issue as well... would appreciate reviews/comments.

P.S. i am using my forked version in my project,because correct pretty-printing is important to my usecase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants