diff options
Diffstat (limited to 'src/util/replacer.js')
-rw-r--r-- | src/util/replacer.js | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/src/util/replacer.js b/src/util/replacer.js index 678933f2..e3f5623e 100644 --- a/src/util/replacer.js +++ b/src/util/replacer.js @@ -428,7 +428,7 @@ export function squashBackslashes(text) { // a set of characters where the backslash carries meaning // into later formatting (i.e. markdown). Note that we do // NOT compress double backslashes into single backslashes. - return text.replace(/([^\\](?:\\{2})*)\\(?![\\*_~-])/g, '$1'); + return text.replace(/([^\\](?:\\{2})*)\\(?![\\*_~>-])/g, '$1'); } export function restoreRawHTMLTags(text) { @@ -599,6 +599,56 @@ export function postprocessImages(inputNodes) { return outputNodes; } +export function postprocessVideos(inputNodes) { + const outputNodes = []; + + for (const node of inputNodes) { + if (node.type !== 'text') { + outputNodes.push(node); + continue; + } + + const videoRegexp = /<video (.*?)>(<\/video>)?/g; + + let match = null, parseFrom = 0; + while (match = videoRegexp.exec(node.data)) { + const previousText = node.data.slice(parseFrom, match.index); + + outputNodes.push({ + type: 'text', + data: previousText, + i: node.i + parseFrom, + iEnd: node.i + parseFrom + match.index, + }); + + parseFrom = match.index + match[0].length; + + const videoNode = {type: 'video'}; + const attributes = html.parseAttributes(match[1]); + + videoNode.src = attributes.get('src'); + + if (attributes.get('width')) videoNode.width = parseInt(attributes.get('width')); + if (attributes.get('height')) videoNode.height = parseInt(attributes.get('height')); + if (attributes.get('align')) videoNode.align = attributes.get('align'); + if (attributes.get('pixelate')) videoNode.pixelate = true; + + outputNodes.push(videoNode); + } + + if (parseFrom !== node.data.length) { + outputNodes.push({ + type: 'text', + data: node.data.slice(parseFrom), + i: node.i + parseFrom, + iEnd: node.iEnd, + }); + } + } + + return outputNodes; +} + export function postprocessHeadings(inputNodes) { const outputNodes = []; @@ -760,6 +810,7 @@ export function parseInput(input) { let output = parseNodes(input, 0); output = postprocessComments(output); output = postprocessImages(output); + output = postprocessVideos(output); output = postprocessHeadings(output); output = postprocessSummaries(output); output = postprocessExternalLinks(output); |