All Projects → remark-embedder → transformer-oembed

remark-embedder / transformer-oembed

Licence: MIT License
@remark-embedder transformer for oEmbed supported links

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to transformer-oembed

cache
A cache for @remark-embedder
Stars: ✭ 12 (-52%)
Mutual labels:  remark, remark-plugin, remark-embedder
remark-behead
Remark plugin to increase or decrease markdown heading weight.
Stars: ✭ 14 (-44%)
Mutual labels:  remark, remark-plugin
remark-hint
Sprinkle hints/tips/warnings on your documents
Stars: ✭ 36 (+44%)
Mutual labels:  remark, remark-plugin
remark-external-links
Legacy plugin to automatically add target and rel attributes to external links — please use `rehype-external-links` instead
Stars: ✭ 50 (+100%)
Mutual labels:  remark, remark-plugin
remark-embed-images
plugin to embed local images as data URIs
Stars: ✭ 23 (-8%)
Mutual labels:  remark, remark-plugin
strip-markdown
plugin remove Markdown formatting
Stars: ✭ 84 (+236%)
Mutual labels:  remark, remark-plugin
remark-frontmatter
remark plugin to support frontmatter (YAML, TOML, and more)
Stars: ✭ 167 (+568%)
Mutual labels:  remark, remark-plugin
remark-slate-transformer
remark plugin to transform remark syntax tree (mdast) to Slate document tree, and vice versa. Made for WYSIWYG markdown editor.
Stars: ✭ 62 (+148%)
Mutual labels:  remark, remark-plugin
remark-autolink-headings
Legacy remark plugin to automatically add links to headings — please use `rehype-autolink-headings` instead
Stars: ✭ 63 (+152%)
Mutual labels:  remark, remark-plugin
remark-bookmarks
plugin to manage links
Stars: ✭ 15 (-40%)
Mutual labels:  remark, remark-plugin
remark-highlight.js
Legacy plugin to highlight code blocks with highlight.js — please use `rehype-highlight` instead
Stars: ✭ 58 (+132%)
Mutual labels:  remark, remark-plugin
remark-admonitions
Add admonitions support to Remarkable
Stars: ✭ 90 (+260%)
Mutual labels:  remark, remark-plugin
remark-man
plugin to compile markdown to man pages
Stars: ✭ 87 (+248%)
Mutual labels:  remark, remark-plugin
twoslash
You take some Shiki, add a hint of TypeScript compiler, and 🎉 incredible static code samples
Stars: ✭ 596 (+2284%)
Mutual labels:  remark, remark-plugin
remark-directive
remark plugin to support directives
Stars: ✭ 137 (+448%)
Mutual labels:  remark, remark-plugin
remark-footnotes
Legacy plugin to add support for pandoc footnotes — please use `remark-gfm` instead
Stars: ✭ 38 (+52%)
Mutual labels:  remark, remark-plugin
remark-license
plugin to generate a license section
Stars: ✭ 15 (-40%)
Mutual labels:  remark, remark-plugin
myPortfolio
This is a portfolio application built by using Next.js, ChakraUi, Typescript and Dev.to api.
Stars: ✭ 127 (+408%)
Mutual labels:  remark
oembed
A simple plugin to extract media information from websites, like youtube videos, twitter statuses or blog articles.
Stars: ✭ 34 (+36%)
Mutual labels:  oembed
oembed
PHP OEmbed wrapper for well-known video platforms and services
Stars: ✭ 26 (+4%)
Mutual labels:  oembed

@remark-embedder/transformer-oembed

@remark-embedder transformer for oEmbed supported links


Build Status Code Coverage version downloads MIT License All Contributors PRs Welcome Code of Conduct

The problem

You're using @remark-embedder/core to automatically convert URLs in your markdown to the embedded version of those URLs and want to have a transform for providers that support an oEmbed API. Learn more about oEmbed from oembed.com

This solution

