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

@orbiting/remark-preset

v1.2.4

Published

a preconfigured mdast processor with zones and meta data

Downloads

28

Readme

Remark Preset

Preconfigured remark for our projects.

API

parse

import { parse } from '@orbiting/remark-preset'

parse(md): Mdast

md: String
The markdown to parse.

Returns a mdast tree.

stringify

import { stringify } from '@orbiting/remark-preset'

stringify(mdast): String

mdast: Object
The mdast tree to stringify.

Returns a markdown string.

Features

Custom Mdast Type zone

<section><h6>IDENTIFIER</h6>

Group arbitrary markdown

<hr /></section>

Yields following AST:

{
  type: 'zone',
  identfier: 'IDENTIFIER',
  children: [{type: 'paragraph', children: [
    {type: 'text', value: 'Group arbitrary markdown'}
  ]}]
}

Zones can be nested and can have data (stringified as json in a code node). Under the hood the zone type is expanded and collapsed into flat nodes wrapped by html nodes with the section markup.

sub and sup Types

# CO<sub>2</sub>

40 µg/m<sup>3</sup>

Yields following AST:

[
  {
    type: 'heading',
    depth: 1,
    children: [
      {type: 'text', value: 'CO'},
      {
        type: 'sub',
        children: [
          {type: 'text', value: '2'}
        ]
      }
    ]
  },
  {
    type: 'paragraph',
    children: [
      {type: 'text', value: '40 µg/m'},
      {
        type: 'sup',
        children: [
          {type: 'text', value: '3'}
        ]
      }
    ]
  }
]

span Type

Need custom inline nodes? Use span.

<span data-number="10000">10'000</span>

Yields following AST:

{
  type: 'paragraph',
  children: [
    {
      type: 'span',
      data: {
        number: '10000'
      },
      children: [
        {
          type: 'text',
          value: '10\'000'
        }
      ]
    }
  ]
}

node.data must be a flat object with only strings. Each key gets mapped to its own data attribute. You can store complex data, if you really need to, by using one key with stringified json.

Meta Data

Yaml meta data on root.meta. Powered by js-yaml and remark-frontmatter.

Utils

If want only want the features and configure the unified processors yourself, you can import them individually:

import unified from 'unified'
import remarkStringify from 'remark-stringify'
import remarkParse from 'remark-parse'
import frontmatter from 'remark-frontmatter'

import * as meta from '@orbiting/remark-preset/lib/meta'
import * as zone from '@orbiting/remark-preset/lib/zone'
import * as tag from '@orbiting/remark-preset/lib/tag'
import * as span from '@orbiting/remark-preset/lib/span'

unified()
  .use(remarkParse, {
    // your options
  })
  .use(frontmatter, ['yaml'])
  .use(meta.parse)
  .use(zone.collapse({
    test: ({type, value}) => {
      // your logic
    },
    mutate: (start, nodes, end) => {
      // your logic
      return {
        type: 'zone',
        children: nodes
      }
    }
  }))
  .use(span.collapse)
  .use(tag.collapse('sub'))

const stringifier = unified()
  .use(remarkStringify, {
    // your options
  })
  .use(frontmatter, ['yaml'])
  .use(meta.format)
  .use(zone.expand({
    test: ({type}) => type === 'zone',
    mutate: (node) => {
      // your logic
      return [
        {
          type: 'html',
          value: `<section>`
        },
        ...node.children,
        {
          type: 'html',
          value: '</section>'
        }
      ]
    }
  }))
  .use(span.expand)
  .use(tag.expand('sub'))