+ text = padding_top + "<strofa></strofa>" + padding_bottom;
+ move_forward -= "</strofa>".length;
+ move_up += params.padding_bottom || 0;
+ }
+
+ done(text, move_forward, move_up);
+ }.bind(this);
+
+
+ this.scriptlets['autotag'] = function(context, params, text, move_forward, move_up, done)
+ {
+ if(!text.match(/^\n+$/)) done(text, move_forward, move_up);
+
+ var output = '';
+
+ function insert_done(text, mf, mu) {
+ output += text;
+ }
+
+ if (!params.split) params.split = 2;
+ if (!params.padding) params.padding = 3;
+
+ if (params.tag == 'strofa')
+ tagger = this.scriptlets['insert_stanza'];
+ else
+ tagger = this.scriptlets['insert_tag'];
+
+ 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)