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

section-remark

v0.0.1

Published

Specialized Remark that only transforms (or adds) one Markdown section

Downloads

2

Readme

section-remark

Specialized Remark that only transforms (or adds) one Markdown section.

npm status node Build Status Dependency status JavaScript Style Guide

Background

Remark works on an abstract syntax tree, which means some information is lost. Not semantics, but formatting, style, whitespace, i.e. your personal preferences. What's more, converting the AST back to markdown will add formatting and possibly result in unwanted diff noise.

Meant for sections of generated markdown, section-remark runs on a subset of the tree (a range of nodes starting with a certain header), stringifies it and concatenates the result with the rest of your markdown. Other sections are left alone.

Returns a unified processor, so like the regular remark, you can use any plugin.

Usage

As an example, let's generate a Contributors section:

const remark = require('section-remark')
const contributors = require('remark-contributors')
const report = require('vfile-reporter')
const vfile = require('to-vfile')

remark('Contributors')
  .use(contributors)
  .process(vfile.readSync('README.md'), function (err, file) {
    console.error(report(err || file))
    vfile.writeSync(file)
  })

This does nothing if the contributors section doesn't already exist. To either replace it or add it to the end of the document, do:

remark('Contributors', { add: true })

To replace it or add it after another section:

remark('Contributors', { after: 'API' })

We can use any test supported by mdast-util-heading-range. If we want to generate an API section and insert it after a usage or example section:

remark('API', { after: /^(usage|example)$/i })

Same goes for the first argument. If we want to replace or add a TOC:

remark(/^(table of )?contents$/i, { add: true })

This will throw an error though if the TOC doesn't exist, because section-remark can't convert the regular expression to a title. We should define the text option, so that a "Contents" header will be renamed to "Table of Contents". And let's insert the TOC before another section.

remark(/^(table of )?contents$/i, {
  text: 'Table of Contents',
  before: /^usage|example$/i
})

Lastly, if you use before or after and the section does not already exist, its header will inherit the depth of its before or after sibling.

API

sectionRemark(test[, options])

Returns a unified processor that transforms a section starting with a header which matches test (see mdast-util-heading-range). Options:

  • add: add to end of document, if not found
  • before: insert before section, if not found
  • after: insert after section, if not found
  • text: text content of header, defaults to test if a string
  • depth: header depth, starting at 1, defaults to sibling depth or 2.

Install

With npm do:

npm install section-remark

License

MIT © Vincent Weevers