Revision as of 19:06, 25 May 2020 view sourcePlastikspork (talk | contribs)Edit filter managers, Administrators258,929 edits Fix← Previous edit |
Latest revision as of 16:30, 28 December 2024 view source Pppery (talk | contribs)Interface administrators, Administrators100,463 edits Per request on talk |
(4 intermediate revisions by 2 users not shown) |
Line 1: |
Line 1: |
|
//<syntaxhighlight lang=javascript> |
|
|
|
|
|
//Convert HTML to wikitext |
|
//Convert HTML to wikitext |
|
function autoEdHTMLtoWikitext(str) { |
|
function autoEdHTMLtoWikitext(str) { |
|
// <b>, <strong>, <i>, and <em> tags |
|
// <b> and <i> tags |
|
str = str.replace(/<(B|STRONG)*>((?:|<*\/>|<(+)(?:| *)>*<\/\3>)*?)<\/\1*>/gi, "'''$2'''"); |
|
str = str.replace(/<B*>((?:|<*\/>|<(+)(?:| *)>*<\/\3>)*?)<\/\1*>/gi, "'''$1'''"); |
|
str = str.replace(/<(I|EM)*>((?:|<*\/>|<(+)(?:| *)>*<\/\3>)*?)<\/\1*>/gi, "''$2''"); |
|
str = str.replace(/<I*>((?:|<*\/>|<(+)(?:| *)>*<\/\3>)*?)<\/\1*>/gi, "''$1''"); |
|
// </br>, <\br>, <br\>, <BR />, ... |
|
// </br>, <\br>, <br\>, <BR />, ... |
|
str = str.replace(/<+BR*>/gim, '<br />'); |
|
str = str.replace(/<+BR*>/gim, '<br />'); |
Line 16: |
Line 14: |
|
// <hr> |
|
// <hr> |
|
str = str.replace(/()*<*HR*>/gi, '$1----'); |
|
str = str.replace(/()*<*HR*>/gi, '$1----'); |
|
str = str.replace(/(.)<*HR*>/gi, '$1\n----'); |
|
// str = str.replace(/(.)<*HR*>/gi, '$1\n----'); // Breaks wikitables |
|
// Not really an HTML-to-wikitext fix, but close enough |
|
|
str = str.replace(/<*REFERENCES*>/gim, '<references />'); |
|
|
// Repeated references tag |
|
// Repeated references tag |
|
str = str.replace(/(<references \/>)*\1/gim, '$1'); |
|
str = str.replace(/(<references \/>)*\1/gim, '$1'); |
Line 41: |
Line 37: |
|
return str; |
|
return str; |
|
} |
|
} |
|
|
|
|
//</syntaxhighlight> |
|