diff options
Diffstat (limited to 'extensions/tinymce/jscripts/tiny_mce/plugins/mediawiki/editor_plugin.js')
-rw-r--r-- | extensions/tinymce/jscripts/tiny_mce/plugins/mediawiki/editor_plugin.js | 67 |
1 files changed, 51 insertions, 16 deletions
diff --git a/extensions/tinymce/jscripts/tiny_mce/plugins/mediawiki/editor_plugin.js b/extensions/tinymce/jscripts/tiny_mce/plugins/mediawiki/editor_plugin.js index 47f2770..e69dc5f 100644 --- a/extensions/tinymce/jscripts/tiny_mce/plugins/mediawiki/editor_plugin.js +++ b/extensions/tinymce/jscripts/tiny_mce/plugins/mediawiki/editor_plugin.js @@ -59,9 +59,26 @@ // Private methods + convertlists : function(s) { + var t = this; + + s = s.replace(/<(?:ol|ul)>(.*?)<\/(?:ol|ul)>/gim, function (m) { + var glyph = m.match(/ol/) ? '#' : '*'; + + m.replace(/<li>(.*?)<\/li>/gim, glyph + "$1"); + + // TODO: fixme, this needs to be recursive... + //m = t['convertlists'](m); + + return m; + }); + + return s; + }, + // HTML -> MediaWiki, it'd be nice to get this upstream into remy's code _html2mw : function(s) { - // s = tinymce.trim(s); + var t = this; function rep(re, str) { s = s.replace(re, str); @@ -77,6 +94,11 @@ // handle external urls with body text rep(/<a.*?href=\"(.+?)\".*?>(.+?)<\/a>/gim,"[$1 $2]"); + + // images + // XXXXXXXXXXXXXXXXXXXXXX + + // <em> to '' rep(/<em>(.*?)<\/em>/gim, "''$1''"); @@ -84,31 +106,44 @@ rep(/<strong>(.*?)<\/strong>/gim, "'''$1'''"); // headers - rep(/<h1>(.*?)<\/h1>/gim, "\n=$1="); - rep(/<h2>(.*?)<\/h2>/gim, "\n==$1=="); - rep(/<h3>(.*?)<\/h3>/gim, "\n===$1==="); - rep(/<h4>(.*?)<\/h4>/gim, "\n====$1===="); - rep(/<h5>(.*?)<\/h5>/gim, "\n=====$1====="); - rep(/<h5>(.*?)<\/h6>/gim, "\n======$1======"); + rep(/<h1>(.*?)<\/h1>/gim, "=$1="); + rep(/<h2>(.*?)<\/h2>/gim, "==$1=="); + rep(/<h3>(.*?)<\/h3>/gim, "===$1==="); + rep(/<h4>(.*?)<\/h4>/gim, "====$1===="); + rep(/<h5>(.*?)<\/h5>/gim, "=====$1====="); + rep(/<h5>(.*?)<\/h6>/gim, "======$1======"); // <p> - rep(/<p>([\s\S]*?)<\/p>/gim, '\n\n$1'); + rep(/<p>([\s\S]*?)<\/p>/gim, '\n$1'); - // <br> - rep(/<br[^>]*>/gim, '\n\n'); + + // <p align> + rep(/<p.*?align\: left.*?>([\s\S]*?)<\/p>/gim, '\n$1'); + + // various indents... + // <p style="padding-left"...> + rep(/<p .*?padding\-left.*?>([\s\S]*?)<\/p>/gim, '\n $1'); + rep(/<pre>([\s\S]*?)<\/pre>/gim, '\n $1'); + rep(/<blockquote>([\s\S]*?)<\/blockquote>/gim, '\n $1'); // <nbsp> - //rep(/ /gi, ' '); + rep(/\ \;/gim, ' '); - // ul,ol lists - // XXXXXXXXXXXXXXXXXXXXXX - + // <br> + rep(/<br[^>]*?>/gim, '\n'); - // images - // XXXXXXXXXXXXXXXXXXXXXX + // ul,ol lists + s = t['convertlists'](s); // tables // XXXXXXXXXXXXXXXXXXXXXX + // this doesn't work great atm ... :/ + rep(/<table.*?>.*?(?:<tbody>)([\s\S]*?)<\/tbody>.*?<\/table>/gim, "{|\n$1|}\n"); + rep(/<tr.*?>\s*?([\s\S]*?)\s*?<\/tr>/gim, "|-\n$1"); + rep(/<td.*?>[\s\n]*?([^\n]*?)[\n\s]*?<\/td>/gim, "|$1\n"); + // this last one 'cause my regex's seem to leave <td/>'s all over the place... + // probably due to a tinymce cleanup function repairing bad html + // rep(/\s*?<td\/>\s*?/gim, ""); return s; }, |