< Misplaced Pages:AutoEd
Browse history interactively ← Previous edit Content deleted Content addedInline
Revision as of 20:38, 25 January 2024 view source Pppery (talk | contribs )Interface administrators , Administrators 100,463 edits Per request← Previous edit
Latest revision as of 16:30, 28 December 2024 view source Pppery (talk | contribs )Interface administrators , Administrators 100,463 edits Per request on talk
Line 15:
Line 15:
str = str.replace(/()*<*HR*>/gi, '$1----');
str = str.replace(/()*<*HR*>/gi, '$1----');
// str = str.replace(/(.)<*HR*>/gi, '$1\n----'); // Breaks wikitables
// str = str.replace(/(.)<*HR*>/gi, '$1\n----'); // Breaks wikitables
// Not really an HTML-to-wikitext fix, but close enough
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');
Latest revision as of 16:30, 28 December 2024
//Convert HTML to wikitext
function autoEdHTMLtoWikitext(str) {
// <b> and <i> tags
str = str.replace(/<B*>((?:|<*\/>|<(+)(?:| *)>*<\/\3>)*?)<\/\1*>/gi, "'''$1'''");
str = str.replace(/<I*>((?:|<*\/>|<(+)(?:| *)>*<\/\3>)*?)<\/\1*>/gi, "''$1''");
// </br>, <\br>, <br\>, <BR />, ...
str = str.replace(/<+BR*>/gim, '<br />');
str = str.replace(/<*BR*+*>/gim, '<br />');
// <.br>, <br.>, <Br>, ...
str = str.replace(/<*BR*>/gim, '<br>');
// <br>>, <<br />, <<br >> ...
str = str.replace(/<*(<br*>)/gim, '$1');
str = str.replace(/(<br*>)*>/gim, '$1');
// <hr>
str = str.replace(/()*<*HR*>/gi, '$1----');
// str = str.replace(/(.)<*HR*>/gi, '$1\n----'); // Breaks wikitables
// Repeated references tag
str = str.replace(/(<references \/>)*\1/gim, '$1');
// Make sure <H1>, ..., <H6> is after a newline
str = str.replace(/()*(<H*>)/gim, '$1\n$2');
// Make sure </H1>, ..., </H6> is before a newline
str = str.replace(/(<\/H*>)*()/gim, '$1\n$2');
// Remove newlines from inside <H1>, ..., <H6>
var loopcount = 0;
while( str.search( /<H()*>(?:|<\/?*>)*?<\/H\1*>/gim ) >= 0 && loopcount <= 10 ) {
str = str.replace(/(<H)()(*>(?:|<\/?*>)*?)((?:|<\/?*>)*?<\/H)\2(*>)/gim, '$1$2$3 $4$2$5');
loopcount++;
}
// Replace <H1>, ..., <H6> with wikified section headings
str = str.replace(/(^|)*<H1*>(*?)<\/H1*>*(|$)/gim, '$1=$2=$3');
str = str.replace(/(^|)*<H2*>(*?)<\/H2*>*(|$)/gim, '$1==$2==$3');
str = str.replace(/(^|)*<H3*>(*?)<\/H3*>*(|$)/gim, '$1===$2===$3');
str = str.replace(/(^|)*<H4*>(*?)<\/H4*>*(|$)/gim, '$1====$2====$3');
str = str.replace(/(^|)*<H5*>(*?)<\/H5*>*(|$)/gim, '$1=====$2=====$3');
str = str.replace(/(^|)*<H6*>(*?)<\/H6*>*(|$)/gim, '$1======$2======$3');
return str;
}
Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.
**DISCLAIMER** We are not affiliated with Wikipedia, and Cloudflare.
The information presented on this site is for general informational purposes only and does not constitute medical advice.
You should always have a personal consultation with a healthcare professional before making changes to your diet, medication, or exercise routine.
AI helps with the correspondence in our chat.
We participate in an affiliate program. If you buy something through a link, we may earn a commission 💕
↑