KidzSearch Encyclopedia:AutoEd/htmltowikitext.js
//<source lang=javascript>
//Convert HTML to wikitext function autoEdHTMLtoWikitext(str) {
// , , , and tags str = str.replace(/<(B|STRONG)[ ]*>((?:[^<>]|<[a-z][^<>]*\/>|<([a-z]+)(?:| [^<>]*)>[^<>]*<\/\3>)*?)<\/\1[ ]*>/gi, "$2"); str = str.replace(/<(I|EM)[ ]*>((?:[^<>]|<[a-z][^<>]*\/>|<([a-z]+)(?:| [^<>]*)>[^<>]*<\/\3>)*?)<\/\1[ ]*>/gi, "$2"); //
, <\br>, <br\>,
, ... str = str.replace(/<[\\\/]+BR[\\\/\s]*>/gim, '
'); str = str.replace(/<[\\\/\s]*BR[\s]*[\\\/]+[\s]*>/gim, '
'); // <.br>, <br.>,
, ... str = str.replace(/<[\s\.]*BR[\s\.]*>/gim, '
'); //
>, <
, <
> ... str = str.replace(/<[\s]*(<br[\s\/]*>)/gim, '$1'); str = str.replace(/(<br[\s\/]*>)[\s]*>/gim, '$1');
//
str = str.replace(/([\r\n])[\t ]*<[\\\/\. ]*HR[\\\/\. ]*>/gi, '$1----'); str = str.replace(/(.)<[\\\/\. ]*HR[\\\/\. ]*>/gi, '$1\n----'); // Not really an HTML-to-wikitext fix, but close enough str = str.replace(/<[\\\/\s]*REFERENCES[\\\/\s]*>/gim, ''); // Repeated references tag str = str.replace(/()[\s]*\1/gim, '$1');
// Make sure
, ..., is after a newline
str = str.replace(/([^\r\n ])[\t ]*(<H[1-6][^<>]*>)/gim, '$1\n$2');
// Make sure
, ...,
is before a newline
str = str.replace(/(<\/H[1-6][^<>]*>)[\t ]*([^\r\n ])/gim, '$1\n$2');
// Remove newlines from inside