-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Description
Description
The html_beautify function incorrectly formats CDATA sections by moving them to a new line, treating them like regular XML elements. CDATA content should remain inline, just like regular text content.
I expect the following:
<simple><![CDATA[You will see this in the document]]></simple>
to be treated equally to:
<simple>This is plain text</simple>
while the former is formatted to:
<simple>
<![CDATA[You will see this in the document]]>
</simple>
Input
The code looked like this before beautification:
<document>
<cases>
<case>
<simple><![CDATA[You will see this in the document]]></simple>
</case>
</cases>
</document>
Expected Output
The code should have looked like this after beautification:
<document>
<cases>
<case>
<simple><![CDATA[You will see this in the document]]></simple>
</case>
</cases>
</document>
Actual Output
The code actually looked like this after beautification:
<document>
<cases>
<case>
<simple>
<![CDATA[You will see this in the document]]>
</simple>
</case>
</cases>
</document>
Steps to Reproduce
const fs = require("fs");
const html_beautify = require("js-beautify/js/lib/beautify-html").html_beautify;
const config = {
e4x: true,
wrap_line_length: 80,
break_chained_methods: true,
unescape_strings: true,
indent_with_tabs: true,
unformatted: []
};
const input = fs.readFileSync("example.xml", "utf-8");
const formatted = html_beautify(input, config);
console.log(formatted);
I tested using version 1.15.4.
Metadata
Metadata
Assignees
Labels
No labels