1.0.21 • Published 1 year ago

@hongvanpc10/rehype-embed v1.0.21

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@hongvanpc10/rehype-embed

Add improved video syntax: support embeds videos from youtube links.

Installation

This package is ESM only: Node 12+ is needed to use it and it must be import instead of require.

npm install @hongvanpc10/rehype-embed

Or

yarn add @hongvanpc10/rehype-embed

Usage

import { unified } from 'unified'
import remark2rehype from 'remark-rehype'
import remarkParse from 'remark-parse'
import rehypeEmbed from '@hongvanpc10/rehype-embed'
import stringify from 'rehype-stringify'

const string = `{@embed:https://www.youtube.com/watch?v=xsI0j3pO7vc}`

const htmlStr = unified()
  .use(remarkParse)
  .use(remark2rehype)
  .use(rehypeEmbed)
  .use(stringify)
  .processSync(string)
  .toString()

Output:

<p>
  <iframe
    src="https://www.youtube.com/embed/xsI0j3pO7vc"
    style="width: 100%; aspect-ratio: 16 / 9; border-radius: 0.75rem"
    frameborder="0"
    allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
    allowfullscreen=""
  ></iframe>
</p>

Custom Style

const string = `{@embed:https://www.youtube.com/watch?v=xsI0j3pO7vc}`
const htmlStr = unified()
  .use(remarkParse)
  .use(remark2rehype)
  .use(rehypeEmbed, {
    style: 'width: 100%; aspect-ratio: 16 / 9; border-radius: 20px;',
    class: 'iframe'
  })
  .use(stringify)
  .processSync(string)
  .toString()

Output:

<p>
  <iframe
    src="https://www.youtube.com/embed/xsI0j3pO7vc"
    style="width: 100%; aspect-ratio: 16 / 9; border-radius: 20px"
    class="iframe"
    frameborder="0"
    allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
    allowfullscreen=""
  ></iframe>
</p>

Options

OptionTypeDefault
stylestring'width: 100%; aspect-ratio: 16 / 9; border-radius: 0.75rem'
allowstring'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share'
allowfullscreenbooleantrue
classstring

License

MIT © Hong Van

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.11

1 year ago

1.0.21

1 year ago

1.0.10

1 year ago

1.0.20

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago