GithubHelp home page GithubHelp logo

konsumer / rehype-oembed Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 253 KB

Rehype plugin for adding rich embeds when a link on it's own line is encountered.

Home Page: http://konsumer.js.org/rehype-oembed/

JavaScript 100.00%

rehype-oembed's Introduction

rehype-oembed

This is a rehype plugin to embed many types of media in HTML (replacing links.)

WIP

This is not finished yet, and likely will be renamed. Please check back.

Plugin that does similar to gatsby-rehype-oembed, but works with remark, in general, as well as Gatsby, and has more supported formats.

usage

Install:

npm i @konsumer/rehype-oembed

In markdown, put your media-link on a line of it's own:

https://twitter.com/Chhapiness/status/1422326068917284869?s=20

In HTML, put a link alone inside a <p>, and make sure the href is the same as the text in the link:

<p>
  <a href="https://www.youtube.com/watch?v=K-281doxOMc">https://www.youtube.com/watch?v=K-281doxOMc</a>
</p>

Here is an example of parsing a markdown file to HTML, and adding the embeds:

import oembed from '@konsumer/rehype-oembed'
import { promises as fs } from 'fs'
import { reporter } from 'vfile-reporter'
import { unified } from 'unified'
import remarkParse from 'remark-parse'
import remarkGfm from 'remark-gfm'
import remarkRehype from 'remark-rehype'
import remarkStringify from 'rehype-stringify'

const markdownToHtml = async file => unified()
  .use(remarkParse)
  .use(remarkRehype)
  .use(remarkGfm)
  .use(oembed)
  .use(remarkStringify)
  .process(await fs.readFile(file))

markdownToHtml()
  .then(console.log)

thanks

rehype-oembed's People

Contributors

konsumer avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.