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

markdown-it-internal-link

v1.0.4

Published

Internal links plugin for markdown-it markdown parser.

Downloads

16

Readme

markdown-it-internal-link

npm version pipeline status coverage report

Internal links plugin for markdown-it markdown parser.

Use this plugin to parse and render [[internal links]] (also called wikilinks or roamlinks).

Install

Node:

npm install --save markdown-it-internal-link

Usage

Node:

const md = require("markdown-it")();
const markdownItInternalLink = require("markdown-it-internal-link");

md.use(markdownItInternalLink, options);

Browser:

<script src="https://unpkg.com/markdown-it-internal-link@1/dist/index.umd.js"></script>
const md = window.markdownit();

md.use(window.markdownItInternalLink, options);

By default, all [[bracketed]] links are converted to <a href="bracketed">bracketed</a>. To override this behavior, specify the options parameter as either an object or a function.

Options

If options is an object, the plugin uses its properties to make the HTML attributes of the <a> element, except options.text used for the inner text. All the properties can be given as strings, or functions ((content: string, env: any) => string) called for each link. The content argument is a string corresponding to the text inside double-brackets. The env argument is the environment object passed to markdown-it before rendering.

Example:

md.use(markdownItInternalLink, {
    // add a class attribute
    class: "my-link",

    // add a title attribute
    title: "click me",

    // override the inner text
    text: (content) => content.toUpperCase()
});

md.render("[[foo]]");
// => `<a class="my-link" href="foo" title="click me">FOO</a>`

If options is a function, it must have the signature (content: string, env: any) => (object | string). This function is called for each link. It can return an object with a structure similar to the previous example. For example, how to render wikilinks with optional label (piped links):

// Render wikilinks with optional label
md.use(markdownItInternalLink, (content) => {
    // search for the pipe character
    const pos = content.indexOf("|");

    return {
        // add a class attribute
        class: "wikilink",

        // override the href attribute
        href: pos === -1 ? content : content.substring(0, pos),

        // override the inner text
        text: pos === -1 ? content : content.substring(pos + 1)
    };
});

md.render("[[foo]]"); // => `<a class="wikilink" href="foo">foo</a>`

md.render("[[foo|bar]]"); // => `<a class="wikilink" href="foo">bar</a>`

To fully control the rendering, the function can return a string instead. The following example converts internal links to <button> elements:

// Render buttons
md.use(markdownItInternalLink, (content) => `<button>${content}</button>`);

md.render("[[foo]]"); // => `<button>foo</button>`

One can also use the env parameter to specify a per-render context. The following example collects all the internal links of the document:

md.use(markdownItInternalLink, (content, env) =>
    env.internalLinks.push(content)
);

const env = { internalLinks: [] };

md.render("[[foo]] and [[bar]]", env);
// => `<a href="foo">foo</a> and <a href="bar">bar</a>`

console.log(env.internalLinks); // => ["foo", "bar"]

Contributing

Contributions are welcome. When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.

License

This software is licensed under the MIT license. Please see the LICENSE file for further information.