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

@andatoshiki/markdown-it-link-to-card

v0.0.1

Published

A markdown-it plugin to convert link to card.

Downloads

4

Readme

@luckrya/markdown-it-link-to-card

A markdown-it plugin for turning page links into link cards (which contain brief information about the link).

  • Extract links with special flags (eg. [text](@:url)) and convert them into card information display.
  • Support for custom renderers to support rendering into anything you want.
  • Support injecting class names for cards to support custom styles.

Install

npm i -D @luckrya/markdown-it-link-to-card

Usage

import MarkdownIt from "markdown-it";
import { linkToCardPlugin } from "@luckrya/markdown-it-link-to-card";
import type { LinkToCardPluginOptions } from "@luckrya/markdown-it-link-to-card";

const md = MarkdownIt({ html: true }).use<LinkToCardPluginOptions>(
  linkToCardPlugin,
  {
    // options
    size: "small",
  }
);

const rendered = md.render(`

# Home

...

### Reference

  - [github](https://github.com)
  - [bing](https://cn.bing.com/)
  - [知乎 - 发现页](https://www.zhihu.com/explore)
  - [markdown-it-link-to-card](https://github.com/luckrya/markdown-it-link-to-card)

<br />

  - [github](@:https://github.com)
  - [bing](@:https://cn.bing.com)
  - [知乎 - 发现页](@:https://www.zhihu.com/explore)
  - [markdown-it-link-to-card](@:https://github.com/luckrya/markdown-it-link-to-card)

`);

Use in vitepress:

// docs/.vitepress/config.ts

import { defineConfig } from "vitepress";
import { linkToCardPlugin } from "@luckrya/markdown-it-link-to-card";
import type { LinkToCardPluginOptions } from "@luckrya/markdown-it-link-to-card";

export default defineConfig({
  // ...

  themeConfig: {
    nav: [{ text: "Home", link: "/index" }],
  },

  markdown: {
    config: (md) => {
      md.use<LinkToCardPluginOptions>(linkToCardPlugin, {
        // options
        size: "small",
      });
    },
  },

  // ...
});

// docs/index.md
// Let's say your home page content is:
`
# Home

...

### Reference

  - [github](https://github.com)
  - [bing](https://cn.bing.com/)
  - [知乎 - 发现页](https://www.zhihu.com/explore)
  - [markdown-it-link-to-card](https://github.com/luckrya/markdown-it-link-to-card)

<br />

  - [github](@:https://github.com)
  - [bing](@:https://cn.bing.com)
  - [知乎 - 发现页](@:https://www.zhihu.com/explore)
  - [markdown-it-link-to-card](@:https://github.com/luckrya/markdown-it-link-to-card)

`;

Rendering results:

Rendering results

Options

tag

  • Type: string

  • Default: @

  • Details:

    Identifier, e.g. [xxx](@:https://github.com)

    Note that a regular expression will be constructed internally to separate characters. If the value provided by tag is a special symbol of the regular expression, be sure to escape it manually.

    e.g. \\$ => [xxx]($:https://github.com)

Size

  • Type: 'small' | 'large'
  • Default: 'small'
  • Details: Card size, only valid in inline style mode.

target

  • Type: '_self' | '_blank' | '_top' | '_parent'
  • Default: '_blank'
  • Details: Link jump behavior. more detail

classPrefix

  • Type: string | undefined

  • Default: undefined

  • Details: Card DOM class name prefix. If this option is set, the inline style will not be injected, but the relevant class name will be injected directly. e.g. the setting value is 'my-docs' will get the following structure

    <span class="my-docs__container">
      <img class="my-docs__img" src="$logo" />
      <span class="my-docs__texts">
        <span class="my-docs__texts--title">$title</span>
        <span class="my-docs__texts--desc">$description</span>
      </span>
    </span>

showTitle

  • Type: boolean
  • Default: true
  • Details: Whether to display the link title. Note that this will be displayed as a tooltip, with the displayed value extracted from [link title](). more detail

render

  • Type: undefined | CardDomRender

    type CardDomRender = (
      data: {
        logo?: string;
        title?: string;
        description?: string;
      },
      options: {
        href: string;
        linkTitle: string;
        showTitle: boolean;
        target: "_self" | "_blank" | "_top" | "_parent";
        size: "small" | "large";
        classPrefix?: string;
      }
    ) => string;
  • Default: undefined

  • Details: Custom Rendering DOM Fragments.

Q/A

How to get url metadata?

Synchronized remote request. why? "All complex parsers are sync by nature.". As the number of card links you write increases, the loading will not become very slow, because it does caching internally.

Does the plugin set up the cache? And how?

Yes, it's set. It will cache all the parsed metadata in the form of local cache instead of in memory! A special file (.linkcardrc) will be created in the working directory of the current execution to store this metadata.

It is not recommended that this file be ignored by Git!

API

import { generateCard } from "@luckrya/markdown-it-link-to-card";

generateCard("https://github.com", {
  linkTitle: "Github Home",
  showTitle: true,
  size: "small",
}).then(({ dom }) => {
  // card dom fragment
  console.log(dom);
});