From 6691c0eec4360bc11ea09d7bbb5e03a725e0c847 Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Sat, 23 Jan 2016 12:25:53 -0500 Subject: [PATCH] dealing with back indenting --- index.js | 13 +++++++------ test.txt | 1 + 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 2126c8e..0146ad2 100755 --- a/index.js +++ b/index.js @@ -16,10 +16,12 @@ module.exports = function(file_path, callback){ } return result; } - var popTabStack = function(tabStack, current_line_num_tabs, previous_line_num_tabs){ + var popHTMLStack = function(html_stack, current_line_num_tabs, previous_line_num_tabs){ var result = ''; for(var i = previous_line_num_tabs; i > current_line_num_tabs; i--){ - result += tabStack.pop(); + result += html_stack.pop(); + result += html_stack.pop(); + result += html_stack.pop(); } return result; } @@ -31,7 +33,6 @@ module.exports = function(file_path, callback){ var html_stack = []; for(var i = 0; i < lines.length; i++){ if(lines[i] !== ''){ - console.log(i + lines[i]); var tabs_array = lines[i].split('\t'); var current_line_num_tabs = tabs_array.length - 1; if(current_line_num_tabs > previous_line_num_tabs){ @@ -40,6 +41,9 @@ module.exports = function(file_path, callback){ } else if (current_line_num_tabs === previous_line_num_tabs) { html += html_stack.pop(); } + else if(current_line_num_tabs < previous_line_num_tabs){ + html += popHTMLStack(html_stack, current_line_num_tabs, previous_line_num_tabs); + } html += insertTabs((current_line_num_tabs * 2) + 1) + '
  • \n'; html += insertTabs((current_line_num_tabs * 2) + 2) + tabs_array[tabs_array.length - 1] + '\n'; html_stack.push(insertTabs((current_line_num_tabs * 2) + 1) + '
  • \n'); @@ -55,9 +59,6 @@ module.exports = function(file_path, callback){ var html_push_string = '\n' + insertTabs(num_tabs * 2) + ''; tabStack.push(html_push_string); } - else if(num_tabs < previous_line){ - html += popTabStack(tabStack, num_tabs, previous_line); - } html += '\n' + insertTabs(num_tabs * 2 + 1) + '
  • ' + split_value[split_value.length - 1] + '
  • '; previous_line = num_tabs; diff --git a/test.txt b/test.txt index 3fea2c7..815317b 100644 --- a/test.txt +++ b/test.txt @@ -2,3 +2,4 @@ first line second line third line indented once indented twice + last line indented once