From 91000a031a1c69a8e7e965d1c8d3a713d3c927f7 Mon Sep 17 00:00:00 2001 From: Justin Ohms Date: Fri, 27 Apr 2012 12:29:43 -0700 Subject: [PATCH] Adds support for line continuation via indentation Allows long blocks of text or arrays to be cleaning added to an ini file. If a line begins with empty space (tab, space) it will automatically be appended to the previous line. ! This assumes that section heads and keys are NOT indented. ! Example ini: [SectionHead] key1=value of key 1 my_array=val1, val2, val3 long_text=This is some long text that I need to include it wraps multiple lines. The resulting object: {SectionHead: { key1:'value of key 1', my_array:'val1, val2, val3', long_text:'This is some long text that I need to include it wraps multiple lines.' } } --- lib/node-iniparser.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/node-iniparser.js b/lib/node-iniparser.js index 93397a3..b212252 100644 --- a/lib/node-iniparser.js +++ b/lib/node-iniparser.js @@ -39,6 +39,9 @@ module.exports.parseSync = function(file){ }; function parse(data){ + // Line continuation, if a line starts with white space "\s" it will be appended to the previous line + data = data.replace(/((\r\n\s+)?|(\r\s+)?|(\n\s+)?)/mg,""); //this regex combines lines that have leading white space + var value = {}; var lines = data.split(/\r\n|\r|\n/); var section = null;