Skip to content

Commit

Permalink
feat: Support parsing video element with inner source element
Browse files Browse the repository at this point in the history
  • Loading branch information
ericof committed Dec 20, 2021
1 parent 533207e commit b1baa76
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/converters/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@ const iframeBlock = (elem) => {
};

const videoBlock = (elem) => {
const src = elem.src;
let src = elem.src;
if (src === '') {
// If src is empty search for the first source element
const child = elem.firstElementChild;
if (child.tagName === 'SOURCE') {
src = child.src;
}
}
const youtubeId = getYTVideoId(src);
const block = {
'@type': 'video',
Expand Down
9 changes: 9 additions & 0 deletions src/converters/blocks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ describe('videoBlock processing', () => {
expect(result['@type']).toBe('video');
expect(result['url']).toBe('https://youtu.be/jn4zGVJq9m0');
});

test('External video (Youtube) from source element', () => {
const elem = elementFromString(
'<video width="170" height="85"><source src="https://youtu.be/47BC9R2vD2w"></video>',
);
const result = videoBlock(elem);
expect(result['@type']).toBe('video');
expect(result['url']).toBe('https://youtu.be/47BC9R2vD2w');
});
});

describe('imageBlock processing', () => {
Expand Down

0 comments on commit b1baa76

Please sign in to comment.