- for (i in chunks) {
- if (chunks[i]) {
- if (params.tag == 'akap' && chunks[i].match(/^---/))
- tag = 'akap_dialog';
- else tag = params.tag;
- tagger(context, {tag: tag}, chunks[i], 0, insert_done);
- text += padding;
- }
+ var padding_top = text.match(/^\n+/)
+ output = padding_top ? padding_top[0] : '';
+
+ padding = '';
+ for(var i=params.padding; i; --i) {
+ padding += "\n";
+ }
+
+ text = text.substr(output.length);
+ var chunk_reg = new RegExp("^([\\s\\S]+?)(\\n{"+params.split+",}|$)");
+ while (match = text.match(chunk_reg)) {
+ if (params.tag == 'akap' && match[1].match(/^---/))
+ tag = 'akap_dialog';
+ else tag = params.tag;
+ tagger(context, {tag: tag}, match[1], 0, 0, insert_done);
+ if (match[2].length > params.padding)
+ output += match[2];
+ else
+ output += padding;
+ text = text.substr(match[0].length)