Misplaced Pages

:AutoEd/htmltowikitext.js: Difference between revisions - Misplaced Pages

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
< Misplaced Pages:AutoEd Browse history interactivelyNext edit →Content deleted Content addedVisualWikitext
Revision as of 20:56, 28 April 2009 view sourceAFigureOfBlue (talk | contribs)Edit filter managers, Administrators53,878 edits Copy from Misplaced Pages:AutoEd/isbn.js and User:Drilnoth/codefixer.js  Revision as of 20:56, 28 April 2009 view source AFigureOfBlue (talk | contribs)Edit filter managers, Administrators53,878 editsm CleanNext edit →
Line 3: Line 3:
function autoEdHTMLtoWikitext(str) { //MAIN FUNCTION describes list of fixes function autoEdHTMLtoWikitext(str) { //MAIN FUNCTION describes list of fixes


//Allows WikiMagic to work with ISBNs //Convert HTML to wikitext
str = str.replace(new RegExp('ISBN-10:|ISBN-13:|ISBN-10|ISBN-13|ISBN:', 'gi'), 'ISBN');
str = str.replace(/<(B|STRONG)*>(*)<\/\1*>/gi, "'''$2'''"); // Wikify <B> and <STRONG> str = str.replace(/<(B|STRONG)*>(*)<\/\1*>/gi, "'''$2'''"); // Wikify <B> and <STRONG>
str = str.replace(/<(I|EM)*>(*)<\/\1*>/gi, "''$2''"); // Wikify <I> and <EM> str = str.replace(/<(I|EM)*>(*)<\/\1*>/gi, "''$2''"); // Wikify <I> and <EM>

Revision as of 20:56, 28 April 2009

//

function autoEdHTMLtoWikitext(str) { //MAIN FUNCTION describes list of fixes
    //Convert HTML to wikitext
    str = str.replace(/<(B|STRONG)*>(*)<\/\1*>/gi,  "'''$2'''"); // Wikify <B> and <STRONG>
    str = str.replace(/<(I|EM)*>(*)<\/\1*>/gi,  "''$2''");       // Wikify <I> and <EM>
    str = str.replace(/<+BR*>/gi, '<br />'); // Tag starts with a slash or period
    str = str.replace(/<*BR*+*>/gi, '<br />'); // Tag ends with a slash or period
    str = str.replace(/<*BR*>/gi, '<br>'); // Tag contains no slashes
    str = str.replace(/()*<*HR*>/gi, '$1----');
    str = str.replace(/(.)<*HR*>/gi, '$1\n----');
    str = str.replace(new RegExp('<REFERENCES/ >|<REFERENCES></REFERENCES>|<REFERENCES>|<REFERENCES/>', 'gi'), '<references />'); //Not really an HTML-to-wikitext fix, but close enough
    str = str.replace(/()*(<H*>)/gim, '$1\n$2');   // 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(/(^|)*<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;
}
//