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, '
\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*(
'; });
// 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 + '
');
}
/**
* @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 = '';
return out;
}
Formatter.applyVideoPressFormattingCallback = function(match) {
if (match.attrs.numeric.length == 0) {
return match.content;
}
var videopressID = match.attrs.numeric[0];
var posterSVG = '"svg/wpposter.svg"';
// 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 video is tapped.
var out = '';
// Wrap video in edit-container node for a permanent delete button overlay
var containerStart = '';
out = containerStart + out + '';
return out;
}
Formatter.applyVideoFormattingCallback = function(match) {
// Find the tag containing the video source
var srcTag = "";
if (match.attrs.named['src']) {
srcTag = "src";
} else {
for (var i = 0; i < Formatter.videoShortcodeFormats.length; i++) {
var format = Formatter.videoShortcodeFormats[i];
if (match.attrs.named[format]) {
srcTag = format;
break;
}
}
}
if (srcTag.length == 0) {
return match.content;
}
var out = '';
// Wrap video in edit-container node for a permanent delete button overlay
var containerStart = '';
out = containerStart + out + '';
return out;
}
if (typeof module !== 'undefined' && module.exports != null) {
exports.Formatter = Formatter;
}