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

commonmark-helpers

v0.4.1

Published

Helper methods for commonmark

Downloads

127

Readme

commonmark-helpers

NPM version Build Status Coveralls Status Dependency Status DevDependency Status

Even the strongest sometimes need help.

Basically, with commonmark-helpers you can find desire elements in markdown document and process them in html or plaintext format.

Bunch of helpers for working with commonmark. Also, you can be interested, why I created this module, that’s why I wrote a post about reasons.

Very important to notice, that this package is very simple and doesn’t contain any smart and/or complicated logic, that’s why it’s tightly coupled with commonmark API for AST tree. Check it out first.

Install

npm install --save commonmark-helpers

Usage

var md = require('commonmark-helpers');

md.text(md.match('# title\n\ntext', md.isHeader)); // title
md.html(`*italic*`);        // <p><em>italic</em></p>\n
md.text('**`plaintext`**'); // plaintext

function up(node) {
  if (node.literal) {
    node.literal = node.literal.toUpperCase();
  }
};

md.text(md.matchProcess('# LOOK\n\nMA', up)); // LOOK\n\nMA

Look into tests for more examples.

API

html(input)

Return html.

input

Type: string / AST

text(input)

Return plain text.

input

Type: string / AST

ast(input)

Return AST tree for current text.

input

Type: string

match(input, matcher)

Return first AST-node matched my matcher in process of walking through AST-tree. Returns undefined if no one AST-node have been matched.
The most powerful method in this collection.

input

Type: string / AST

matcher

Type: function. Receive: AST-node, event

In most cases you need only AST-node to match on.

matchRemove(input, matcher)

The same as match() but remove first matched AST-node and return AST-tree without it.

input

Type: string / AST

matcher

Type: function. Receive: AST-node, event

In most cases you need only AST-node to match on.

matchRemoveList(input, matcher1, [matcher2, […, matcherN]])

The same as matchRemove() but resulting AST-tree after matcher1 passing to matcher2, result of this to matcher3 and so on. Return AST-tree without all the matched AST-nodes.

input

Type: string / AST

matcher1, matcher2, …, matcherN

Type: function. Receive: AST-node, event

In most cases you need only AST-node to match on.

matchProcess(input, processor)

Match and process AST-nodes, return modified AST-tree.

input

Type: string / AST

processor

Type: function. Receive: AST-node, event

In most cases you need only AST-node to match on and modify.

matchProcessList(input, processor1, [processor2, […, processorN]])

The same as matchProcess() but resulting AST-tree after processor1 passing to processor2, result of this to processor3 and so on. Return AST-tree is AST-tree with all applied processors.

input

Type: string / AST

processor1, processor2, …, processorN

Type: function. Receive: AST-node, event

In most cases you need only AST-node to match on and modify.

Bunch of shortcut helpers

const isType = (node, type) => node.type === type;
const isLevel  = (node, level) => node.level === level;
const isText = node => isType(node, 'Text');
const isEmph = node => isType(node, 'Emph');
const isCode = node => isType(node, 'Code');
const isHtml = node => isType(node, 'Html');
const isLink = node => isType(node, 'Link');
const isItem = node => isType(node, 'Item');
const isList = node => isType(node, 'List');
const isImage = node => isType(node, 'Image');
const isStrong = node => isType(node, 'Strong');
const isHeader = node => isType(node, 'Header');
const isDocument = node => isType(node, 'Document');
const isCodeBlock = node => isType(node, 'CodeBlock');
const isHtmlBlock = node => isType(node, 'HtmlBlock');
const isSoftbreak = node => isType(node, 'Softbreak');
const isHardbreak = node => isType(node, 'Hardbreak');
const isParagraph = node => isType(node, 'Paragraph');
const isBlockQuote = node => isType(node, 'BlockQuote');
const isHorizontalRule = node => isType(node, 'HorizontalRule');

const isRoot  = node => node.parent && isDocument(node.parent);
const isBreak = node => isHardbreak(node) || isSoftbreak(node);

License

MIT © Vladimir Starkov