lib/ttml.js
function(data) {
        var TTML_BODY = '',
            index = 0,
            splitText,
            captions = data;

        TTML_BODY += TTML.header.join('\n') + '\n';
        captions.forEach(function(caption) {
            if (caption.text.length > 0 && validateText(caption.text)) {
                if ((/&/.test(caption.text)) && !(/&amp;/.test(caption.text))) {
                    caption.text = caption.text.replace(/&/g, '&amp;');
                }
                if ((/</.test(caption.text)) && !(/&lt;/.test(caption.text))) {
                    caption.text = caption.text.replace(/</g, '&lt;');
                }
                if ((/>/.test(caption.text)) && !(/&gt;/.test(caption.text))) {
                    caption.text = caption.text.replace(/>/g, '&gt;');
                }
                if (/\{break\}/.test(caption.text)) {
                    splitText = caption.text.split('{break}');
                    //TODO this should count for number of breaks and add the appropriate pops where needed.
                    for (index = 0; index < splitText.length; index++) {
                        TTML_BODY += TTML.lineTemplate.replace('{region}', 'pop' + (index + 1))
                            .replace('{startTime}', module.exports.formatTime(caption.startTimeMicro))
                            .replace('{endTime}', module.exports.formatTime(caption.endTimeMicro))
                            .replace('{text}', module.exports.renderMacros(macros.fixItalics(macros.cleanMacros(splitText[index])))) + '\n';
                    }
                } else {
                    TTML_BODY += TTML.lineTemplate.replace('{region}', 'pop1')
                        .replace('{startTime}', module.exports.formatTime(caption.startTimeMicro))
                        .replace('{endTime}', module.exports.formatTime(caption.endTimeMicro))
                        .replace('{text}', module.exports.renderMacros(macros.fixItalics(macros.cleanMacros(caption.text)))) + '\n';
                }
            }
        });

        return TTML_BODY + TTML.footer.join('\n') + '\n';
    }
function(data) {
        var TTML_BODY = '',
            index = 0,
            splitText,
            captions = data;

        TTML_BODY += TTML.header.join('\n') + '\n';
        captions.forEach(function(caption) {
            if (caption.text.length > 0 && validateText(caption.text)) {
                if ((/&/.test(caption.text)) && !(/&amp;/.test(caption.text))) {
                    caption.text = caption.text.replace(/&/g, '&amp;');
                }
                if ((/</.test(caption.text)) && !(/&lt;/.test(caption.text))) {
                    caption.text = caption.text.replace(/</g, '&lt;');
                }
                if ((/>/.test(caption.text)) && !(/&gt;/.test(caption.text))) {
                    caption.text = caption.text.replace(/>/g, '&gt;');
                }
                if (/\{break\}/.test(caption.text)) {
                    splitText = caption.text.split('{break}');
                    //TODO this should count for number of breaks and add the appropriate pops where needed.
                    for (index = 0; index < splitText.length; index++) {
                        TTML_BODY += TTML.lineTemplate.replace('{region}', 'pop' + (index + 1))
                            .replace('{startTime}', module.exports.formatTime(caption.startTimeMicro))
                            .replace('{endTime}', module.exports.formatTime(caption.endTimeMicro))
                            .replace('{text}', module.exports.renderMacros(macros.fixItalics(macros.cleanMacros(splitText[index])))) + '\n';
                    }
                } else {
                    TTML_BODY += TTML.lineTemplate.replace('{region}', 'pop1')
                        .replace('{startTime}', module.exports.formatTime(caption.startTimeMicro))
                        .replace('{endTime}', module.exports.formatTime(caption.endTimeMicro))
                        .replace('{text}', module.exports.renderMacros(macros.fixItalics(macros.cleanMacros(caption.text)))) + '\n';
                }
            }
        });

        return TTML_BODY + TTML.footer.join('\n') + '\n';
    }
function ( data ) { var TTML_BODY = '' , index = 0 , splitText , captions = data ; TTML_BODY += TTML . header . join ( '\n' ) + '\n' ; captions . forEach ( function ( caption ) { if ( caption . text . length > 0 && validateText ( caption . text ) ) { if ( ( / & / . test ( caption . text ) ) && ! ( / &amp; / . test ( caption . text ) ) ) { caption . text = caption . text . replace ( / & / g , '&amp;' ) ; } if ( ( / < / . test ( caption . text ) ) && ! ( / &lt; / . test ( caption . text ) ) ) { caption . text = caption . text . replace ( / < / g , '&lt;' ) ; } if ( ( / > / . test ( caption . text ) ) && ! ( / &gt; / . test ( caption . text ) ) ) { caption . text = caption . text . replace ( / > / g , '&gt;' ) ; } if ( / \{break\} / . test ( caption . text ) ) { splitText = caption . text . split ( '{break}' ) ; //TODO this should count for number of breaks and add the appropriate pops where needed. for ( index = 0 ; index < splitText . length ; index ++ ) { TTML_BODY += TTML . lineTemplate . replace ( '{region}' , 'pop' + ( index + 1 ) ) . replace ( '{startTime}' , module . exports . formatTime ( caption . startTimeMicro ) ) . replace ( '{endTime}' , module . exports . formatTime ( caption . endTimeMicro ) ) . replace ( '{text}' , module . exports . renderMacros ( macros . fixItalics ( macros . cleanMacros ( splitText [ index ] ) ) ) ) + '\n' ; } } else { TTML_BODY += TTML . lineTemplate . replace ( '{region}' , 'pop1' ) . replace ( '{startTime}' , module . exports . formatTime ( caption . startTimeMicro ) ) . replace ( '{endTime}' , module . exports . formatTime ( caption . endTimeMicro ) ) . replace ( '{text}' , module . exports . renderMacros ( macros . fixItalics ( macros . cleanMacros ( caption . text ) ) ) ) + '\n' ; } } } ) ; return TTML_BODY + TTML . footer . join ( '\n' ) + '\n' ; }
generates TTML from JSON
@function
@param {array} data - JSON array of captions
@public
generates TTML from JSON