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

@kasisoft/remark-autolinker

v0.2.0

Published

Automatically generate links within markdown files based upon a predefined configuration.

Downloads

76

Readme

remark-autolinker

Build StandWithUkraine

Contents

What is this?

This plugin is part of the remark plugin infrastructure used by components such as mdsvex. Using markdown to write your content is a nice and convenient way to edit your content. Typically your writing content for a certain domain so you obviously would repeat several links across all your pages. Although unproblematic this plugin provides you with a lazy solution for this. It allows to setup a global configuration providing terms that shall be used to generate links. Here is a little example:

---
title: example
---
My main programming language is Java.

Using a corresponding configuration you can automatically link the term Java to generate the following markdown:

---
title: example
---
My main programming language is [Java](https://www.java.com/de/).

Obviously it's up to you which terms should be linked automatically.

When should I use this?

Whenever you like to conveniently generate links. This plugin isn't necessary but it's very helpful do stop repeating yourself.

Install

This package is ESM only. In Node.js (version 18+), install with pnpm:

pnpm i -D @kasisoft/remark-autolinker

Usage

  • Setup your Svelte project and install mdsvex (see mdsvexdocs)
  • Your project will now contain a file named mdsvex.config.js.
    • Import the plugin:
      import { remarkAutolinker } from '@kasisoft/remark-autolinker';
    • Update the array of remark plugins with a configuration:
      // RemarkAutolinkerOptions
      const myconfig = {
          debug: ['RootBefore', 'RootAfter'],
          all: false,
          caseInsensitive: false,
          links: [
              { key: 'Java', link: 'https://www.java.com/de/' },
              ...
          ],
      };
      const config = defineConfig({
          ...
          remarkPlugins: [
              [remarkAutolinker, myconfig]
          ],
          ...
      });

Direct Usage

It's possible to use the autolinking functionality directly like this:

  • Import the functionality:
    import { autolinkText } from '@kasisoft/remark-autolinker';
  • Run the transformation of a text:
      // RemarkAutolinkerOptions
      const myconfig = {
          debug: ['RootBefore', 'RootAfter'],
          all: false,
          caseInsensitive: false,
          links: [
              { key: 'Java', link: 'https://www.java.com/de/' },
              ...
          ],
      };
    const mytext: string = 'Some text...';
    const transformed: (string|Link)[] = autolinkText(mytext, myconfig);
    // each autolinked element is of type Link whereas non-matching
    // elements remain simple text.

Configuration

The configuration is fully typed using Typescript. RemarkAutolinkerOptions is defined as followed:

export interface Link {

    /* The term to be replaced by a Link */
    key: string,

    /* The link itself */
    link: string,

} /* ENDINTERFACE */

export interface RemarkAutolinkerOptions {

    /* Debug.{None, Default, RootBefore, RootAfter, All}
     * It's okay to use a list of string values for the debugging levels.
     * For instance: ['RootBefore', 'RootAfter']
     */
    debug           : Debug|'None'|'Default'|'RootBefore'|'RootAfter'|'All'|string[];

    /* By default only the first occurrance will be changed into a link.
     * If enabled all occurrences will be changed.
     */
    all             : boolean;

    /* By default the replacement requires a case sensitive match.
     * If enabled it will match independently of case sensitivity.
     */
    caseInsensitive : boolean;

    /* This is the list of links to define the terms that should be linked automatically. */
    links           : Link[];

} /* ENDINTERFACE */
  • debug : Debug - Combine flags of Debug in order to generate debug statements:
    • Debug.None: no output (just a convenience value)
    • Debug.Default: some basic output
    • Debug.RootBefore: prints the ast before the transformation
    • Debug.RootAfter: prints the ast after the transformation
    • Debug.All: enables all outputs (convenience value)
    • Using an array of strings representing these debug settings is also possible. For instance:
      • ['RootBefore', 'RootAfter']
  • all : Enables the automatic linking for all occurrences within the text.
  • caseInsensitive : Enables case insensitive matching.
  • links : The list of links to be used for the automatic linking.

Contributing

If you want to contribute I'm happy for any kind of feedback or bug reports. Please create issues and pull requests as you like but be aware that it may take some time for me to react.

Thanks

  • Svelte - For providing a great, fast and easy comprehensible framework.
  • MSDVEX - For the nice intergration of Markdown in Svelte
  • remark - For a great platform to modify/transform the content.

License

MIT © Kasisoft.com - [email protected]