How to replace all the youtube urls from a textarea with the html returned from the oEmbed?

To embed a video or another object into a post or page on WordPress, place the URLs into the content area. Make sure the URL is on its own line and not hyperlinked (clickable when viewing the post).

WordPress will automatically turn the URL into a YouTube embed and provide a live preview in the visual editor.

How can I do the same on a meteor app using javascript?

Thanks.

This is not really a Meteor question, but this might be a direction in pure js (no react etc).

const linesWithUrl = textArea.value.split('\n');
const embeddedVideos = linesWithUrl.map(url => (
  return ` <iframe width="560" height="315" src="${url}" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>`;
));


1 Like