From b6eebdff83f5d69066d62451b98c6771e51e90e4 Mon Sep 17 00:00:00 2001 From: Bret McMillan Date: Mon, 17 Nov 2008 14:22:19 -0500 Subject: fixes for headers; intial support for lists and tables, both still need more work --- .../tiny_mce/plugins/mediawiki/editor_plugin.js | 67 ++++++++++++++++------ .../tiny_mce/plugins/mediawiki/wiki2html.js | 43 +++++++++++++- 2 files changed, 93 insertions(+), 17 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>/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>/gim,"[$1 $2]"); + + // images + // XXXXXXXXXXXXXXXXXXXXXX + + // to '' rep(/(.*?)<\/em>/gim, "''$1''"); @@ -84,31 +106,44 @@ rep(/(.*?)<\/strong>/gim, "'''$1'''"); // headers - rep(/

    (.*?)<\/h1>/gim, "\n=$1="); - rep(/

    (.*?)<\/h2>/gim, "\n==$1=="); - rep(/

    (.*?)<\/h3>/gim, "\n===$1==="); - rep(/

    (.*?)<\/h4>/gim, "\n====$1===="); - rep(/

    (.*?)<\/h5>/gim, "\n=====$1====="); - rep(/
    (.*?)<\/h6>/gim, "\n======$1======"); + rep(/

    (.*?)<\/h1>/gim, "=$1="); + rep(/

    (.*?)<\/h2>/gim, "==$1=="); + rep(/

    (.*?)<\/h3>/gim, "===$1==="); + rep(/

    (.*?)<\/h4>/gim, "====$1===="); + rep(/

    (.*?)<\/h5>/gim, "=====$1====="); + rep(/
    (.*?)<\/h6>/gim, "======$1======"); //

    - rep(/

    ([\s\S]*?)<\/p>/gim, '\n\n$1'); + rep(/

    ([\s\S]*?)<\/p>/gim, '\n$1'); - //
    - rep(/]*>/gim, '\n\n'); + + //

    + rep(/([\s\S]*?)<\/p>/gim, '\n$1'); + + // various indents... + //

    + rep(/

    ([\s\S]*?)<\/p>/gim, '\n $1'); + rep(/

    ([\s\S]*?)<\/pre>/gim, '\n $1');
    +			rep(/
    ([\s\S]*?)<\/blockquote>/gim, '\n $1'); // - //rep(/ /gi, ' '); + rep(/\ \;/gim, ' '); - // ul,ol lists - // XXXXXXXXXXXXXXXXXXXXXX - + //
    + rep(/]*?>/gim, '\n'); - // images - // XXXXXXXXXXXXXXXXXXXXXX + // ul,ol lists + s = t['convertlists'](s); // tables // XXXXXXXXXXXXXXXXXXXXXX + // this doesn't work great atm ... :/ + rep(/.*?(?:)([\s\S]*?)<\/tbody>.*?<\/table>/gim, "{|\n$1|}\n"); + rep(/\s*?([\s\S]*?)\s*?<\/tr>/gim, "|-\n$1"); + rep(/[\s\n]*?([^\n]*?)[\n\s]*?<\/td>/gim, "|$1\n"); + // this last one 'cause my regex's seem to leave 's all over the place... + // probably due to a tinymce cleanup function repairing bad html + // rep(/\s*?\s*?/gim, ""); return s; }, diff --git a/extensions/tinymce/jscripts/tiny_mce/plugins/mediawiki/wiki2html.js b/extensions/tinymce/jscripts/tiny_mce/plugins/mediawiki/wiki2html.js index 63ccf52..2d3f442 100644 --- a/extensions/tinymce/jscripts/tiny_mce/plugins/mediawiki/wiki2html.js +++ b/extensions/tinymce/jscripts/tiny_mce/plugins/mediawiki/wiki2html.js @@ -46,6 +46,46 @@ function wiki2html(s) { } return list(s + + /* tables */ + .replace(/\{\|([.\n\s\S]*?)\|\}/gim, function (m, l) { + + var to_return = ''; + var rows = l.split("|-"); + + if (!rows) { + return m; + } + + // add the caption, if it exists + var caption = ''; + var i = 0; + + if (rows[0].match(/\|\+\s*?(.*?)\n/gim)) { + to_return += ""; + i++; + } + + to_return += ''; + var num_rows = rows.length; + + while (i < num_rows) { + + if (!rows[i].match(/[^\s\n]/)) { + i++; + continue; + } + + rows[i] = rows[i].replace(/\|\|\s*(.*?)/gim, "\n|$1"); + + rows[i] = rows[i].split("\n|"); + + to_return += ""; + i++; + } + + return to_return + '
    FIXME: SOME CAPTION
    " + rows[i].join("") + "
    '; + }) /* BLOCK ELEMENTS */ .replace(/(?:^|\n+)([^# =\*<].+)(?:\n+|$)/gm, function (m, l) { @@ -55,7 +95,7 @@ function wiki2html(s) { .replace(/(?:^|\n)[ ]{2}(.*)+/g, function (m, l) { // blockquotes if (l.match(/^\s+$/)) return m; - return '
    ' + l + '
    '; + return '
    ' + l + '
    '; }) .replace(/((?:^|\n)[ ]+.*)+/g, function (m) { // code @@ -97,6 +137,7 @@ function wiki2html(s) { return '' + (p.length ? p.join('|') : link) + ''; } }) + ); } -- cgit