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

v1.2.0

Published

Markdown parsing for custom containers

Downloads

7,514

Readme

remark-containers

This remark plugin provides parsing for containers in your markdown.

Default Syntax

Containers begin with ::: [noparse] {HTML Element Name} [optional list of classes] on a new line, and end with ::: on a new line. Container markers may be indented by up to 2 spaces.

For example:

::: aside class-one class-two
# Header One

With container contents. 
:::

renders as:

<aside class="class-one class-two">
  <h1>Header One</h1>
  <p>With container contents.</p>
</aside>

Containers may be nested

For example:

::: div outer
# Header One

Outer contents.

  ::: div inner
  Inner contents.
  :::

More outer contents.
::: 

renders as:

<div class="outer">           
  <h1>Header One</h1>         
  <p>Outer contents.</p>      
  <div class="inner">         
    <p>Inner contents.</p>    
  </div>                      
  <p>More outer contents.</p> 
</div>                        

noparse stops processing of the container contents and instead treats it as raw text.

For example:

::: noparse div outer
# Header One

Outer contents.

 ::: div inner
 Inner contents. 
 :::

More outer contents.
::: 

renders as:

<div class="outer">           
# Header One
Outer contents.
::: div inner
Inner contents. 
:::
More outer contents.
</div>                        

Installation

npm install remark-containers

Usage

const unified = require('unified')
const parse = require('remark-parse')
const containers = require('remark-containers')
const stringify = require('rehype-stringify')
const remark2rehype = require('remark-rehype')

unified()
  .use(parse)
  .use(containers)
  .use(remark2rehype)
  .use(stringify)

Options

Passing an options object allows full control over the resulting mdast.

.use(containers, {
  default: true, 
  custom: [{
    type: 'callout',
    element: 'article',
    transform: function(node, config, tokenize) {
      node.data.hProperties = {
          className: config || 'left'
      }
    }
    }, {
        type: 'quote',
        element: 'aside',
        transform: function(node, config, tokenize) {
          var words = tokenizeWords.parse(config)

          node.data.hProperties = {
              className: `quoted ${words.shift()}`
          }
          node.children.push({
              type: 'footer',
              data: {
                hName: 'footer'
              },
              children: tokenize(words.join(' '))
          })
        }
    }
  ]
})

default

When true the default syntax will also be enabled.

custom

An array of custom container configurations.

type

A single word string identifying the type of this container. Any markdown of the form ::: {type} will use this custom transform.

element

The html element name to use for the container. Default 'div'.

transform(node, config, tokenize)

A function to manipulate the mdast node.

node

The mdast node for this container.

config

The string after ::: type until the end of the line. Can be used to configure how the transform operates.

tokenize

A function(value): mdastNode you can use to tokenize an inline markdown string, if needed.

Feedback

Bugs & feedback.

License

MIT © Dan Behlings