@mintlify/common
Version:
Commonly shared code within Mintlify
26 lines (25 loc) • 1.31 kB
JavaScript
import { visit } from 'unist-util-visit';
import { createMdxJsxAttribute } from '../../lib/remark-utils.js';
export const remarkVideo = () => {
return (tree) => {
visit(tree, 'mdxJsxFlowElement', (node) => {
if (node.name === 'video') {
const hasAutoPlay = node.attributes.some((attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'autoPlay');
if (hasAutoPlay) {
const hasPlaysInline = node.attributes.some((attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'playsInline');
const hasLoop = node.attributes.some((attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'loop');
const hasMuted = node.attributes.some((attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'muted');
if (!hasPlaysInline) {
node.attributes.push(createMdxJsxAttribute('playsInline', true));
}
if (!hasLoop) {
node.attributes.push(createMdxJsxAttribute('loop', true));
}
if (!hasMuted) {
node.attributes.push(createMdxJsxAttribute('muted', true));
}
}
}
});
};
};