diff options
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/external-links.js | 8 | ||||
-rw-r--r-- | src/util/replacer.js | 51 | ||||
-rw-r--r-- | src/util/sugar.js | 15 |
3 files changed, 70 insertions, 4 deletions
diff --git a/src/util/external-links.js b/src/util/external-links.js index f84b5c15..43c09265 100644 --- a/src/util/external-links.js +++ b/src/util/external-links.js @@ -353,6 +353,14 @@ export const externalLinkSpec = [ }, { + match: {domain: 'm.nintendo.com'}, + + platform: 'nintendoMusic', + + icon: 'nintendoMusic', + }, + + { match: {domain: 'mspaintadventures.fandom.com'}, platform: 'fandom.mspaintadventures', 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); diff --git a/src/util/sugar.js b/src/util/sugar.js index a0c1ed62..7dd173a0 100644 --- a/src/util/sugar.js +++ b/src/util/sugar.js @@ -48,15 +48,22 @@ export function empty(value) { // Repeats all the items of an array a number of times. export function repeat(times, array) { - if (typeof array === 'string') return repeat(times, [array]); - if (empty(array)) return []; if (times === 0) return []; - if (times === 1) return array.slice(); + if (array === null || array === undefined) return []; + if (Array.isArray(array) && empty(array)) return []; const out = []; + for (let n = 1; n <= times; n++) { - out.push(...array); + const value = + (typeof array === 'function' + ? array() + : array); + + if (Array.isArray(value)) out.push(...value); + else out.push(value); } + return out; } |