lib/macros.js
function(text) {
        var openItalic = false,
            cText = [],
            italicStart = new RegExp(/\{italic\}/),
            commandBreak = new RegExp(/\{break\}/),
            italicEnd = new RegExp(/\{end-italic\}/),
            finalText = "",
            textArray = text.split(''),
            idx = 0;

        for (idx = 0; idx <= textArray.length; idx++) {
            cText.push(textArray[idx]);
            if (italicStart.test(cText.join('')) && openItalic === false) {
                // found an italic start, push to array, reset.
                finalText += cText.join('');
                cText = [];
                openItalic = true;
            } else if (commandBreak.test(cText.join('')) && openItalic === false) {
                finalText += cText.join('');
                cText = [];
                openItalic = false;
            } else if (commandBreak.test(cText.join('')) && openItalic === true) {
                finalText += cText.join('').replace(commandBreak, '{end-italic}{break}');
                cText = [];
                openItalic = false;
            } else if (italicStart.test(cText.join('')) && openItalic === true) {
                // found an italic start within another italic...prepend an end
                finalText += cText.join('').replace(italicStart, '');
                cText = [];
                openItalic = true;
            } else if (italicEnd.test(cText.join('')) && openItalic === true) {
                finalText += cText.join('');
                cText = [];
                openItalic = false;
            } else if (italicEnd.test(cText.join('')) && openItalic === false) {
                //drop useless end italics that are out of place.
                finalText += cText.join('').replace(italicEnd, '');
                cText = [];
                openItalic = false;
            }
            if (idx === text.length) {
                if (openItalic) {
                    finalText += cText.join('') + '{end-italic}';
                } else {
                    finalText += cText.join('');
                }

                cText = [];
            }
        }

        return finalText;

    }
function(text) {
        var openItalic = false,
            cText = [],
            italicStart = new RegExp(/\{italic\}/),
            commandBreak = new RegExp(/\{break\}/),
            italicEnd = new RegExp(/\{end-italic\}/),
            finalText = "",
            textArray = text.split(''),
            idx = 0;

        for (idx = 0; idx <= textArray.length; idx++) {
            cText.push(textArray[idx]);
            if (italicStart.test(cText.join('')) && openItalic === false) {
                // found an italic start, push to array, reset.
                finalText += cText.join('');
                cText = [];
                openItalic = true;
            } else if (commandBreak.test(cText.join('')) && openItalic === false) {
                finalText += cText.join('');
                cText = [];
                openItalic = false;
            } else if (commandBreak.test(cText.join('')) && openItalic === true) {
                finalText += cText.join('').replace(commandBreak, '{end-italic}{break}');
                cText = [];
                openItalic = false;
            } else if (italicStart.test(cText.join('')) && openItalic === true) {
                // found an italic start within another italic...prepend an end
                finalText += cText.join('').replace(italicStart, '');
                cText = [];
                openItalic = true;
            } else if (italicEnd.test(cText.join('')) && openItalic === true) {
                finalText += cText.join('');
                cText = [];
                openItalic = false;
            } else if (italicEnd.test(cText.join('')) && openItalic === false) {
                //drop useless end italics that are out of place.
                finalText += cText.join('').replace(italicEnd, '');
                cText = [];
                openItalic = false;
            }
            if (idx === text.length) {
                if (openItalic) {
                    finalText += cText.join('') + '{end-italic}';
                } else {
                    finalText += cText.join('');
                }

                cText = [];
            }
        }

        return finalText;

    }
function ( text ) { var openItalic = false , cText = [ ] , italicStart = new RegExp ( / \{italic\} / ) , commandBreak = new RegExp ( / \{break\} / ) , italicEnd = new RegExp ( / \{end-italic\} / ) , finalText = "" , textArray = text . split ( '' ) , idx = 0 ; for ( idx = 0 ; idx <= textArray . length ; idx ++ ) { cText . push ( textArray [ idx ] ) ; if ( italicStart . test ( cText . join ( '' ) ) && openItalic === false ) { // found an italic start, push to array, reset. finalText += cText . join ( '' ) ; cText = [ ] ; openItalic = true ; } else if ( commandBreak . test ( cText . join ( '' ) ) && openItalic === false ) { finalText += cText . join ( '' ) ; cText = [ ] ; openItalic = false ; } else if ( commandBreak . test ( cText . join ( '' ) ) && openItalic === true ) { finalText += cText . join ( '' ) . replace ( commandBreak , '{end-italic}{break}' ) ; cText = [ ] ; openItalic = false ; } else if ( italicStart . test ( cText . join ( '' ) ) && openItalic === true ) { // found an italic start within another italic...prepend an end finalText += cText . join ( '' ) . replace ( italicStart , '' ) ; cText = [ ] ; openItalic = true ; } else if ( italicEnd . test ( cText . join ( '' ) ) && openItalic === true ) { finalText += cText . join ( '' ) ; cText = [ ] ; openItalic = false ; } else if ( italicEnd . test ( cText . join ( '' ) ) && openItalic === false ) { //drop useless end italics that are out of place. finalText += cText . join ( '' ) . replace ( italicEnd , '' ) ; cText = [ ] ; openItalic = false ; } if ( idx === text . length ) { if ( openItalic ) { finalText += cText . join ( '' ) + '{end-italic}' ; } else { finalText += cText . join ( '' ) ; } cText = [ ] ; } } return finalText ; }
fixes italics..
@function
@public
@param {string} text - Translated text
fixes italics ..