Skip to content

Commit

Permalink
Merge pull request #15 from jlank/indent-options
Browse files Browse the repository at this point in the history
added ability to specify indent level for pretty printing
  • Loading branch information
jlank committed May 14, 2013
2 parents d7bcca1 + a5c6d81 commit 7ee375d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ outputs:
- `standalone` if true, the `<?xml …?>` gets an additional attribute `standalone="true"`.
- `docType` if defined gets added as the `<!DOCTYPE …>` contents (unescaped).
- `prettyPrint` if truthy the output gets a rudimentary pretty print (good for debugging, don't expect too much)
- `indent` specify what unit you would like to indent by (spaces, tabstop, nothing - pass an empty string)


`jsontoxml.escape (string)`
Expand All @@ -82,8 +83,8 @@ outputs:
* escapes `"" & < >`

`jsontoxml.cdata (string)`
* wraps string with `<!CDATA[[ ]]>`

* wraps string with `<![CDATA[ ]]>`
* removes all occurences of close cdata (`]]>`) in input text

## more description
Expand Down
3 changes: 2 additions & 1 deletion jsontoxml.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ var process_to_xml = function(node_data,options){

var makeNode = function(name, content, attributes, level, hasSubNodes) {

var indent = options.prettyPrint ? '\n' + new Array(level).join("\t") : '';
var indent_value = options.indent !== undefined ? options.indent : "\t";
var indent = options.prettyPrint ? '\n' + new Array(level).join(indent_value) : '';

var node = [indent, '<',name, (attributes || '')];
if(content && content.length > 0) {
Expand Down

1 comment on commit 7ee375d

@soldair
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good stuff =)

Please sign in to comment.