Revision as of 19:06, 25 May 2020 view sourcePlastikspork (talk | contribs)Edit filter managers, Administrators258,929 edits Fix← Previous edit | Revision as of 22:27, 25 May 2020 view source Plastikspork (talk | contribs)Edit filter managers, Administrators258,929 edits Per talk pageNext edit → | ||
Line 1: | Line 1: | ||
//<syntaxhighlight lang=javascript> | |||
//Convert HTML to wikitext | //Convert HTML to wikitext | ||
function autoEdHTMLtoWikitext(str) { | function autoEdHTMLtoWikitext(str) { | ||
Line 18: | Line 16: | ||
str = str.replace(/(.)<*HR*>/gi, '$1\n----'); | str = str.replace(/(.)<*HR*>/gi, '$1\n----'); | ||
// Not really an HTML-to-wikitext fix, but close enough | // Not really an HTML-to-wikitext fix, but close enough | ||
str = str.replace(/<*REFERENCES*>/gim, '<references />'); | str = str.replace(/(\s*)<*REFERENCES*>/gim, '$1<references />'); | ||
// Repeated references tag | // Repeated references tag | ||
str = str.replace(/(<references \/>)*\1/gim, '$1'); | str = str.replace(/(<references \/>)*\1/gim, '$1'); | ||
Line 41: | Line 39: | ||
return str; | return str; | ||
} | } | ||
//</syntaxhighlight> |
Revision as of 22:27, 25 May 2020
//Convert HTML to wikitext function autoEdHTMLtoWikitext(str) {
// , , , and tags str = str.replace(/<(B|STRONG)*>((?:|<*\/>|<(+)(?:| *)>*<\/\3>)*?)<\/\1*>/gi, "$2"); str = str.replace(/<(I|EM)*>((?:|<*\/>|<(+)(?:| *)>*<\/\3>)*?)<\/\1*>/gi, "$2"); //
, <\br>, <br\>,
, ... str = str.replace(/<+BR*>/gim, '
'); str = str.replace(/<*BR*+*>/gim, '
'); // <.br>, <br.>,
, ... str = str.replace(/<*BR*>/gim, '
'); //
>, <
, <
> ... str = str.replace(/<*(<br*>)/gim, '$1'); str = str.replace(/(<br*>)*>/gim, '$1');
//
str = str.replace(/()*<*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*>/gim, '$1'); // Repeated references tag str = str.replace(/()*\1/gim, '$1');
// Make sure
, ...,
is after a newline str = str.replace(/()*(<H*>)/gim, '$1\n$2'); // Make sure
, ..., is before a newline
str = str.replace(/(<\/H*>)*()/gim, '$1\n$2');
// Remove newlines from inside