Skip to content

Commit

Permalink
conditional leading newline slice
Browse files Browse the repository at this point in the history
  • Loading branch information
jescalan committed Aug 24, 2016
1 parent d97f9ed commit 74ba774
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ module.exports = function reshapeBeautify (opts = {}) {
const indentDefault = opts.indent || 2
return function beautifyPlugin (tree) {
const indent = 0
// remove all indents from the tree to start
tree = sanitize(tree)
// adds a leading newline, which can be sliced off
return walk(tree, indent, indentDefault, false).slice(1)
// run the indent processing
tree = walk(tree, indent, indentDefault, false)
// if there's a leading newline/indent, it can be sliced off
if (tree[0].content.match(/^\s+$/)) { tree = tree.slice(1) }
return tree
}
}

Expand Down

0 comments on commit 74ba774

Please sign in to comment.