From: Radek Czajka Date: Fri, 26 Nov 2010 15:22:14 +0000 (+0100) Subject: #958: keep newlines in autotagging X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/1e71d943e17f0011d65d9e92969ff2aa3b73ff31 #958: keep newlines in autotagging --- diff --git a/redakcja/static/js/button_scripts.js b/redakcja/static/js/button_scripts.js index c97a2314..ff17eea4 100644 --- a/redakcja/static/js/button_scripts.js +++ b/redakcja/static/js/button_scripts.js @@ -241,38 +241,45 @@ function ScriptletCenter() { if(!text.match(/^\n+$/)) done(text, move_forward, move_up); - function insert_done(output, mf) { - text += output; + var output = ''; + + function insert_done(text, mf, mu) { + output += text; } if (!params.split) params.split = 2; if (!params.padding) params.padding = 3; - chunks = text.replace(/^\n+|\n+$/, '').split(new RegExp("\\n{"+params.split+",}")); - text = text.match(/^\n+/); - if (!text) - text = ''; - padding = ''; - for(; params.padding; params.padding--) { - padding += "\n"; - } - if (params.tag == 'strofa') tagger = this.scriptlets['insert_stanza']; else tagger = this.scriptlets['insert_tag']; - 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, 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"; } - done(text, move_forward, move_up); + 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) + } + + output += text; + + done(output, move_forward, move_up); }.bind(this); }