diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2025-06-15 14:10:35 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2025-06-15 14:10:35 -0300 |
commit | f66cc7266324ac07d2a952e922aba6453396670f (patch) | |
tree | ede90f1ecf8e0b0a5db1e0c2142e16cd5e775b2e | |
parent | 01dbc3af291fcba1dac42f2e73950750cba1dd81 (diff) |
replacer: complain about /media/
-rw-r--r-- | src/replacer.js | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/replacer.js b/src/replacer.js index 9d6fd191..c6aef6ef 100644 --- a/src/replacer.js +++ b/src/replacer.js @@ -635,16 +635,23 @@ function postprocessHTMLTags(inputNodes, tagName, callback) { return outputNodes; } +function complainAboutMediaSrc(src) { + if (!src) { + throw new Error(`Missing "src" attribute`); + } + + if (src.startsWith('/media/')) { + throw new Error(`Start "src" with "media/", not "/media/"`); + } +} + export function postprocessImages(inputNodes) { return postprocessHTMLTags(inputNodes, 'img', (attributes, {inline}) => { const node = {type: 'image'}; node.src = attributes.get('src'); - - if (!node.src) { - throw new Error('<img> missing src attribute'); - } + complainAboutMediaSrc(node.src); node.inline = attributes.get('inline') ?? inline; @@ -670,10 +677,7 @@ export function postprocessVideos(inputNodes) { const node = {type: 'video'}; node.src = attributes.get('src'); - - if (!node.src) { - throw new Error('<video> missing src attribute'); - } + complainAboutMediaSrc(node.src); if (attributes.get('width')) node.width = parseInt(attributes.get('width')); if (attributes.get('height')) node.height = parseInt(attributes.get('height')); @@ -690,10 +694,7 @@ export function postprocessAudios(inputNodes) { const node = {type: 'audio'}; node.src = attributes.get('src'); - - if (!node.src) { - throw new Error('<audio> missing src attribute'); - } + complainAboutMediaSrc(node.src); node.inline = attributes.get('inline') ?? inline; |