summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBret McMillan <bretm@redhat.com>2008-11-17 14:22:19 -0500
committerBret McMillan <bretm@redhat.com>2008-11-17 14:22:19 -0500
commitb6eebdff83f5d69066d62451b98c6771e51e90e4 (patch)
tree64a8f754784934145701dbc1b290e9af37fef0f9
parentd493deead64ba76da6d8a295d619644167b01477 (diff)
downloadmediawiki-stuff-b6eebdff83f5d69066d62451b98c6771e51e90e4.zip
mediawiki-stuff-b6eebdff83f5d69066d62451b98c6771e51e90e4.tar.gz
mediawiki-stuff-b6eebdff83f5d69066d62451b98c6771e51e90e4.tar.xz
fixes for headers; intial support for lists and tables, both still need more work
-rw-r--r--extensions/tinymce/jscripts/tiny_mce/plugins/mediawiki/editor_plugin.js67
-rw-r--r--extensions/tinymce/jscripts/tiny_mce/plugins/mediawiki/wiki2html.js43
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>(.*?)<\/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(/&nbsp;/gi, ' ');
+ rep(/\&nbsp\;/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;
},
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 = '<table>';
+ 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 += "<caption>FIXME: SOME CAPTION</caption>";
+ i++;
+ }
+
+ to_return += '<tbody>';
+ 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 += "<tr><td>" + rows[i].join("</td><td>") + "</td></tr>";
+ i++;
+ }
+
+ return to_return + '</tbody></table>';
+ })
/* 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 '<blockquote>' + l + '</pre>';
+ return '<blockquote>' + l + '</blockquote>';
})
.replace(/((?:^|\n)[ ]+.*)+/g, function (m) { // code
@@ -97,6 +137,7 @@ function wiki2html(s) {
return '<a href="' + link + '">' + (p.length ? p.join('|') : link) + '</a>';
}
})
+
);
}