npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@r4ai/remark-embed

v0.3.1

Published

[![JSR](https://jsr.io/badges/@r4ai/remark-embed)](https://jsr.io/@r4ai/remark-embed) [![codecov](https://codecov.io/gh/r4ai/remark-embed/graph/badge.svg?token=B9EZXC0PR8)](https://codecov.io/gh/r4ai/remark-embed) [![CI](https://github.com/r4ai/remark-emb

Downloads

234

Readme

@r4ai/remark-embed

JSR codecov CI Version or Publish CodeQL

A remark plugin to embed the content of the URL.

Features

About this plugin

This plugin rewrite a paragraph containing only a URL, such as the following, into any element through the transformer.

https://example.com/hoge

[!note] Note that URLs such as the following will not be converted:

  • according to https://example.com/hoge
  • [example](https://example.com/hoge)

URL must be the only content in the paragraph.

Also, if there is no blank line before and after the paragraph, it will not be converted.

Transformer

Currently, this plugin provides the following transformers:

You can also define your own transformer. Please refer to the transformer in the ./src/transformers directory for details on how to define them.

Following is the algorithm of how this plugin will apply the transformers.

  1. let elements be a list of link nodes such that each node's parent paragraph contains only one link
    Example: elements = [{ type: 'link', url: 'https://example.com/hoge' }]
  2. for each element of elements, do the following in parallel:
    1. let url be the element's url value.
    2. for each transformer of transformers, do the following in sequence:
      1. if transformer.match(url) is true:
        1. replace the element's tag name with the result of transformer.tagName(url)
        2. replace the element's properties with the result of transformer.properties(url)
        3. replace the element's children with the result of transformer.children(url)

Installation

  • Bun:

    bun add @r4ai/remark-embed
  • Deno:

    deno add @r4ai/remark-embed
  • NPM:

    npm install @r4ai/remark-embed
  • PNPM:

    pnpm add @r4ai/remark-embed
  • Yarn:

    yarn add @r4ai/remark-embed

Usage

import rehypeStringify from "rehype-stringify";
import remarkParse from "remark-parse";
import remarkRehype from "remark-rehype";
import { unified } from "unified";
import remarkEmbed from "@r4ai/remark-embed";
import { transformerOEmbed } from "@r4ai/remark-embed/transformers";

const md = `
<https://www.youtube.com/watch?v=jNQXAC9IVRw>
`;

const html = (
  await unified()
    .use(remarkParse)
    .use(remarkRehype)
    .use(remarkEmbed, {
      transformers: [transformerOEmbed()],
    })
    .use(rehypeStringify)
    .process(md)
).toString();

console.log(html);

Yields:

<p>
  <div class="oembed oembed-video">
    <iframe
      width="200"
      height="150"
      src="https://www.youtube.com/embed/jNQXAC9IVRw?feature=oembed"
      frameborder="0"
      allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
      referrerpolicy="strict-origin-when-cross-origin"
      allowfullscreen
      title="Me at the zoo">
    </iframe>
  </div>
</p>

Documentation

See: https://jsr.io/@r4ai/remark-embed/doc