Skip to content

Commit

Permalink
feat: option blank lines, close #216, close #217
Browse files Browse the repository at this point in the history
  • Loading branch information
Scrum committed Jan 24, 2018
1 parent 6e51770 commit 00ce993
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const renderConditional = tree => {
}, []);
};

const indent = (tree, {rules: {indent, eol}}) => {
const indent = (tree, {rules: {indent, eol, blankLines}}) => {
const indentString = typeof indent === 'number' ? ' '.repeat(indent) : '\t';

const getIndent = level => `${eol}${indentString.repeat(level)}`;
Expand All @@ -92,19 +92,19 @@ const indent = (tree, {rules: {indent, eol}}) => {
}

if (level === 0 && index === 0) {
return [...previousValue, node, getIndent(level)];
return [...previousValue, node, blankLines];
}

if (level === 0) {
return [...previousValue, getIndent(level), node, getIndent(level)];
return [...previousValue, getIndent(level), node, blankLines];
}

if ((tree.length - 1) === index) {
return [...previousValue, getIndent(level), node, getIndent(--level)];
}

if (typeof node === 'string' && /<!(?:--)?\[endif]*?]>/.test(node)) {
return [...previousValue, getIndent(level), node, getIndent(0)];
return [...previousValue, getIndent(level), node, blankLines];
}

if (typeof node === 'string' && /<!(?:--)?\[[\s\S]*?]>/.test(node)) {
Expand All @@ -115,7 +115,7 @@ const indent = (tree, {rules: {indent, eol}}) => {
return [...previousValue, ...node.content.slice(0, -1)];
}

return [...previousValue, getIndent(level), node, getIndent(0)];
return [...previousValue, getIndent(level), node, blankLines];
}, []);

return setIndent(tree);
Expand Down
1 change: 1 addition & 0 deletions src/rules.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export default {
indent: 2,
blankLines: '\n',
eof: '\n',
eol: '\n'
};

0 comments on commit 00ce993

Please sign in to comment.