xml-formatter
Advanced tools
Comparing version 1.0.1 to 1.1.0
17
index.js
function newLine(output) { | ||
output.content += '\n'; | ||
output.content += '\r\n'; | ||
var i; | ||
@@ -48,2 +48,13 @@ for (i = 0; i < output.level; i++) { | ||
if (!nodePreserveSpace && output.options.collapseContent) { | ||
var containsTextNodes = node.children.some(function(child) { | ||
return child.name === '#text'; | ||
}); | ||
if (containsTextNodes) { | ||
nodePreserveSpace = true; | ||
} | ||
} | ||
node.children.forEach(function(child) { | ||
@@ -85,2 +96,3 @@ processNode(child, output, preserveSpace || nodePreserveSpace); | ||
* @config {Boolean} [stripComments=false] True to strip the comments | ||
* @config {Boolean} [collapseContent=false] True to keep content in the same line as the element. Only works if element contains at least one text node | ||
* @returns {string} | ||
@@ -94,2 +106,3 @@ */ | ||
options.stripComments = options.stripComments === true; | ||
options.collapseContent = options.collapseContent === true; | ||
@@ -116,2 +129,2 @@ var parse = require('xml-parser-xo'); | ||
module.exports = format; | ||
module.exports = format; |
{ | ||
"name": "xml-formatter", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"repository": "chrisbottin/xml-formatter", | ||
@@ -5,0 +5,0 @@ "description": "Converts XML into a human readable format (pretty print) while respecting the xml:space attribute", |
@@ -24,3 +24,3 @@ | ||
var format = require('xml-formatter'); | ||
var xml = '<root><!-- content --><content><p xml:space="preserve">This is <b>some</b> content.</content></p>'; | ||
var xml = '<root>content><p xml:space="preserve">This is <b>some</b> content.</content></p>'; | ||
@@ -35,3 +35,2 @@ var formattedXml = format(xml); | ||
<root> | ||
<!-- test --> | ||
<content> | ||
@@ -49,5 +48,5 @@ <p xml:space="preserve">This is <b>some</b> content.</p> | ||
var format = require('xml-formatter'); | ||
var xml = '<root><!-- content --><content><p xml:space="preserve">This is <b>some</b> content.</content></p>'; | ||
var xml = '<root><!-- content --><content><p>This is <b>some</b> content.</content></p>'; | ||
var options = {indentation: ' ', stripComments: true}; | ||
var options = {indentation: ' ', stripComments: true, collapseContent: true}; | ||
var formattedXml = format(xml, options); | ||
@@ -63,3 +62,3 @@ | ||
<content> | ||
<p xml:space="preserve">This is <b>some</b> content.</p> | ||
<p>This is <b>some</b> content.</p> | ||
</content> | ||
@@ -72,2 +71,3 @@ </root> | ||
- `debug` (Boolean, default=`false`) Displays a tree of the parsed XML before formatting. | ||
- `collapseContent` (Boolean, default=`false`] True to keep content in the same line as the element. Only works if element contains at least one text node | ||
@@ -74,0 +74,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
382
31758
11
4