diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-12-29 13:53:25 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-12-29 13:53:25 -0400 |
commit | 012e29630fa0bddfd49faf97caf84585109e07ad (patch) | |
tree | 6528fe11ea7ef133385a8a4573c8d858eae1ab4c /src/util/replacer.js | |
parent | e23d54ab78cb38f90ed9f667759f986792aceb86 (diff) |
replacer, content, css: videos in content text
Diffstat (limited to 'src/util/replacer.js')
-rw-r--r-- | src/util/replacer.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/util/replacer.js b/src/util/replacer.js index 78b4a895..e3f5623e 100644 --- a/src/util/replacer.js +++ b/src/util/replacer.js @@ -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); |