Skip to content

Convert URLs in markdown for youtube, twitter, etc. surrounded by newlines into html embeds

License

Notifications You must be signed in to change notification settings

agentofuser/remark-oembed

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

remark-oembed

Downloads Chat

Converts URLs surrounded by newlines into embeds.

The important part of this code is taken directly from Benedicte Raae's excellent gatsby-remark-oembed plugin, so thank you very much @raae 🙏

Installation

yarn:

yarn add @agentofuser/remark-oembed

Usage

Say we have the following file, demo.md:

Hey this is a nice youtube video about making modern react apps with gatsby:

https://www.youtube.com/watch?v=GN0xHSk2P8Q

Check it out 👆

And our script, example.js, looks as follows:

var fs = require('fs')
var remark = require('remark')
var oembed = require('@agentofuser/remark-oembed')

remark()
  .use(oembed)
  .process(fs.readFileSync('demo.md'), function(err, file) {
    if (err) throw err
    console.log(String(file))
  })

Now, running node example yields:

Hey this is a nice youtube video about making modern react apps with gatsby:

<iframe 
  width="480" 
  height="270" 
  src="https://www.youtube.com/embed/GN0xHSk2P8Q?feature=oembed" 
  frameborder="0" 
  allow="accelerometer; 
    autoplay; 
    encrypted-media; 
    gyroscope; 
    picture-in-picture" 
  allowfullscreen>
</iframe>

Check it out 👆

API

remark().use(oembed)

Converts URLs surrounded by newlines into embeds.

Contribute

See contributing.md in remarkjs/remark for ways to get started.

This organisation has a Code of Conduct. By interacting with this repository, organisation, or community you agree to abide by its terms.

License

MIT © Agent of User

About

Convert URLs in markdown for youtube, twitter, etc. surrounded by newlines into html embeds

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •