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

remark-mdat

v0.7.4

Published

A remark plugin implementing the Markdown Autophagic Template (MDAT) system.

Downloads

100

Readme

remark-mdat

NPM Package remark-mdat License: MIT

A remark plugin implementing the Markdown Autophagic Template (MDAT) system.

[!NOTE]
Please see The mdat package for a higher-level CLI tool and library with a collection of built-in expansion rules.

Table of contents

Overview

This is a remark plugin that automates the inline expansion of placeholder HTML comments with dynamic content in Markdown, making it easy to keep readme files and other documentation in sync with an external single source of truth.

The plugin can take placeholder comments in a Markdown file like this:

<!-- title -->

And replace it with dynamic data. In this case, from package.json:

<!-- title -->

# remark-mdat

<!-- /title -->

This plugin powers the higher-level mdat package, which is a better place to start if you just want to expand some comments and aren't working directly with remark processing pipelines.

Getting started

Dependencies

This library is ESM only and requires Node 18 (specifically ^18.19.0 || >=20.5.0). It's designed to work with Remark 15. remark-mdat is implemented in TypeScript and bundles a complete set of type definitions.

Installation

npm install remark-mdat

Usage

API

Core plugin

This package's default export implements the unified Plugin type.

The plugin is integrated into a remark process chain via the .use() method:

import { remark } from 'remark'
import remarkMdat from 'remark-mdat'

remark().use(remarkMdat)

Options

The plugin accepts an optional options object which exposes some configuration options and, most importantly, determines how comments in the source Markdown file will be expanded via the rules field:

export type Options = {
  addMetaComment?: boolean // default: false
  closingPrefix?: string // default: '/',
  keywordPrefix?: string // default: '',
  metaCommentIdentifier?: string // default: '+',
  rules?: Rules // default: a single test rule for the 'mdat' keyword
}

Examples

Basic

remark-mdat includes one test rule by default, <!-- mdat -->.

import { remark } from 'remark'
import remarkMdat from 'remark-mdat'

const markdownInput = '<!-- mdat -->'
const markdownOutput = await remark().use(remarkMdat).process(markdown)

console.log(markdownOutput.toString())

// Logs:
// <!-- mdat -->
//
// Powered by the Markdown Autophagic Template system: [mdat](https://github.com/kitschpatrol/mdat).
//
// <!-- /mdat -->

With options

If you wanted to replace <!-- time --> comments in your Markdown file with the current time, you could pass in a rule:

import { remark } from 'remark'
import { type Rules, default as remarkMdat } from 'remark-mdat'

// Create the rule
const rules: Rules = {
  time: () => new Date().toDateString(),
}

const markdownInput = '<!-- time -->'

// Pass the time rule to remarkMdat
const markdownOutput = await remark().use(remarkMdat, { rules }).process(markdown)

console.log(markdownOutput.toString())

// Logs:
// <!-- time -->
//
// Mon Feb 05 2024
//
// <!-- /time -->

See the mdat package for a higher-level API and CLI that can operate directly on files or strings. It also provides dynamic rule loading and configuration resolution, and bundles a collection of rules convenient for use in readme files.

Utilities

The plugin bundles a number of mdast utilities designed to operate directly on syntax trees. These are exported to support customized Unified.js processors and enforce modularity and separation of concerns in mdat's internal implementation, but you do not need to use them directly — all functionality is encapsulated in the single remarkMdat plugin export.

The remark-mdat plugin chains these utilities together to accommodate the typical use case of end-to-end expansion and validation of mdat comments. For now, the individual utility transformers are not published individually to NPM, and are instead bundled with remark-mdat.

  • mdast-util-mdat

    Composite transformer function performing end-to-end mdat comment expansion and validation on Markdown ASTs by chaining the other utility functions described below.

    Exported as mdat

    Utilities wrapped by mdast-util-mdat:

    • mdast-util-mdat-split

      Transformer function that allows inline mdat expansion comments.

      Exported as mdatSplit

    • mdast-util-mdat-clean

      Transformer function that "resets" all mdat comment expansions in a file, collapsing expanded comments back into single-line placeholders.

      Exported as mdatClean

    • mdast-util-mdat-expand

      Transformer function that expands mdat comments (e.g. <!-- title -->) in a Markdown file according to the rule set passed in to the MdatExpandOptions argument.

      Exported as mdatExpand

    • mdast-util-mdat-check

      Transformer function that validates an expanded Markdown document against the requirements defined in the rules passed in to the MdatCheckOptions argument.

      See reporterMdat to extract, format, and log results from VFile messages written by mdatCheck. This function does not modify the tree, it only appends messages to the VFiles passed through it.

      Exported as mdatCheck

Implementation notes

This project was split from a monorepo containing both mdat and remark-mdat into separate repos in July 2024.

The future

Maintainers

@kitschpatrol

Acknowledgments

Thanks to the unified team for their superb ecosystem of AST tools.

Contributing

Issues and pull requests are welcome.

License

MIT © Eric Mika