function Formatter () {} // Video format tags supported by the [video] shortcode: https://codex.wordpress.org/Video_Shortcode // mp4, m4v and webm prioritized since they're supported by the stock player as of Android API 23 Formatter.videoShortcodeFormats = ["mp4", "m4v", "webm", "ogv", "wmv", "flv"]; Formatter.htmlToVisual = function(html) { var mutatedHTML = wp.loadText(html); // Perform extra transformations to properly wrap captioned images in paragraphs mutatedHTML = mutatedHTML.replace(/^\[caption([^\]]*\])/igm, '

[caption$1'); mutatedHTML = mutatedHTML.replace(/([^\n>])\[caption/igm, '$1
\n[caption'); mutatedHTML = mutatedHTML.replace(/\[\/caption\]\n(?=<|$)/igm, '[/caption]

\n'); mutatedHTML = mutatedHTML.replace(/\[\/caption\]\n(?=[^<])/igm, '[/caption]
\n'); return Formatter.applyVisualFormatting(mutatedHTML); } Formatter.convertPToDiv = function(html) { // Replace the paragraph tags we get from wpload with divs var mutatedHTML = html.replace(/(\s]))/igm, '/igm, ''); // Replace break tags around media items with paragraphs // The break tags appear when text and media are separated by only a line break rather than a paragraph break, // which can happen when inserting media inline and switching to HTML mode and back, or by deleting line breaks // in HTML mode mutatedHTML = mutatedHTML.replace(/
(?=\s*(
'); mutatedHTML = mutatedHTML.replace(/(]*>|<\/a>|<\/label>|<\/video>|<\/span>)
/igm, function replaceBrWithDivs(match) { return match.substr(0, match.length - 6) + '
'; }); // Append paragraph-wrapped break tag under media at the end of a post mutatedHTML = mutatedHTML.replace(/(]*>|<\/a>|<\/label>|<\/video>|<\/span>)[^<>]*<\/div>\s$/igm, function replaceBrWithDivs(match) { return match + '

'; }); return mutatedHTML; } Formatter.visualToHtml = function(html) { return wp.saveText(html); return Formatter.removeVisualFormatting(mutatedHTML); } Formatter.convertDivToP = function(html) { return html.replace(/(\s]))/igm, '/igm, '

'); } /** * @brief Applies editor specific visual formatting. * * @param html The markup to format * * @return Returns the string with the visual formatting applied. */ Formatter.applyVisualFormatting = function(html) { var str = wp.shortcode.replace('caption', html, Formatter.applyCaptionFormatting); str = wp.shortcode.replace('wpvideo', str, Formatter.applyVideoPressFormattingCallback); str = wp.shortcode.replace('video', str, Formatter.applyVideoFormattingCallback); // More tag str = str.replace(//igm, "
") str = str.replace(//igm, "
") return str; } /** * @brief Adds visual formatting to a caption shortcodes. * * @param html The markup containing caption shortcodes to process. * * @return The html with caption shortcodes replaced with editor specific markup. * See shortcode.js::next or details */ Formatter.applyCaptionFormatting = function(match) { var attrs = match.attrs.named; // The empty 'onclick' is important. It prevents the cursor jumping to the end // of the content body when `-webkit-user-select: none` is set and the caption is tapped. var out = '