Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.
/ xformatting Public archive

Formats XML into a more readable format by inserting linebreaks and indents. Supports all element types (e.g. processing instructions) and also the xml:space attribute :shipit:

License

Notifications You must be signed in to change notification settings

xpublisher/xformatting

Repository files navigation

<xformatting/>

Issues Travis


Formats XML into a more readable format by inserting linebreaks and indents. Supports all element types (e.g. processing instructions) and also the xml:space attribute

Installation

$ npm install -S xformatting

Usage

Synchronous

const { formatSync } = require('xformatting');

const xml = '<xformatting><code xml:space="preserve">var hello = "world"</code></xformatting>';
const formattedXml = formatSync(xml);
console.log(formattedXml);

Asynchronous

const { format } = require('xformatting');

const xml = '<xformatting><code xml:space="preserve">var hello = "world"</code></xformatting>';
format(xml).then((formattedXml) => {
	console.log(formattedXml);
});

Options

You can pass an options object to the methods as a second argument. In this table you will find all setting options:

Name Type Default Description
linebreak string "\r\n" New line characters
indentation string "\t" Characters for indentation
preserveSpaceAttribute string "xml:space" Attribute name for preserve space
preserveSpaceFn Function Function to check if preserve space is active

License

MIT

About

Formats XML into a more readable format by inserting linebreaks and indents. Supports all element types (e.g. processing instructions) and also the xml:space attribute :shipit:

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •