From 012e29630fa0bddfd49faf97caf84585109e07ad Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sun, 29 Dec 2024 13:53:25 -0400 Subject: replacer, content, css: videos in content text --- src/content/dependencies/transformContent.js | 56 +++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 9 deletions(-) (limited to 'src/content') diff --git a/src/content/dependencies/transformContent.js b/src/content/dependencies/transformContent.js index 3d9fdd60..48e20f94 100644 --- a/src/content/dependencies/transformContent.js +++ b/src/content/dependencies/transformContent.js @@ -362,6 +362,41 @@ export default { }; } + case 'video': { + const src = + (node.src.startsWith('media/') + ? to('media.path', node.src.slice('media/'.length)) + : node.src); + + const { + width, + height, + align, + pixelate, + } = node; + + const content = + html.tag('div', {class: 'content-video-container'}, + html.tag('video', + src && {src}, + width && {width}, + height && {height}, + + {controls: true}, + + align === 'center' && + {class: 'align-center'}, + + pixelate && + {class: 'pixelate'})); + + return { + type: 'processed-video', + data: + content, + }; + } + case 'internal-link': { const nodeFromRelations = relations.internalLinks[internalLinkIndex++]; if (nodeFromRelations.type === 'text') { @@ -541,15 +576,18 @@ export default { const attributes = html.parseAttributes(match[1]); - // Images that were all on their own line need to be removed from - // the surrounding

tag that marked generates. The HTML parser - // treats a

that starts inside a

as a Crocker-class - // misgiving, and will treat you very badly if you feed it that. - if (attributes.get('data-type') === 'processed-image') { - if (!attributes.get('data-inline')) { - tags[tags.length - 1] = tags[tags.length - 1].replace(/

$/, ''); - deleteParagraph = true; - } + // Images (or videos) that were all on their own line need to be + // removed from the surrounding

tag that marked generates. + // The HTML parser treats a

that starts inside a

as a + // Crocker-class misgiving, and will treat you very badly if you + // feed it that. + if ( + (attributes.get('data-type') === 'processed-image' && + !attributes.get('data-inline')) || + attributes.get('data-type') === 'processed-video' + ) { + tags[tags.length - 1] = tags[tags.length - 1].replace(/

$/, ''); + deleteParagraph = true; } const nonTextNodeIndex = match[2]; -- cgit 1.3.0-6-gf8a5