This is a @remark-embedder transform for supported oembed API providers. Find the list of supported providers on oembed.com.

Table of Contents

Installation

This module is distributed via npm which is bundled with node and should be installed as one of your project's dependencies:

npm install @remark-embedder/transformer-oembed

Usage

import remarkEmbedder from '@remark-embedder/core'
import oembedTransformer from '@remark-embedder/transformer-oembed'
// or, if you're using CommonJS require:
// const {default: oembedTransformer} = require('@remark-embedder/transformer-oembed')
import remark from 'remark'
import html from 'remark-html'

const exampleMarkdown = `
# My favorite YouTube video

[This](https://www.youtube.com/watch?v=dQw4w9WgXcQ) is a great YouTube video.
Watch it here:

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

Isn't it great!?
`

async function go() {
  const result = await remark()
    .use(remarkEmbedder, {
      transformers: [oembedTransformer],
    })
    .use(html)
    .process(exampleMarkdown)

  console.log(result.toString())
}

go()

This will result in:

<h1>My favorite YouTube video</h1>
<p>
  <a href="https://www.youtube.com/watch?v=dQw4w9WgXcQ">This</a> is a great
  YouTube video. Watch it here:
</p>
<iframe
  width="200"
  height="113"
  src="https://www.youtube.com/embed/dQw4w9WgXcQ?feature=oembed"
  frameborder="0"
  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
  allowfullscreen
></iframe>
<p>Isn't it great!?</p>

Config

Some oembed providers offer special configuration via query parameters. You can provide those via config:

// ...
import type {Config} from '@remark-embedder/transformer-oembed'

// ...

async function go() {
  const result = await remark()
    .use(remarkEmbedder, {
      transformers: [
        [
          oembedTransformer,
          {params: {theme: 'dark', dnt: true, omit_script: true}} as Config,
        ],
      ],
    })
    .use(html)
    .process(`https://twitter.com/kentcdodds/status/783161196945944580`)

  console.log(result.toString())
}

// ...

That results in (notice the data- attributes which are specific to twitter's oEmbed API):

<blockquote class="twitter-tweet" data-dnt="true" data-theme="dark">
  <p lang="en" dir="ltr">
    I spent a few minutes working on this, just for you all. I promise, it wont
    disappoint. Though it may surprise 🎉<br /><br />🙏
    <a href="https://t.co/wgTJYYHOzD">https://t.co/wgTJYYHOzD</a>
  </p>
  — Kent C. Dodds (@kentcdodds)
  <a
    href="https://twitter.com/kentcdodds/status/783161196945944580?ref_src=twsrc%5Etfw"
    >October 4, 2016</a
  >
</blockquote>

This could also be used to provide an access token for providers that require this (like Instagram).

Config as a function

You can also provide configuration as a function so you can determine what configuration to give based on the provider and/or the URL. Like so:

const oembedConfig: Config = ({url, provider}) => {
  if (provider.provider_name === 'Instagram') {
    return {
      params: {access_token: '{app-id}|{client-token}'},
    }
  }
}
const remarkEmbedderConfig = {
  transformers: [[oembedTransformer, oembedConfig]],
}
// ... etc...

Inspiration

It's a long story... Check out the inspiration on @remark-embedder/core

Other Solutions

  • remark-oembed: This one requires client-side JS to work which was unacceptable for our use cases.

Issues

Looking to contribute? Look for the Good First Issue label.

🐛 Bugs

Please file an issue for bugs, missing documentation, or unexpected behavior.

See Bugs

💡 Feature Requests

Please file an issue to suggest new features. Vote on feature requests by adding a 👍. This helps maintainers prioritize what to work on.

See Feature Requests

Contributors

Thanks goes to these people (emoji key):


Kent C. Dodds

💻 📖 🚇 ⚠️

Michaël De Boey

💻 📖 🚧

This project follows the all-contributors specification. Contributions of any kind welcome!

LICENSE

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].