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-variables

v1.1.1

Published

Use text/link/abbreviations variables in your markdown files

Downloads

11

Readme

markdown-it-variables

When writing documentation or any markdown-based content, you might find yourself repeating a lot of text. Among these repetitive chunks of text, there might be some important units (e.g. product name, acronyms, etc.) that you would want to keep consistent and easy to write and replace. This markdown-it plugin is a straightforward way of achieving this.

  • ✅ Simple variables #{productName} -> My product
  • ✅ Acronyms: #{who|-} to <abbr title="World Health Organization">WHO</abbr>
  • ✅ Links: #{who|#} to <a href="https://www.who.int">World Health Organization</a>

Install

# Using npm
npm i markdown-it-variables
# Using Yarn
yarn add markdown-it-variables
# Using pnpm
pnpm add markdown-it-variables

Usage

import mardownIt from 'markdown-it';
import { variablesPlugin } from 'markdown-it-variables';

const md = mardownIt().use(variablesPlugin, {
  since: '1948',
  who: {
    url: 'https://www.who.int',
    abbr: 'WHO',
    label: 'World Health Organization',
  },
});

You can then reference your variables from a markdown file: #{since} and #{who}. You can also apply a list of pipe-separated modifiers: #{who|abbr|link}, and use modifier aliases to get even more concise: #{who|-|#}.

Modifiers

Options

data: Record<string, SimpleVariable | ExpandedVariable>

List of variables you want to use.

There are two kinds of variables :

  1. Simple ones, whose values can be any string.
  2. Rich ones, which can define further piece of information that can later be used through modifiers.

The value of rich variables are objects with the following structure:


severity?: 'error' | 'warn' | 'silent' (optional, defaults to 'warn')

Determines the severity of the plugin.

Here is an overview of how different severities change the behaviour of the plugin:

❌ Throws │ ⏭️ Skips (does not transform) │ ✅ Transforms to fallback │ ❕ Prints a warning message


ignoreMissingVariables?: boolean (optional, defaults to false)

When set to true, prevents the plugin from throwing when encountering references to missing variables.

This basically overwrites the above behaviours with the following:

  • It does not throw even if severity is set to 'error'.
  • It does not print any warning even if severity is set to 'warn'.

className?: string (defaults to undefined)

When defined, the outter tags of any variable will have the specified class name. When specified and encountering variables without modifiers, the variable output will be wrapped in a span with the specified class name.


Example

Based on the options illustrated in the Usage section.

Input:

Founded in #{since}, #{who|#} is the United Nations agency that connects nations, partners and
people to promote health, keep the world safe and serve the vulnerable - so everyone, everywhere can
attain the highest level of health.

#{who|-} leads global efforts to expand universal health coverage. We direct and coordinate the
world's response to health emergencies.

Output:

Founded in 1948, <a href="https://www.who.int">World Health Organization</a> is the United Nations
agency that connects nations, partners and people to promote health, keep the world safe and serve
the vulnerable - so everyone, everywhere can attain the highest level of health.

<abbr title="World Health Organization">WHO</abbr> leads global efforts to expand universal health
coverage. We direct and coordinate the world's response to health emergencies.