Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mdast

Package Overview
Dependencies
Maintainers
1
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mdast

Markdown processor powered by plugins

  • 2.3.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
57K
increased by10.48%
Maintainers
1
Weekly downloads
 
Created
Source

mdast

Build Status Coverage Status Inline docs

mdast is a markdown processor powered by plugins. Lots of tests. Node, io.js, and the browser. 100% coverage.

mdast is not just another markdown to HTML compiler. It can generate, and reformat, markdown too. It’s powered by plugins to do all kinds of things: validate your markdown, add links for GitHub references, or add a table of contents.

The project contains both an extensive JavaScript API for parsing, modifying, and stringifying markdown, and a friendly Command Line Interface making it easy to validate, prepare, and compile markdown in a build step.

Table of Contents

Installation

npm:

npm install mdast

Read more about alternatives ways to install and use »

Usage

Load dependencies:

var mdast = require('mdast');
var html = require('mdast-html');
var yamlConfig = require('mdast-yaml-config');

Use plugins:

var processor = mdast().use(yamlConfig).use(html);

Process the document:

var doc = processor.process([
    '---',
    'mdast:',
    '  commonmark: true',
    '---',
    '',
    '2) Some *emphasis*, **strongness**, and `code`.'
].join('\n'));

Yields:

<ol start="2">
<li>Some <em>emphasis</em>, <strong>strongness</strong>, and <code>code</code>.</li>
</ol>

API

Get Started with the API »

mdast.process(value, options?, done?)

Parse a markdown document, apply plugins to it, and compile it into something else.

Signatures

  • doc = mdast.process(value, options?, done?).

Parameters

  • value (string) — Markdown document;

  • options (Object) — Settings:

  • done (function(Error?, string?)) — Callback invoked when the output is generated with either an error, or a result. Only strictly needed when async plugins are used.

All options (including the options object itself) can be null or undefined to default to their default values.

Returns

string or null: A document. Formatted in markdown by default, or in whatever a plugin generates. The result is null if a plugin is asynchronous, in which case the callback done should’ve been passed (don’t worry: plugin creators make sure you know its async).

mdast.use(plugin, options?)

Change the way mdast works by using a plugin.

Signatures

  • processor = mdast.use(plugin, options?);
  • processor = mdast.use(plugins).

Parameters

  • plugin (Function) — A Plugin;
  • plugins (Array.<Function>) — A list of Plugins;
  • options (Object?) — Passed to plugin. Specified by its documentation.

Returns

Object: an instance of MDAST: The returned object functions just like mdast (it has the same methods), but caches the used plugins. This provides the ability to chain use calls to use multiple plugins, but ensures the functioning of the mdast module does not change for other dependents.

CLI

Get Started with the CLI »

Install:

npm install --global mdast

Use:

Usage: mdast [options] <file|dir ...>

Markdown processor powered by plugins

Options:

  -h, --help                output usage information
  -V, --version             output the version number
  -o, --output [path]       specify output location
  -c, --config-path <path>  specify configuration location
  -i, --ignore-path <path>  specify ignore location
  -s, --setting <settings>  specify settings
  -u, --use <plugins>       use transform plugin(s)
  -e, --ext <extensions>    specify extensions
  -w, --watch               watch for changes and reprocess
  -a, --ast                 output AST information
  -q, --quiet               output only warnings and errors
  -S, --silent              output only errors
  -f, --frail               exit with 1 on warnings
  --file-path <path>        specify file path to process as
  --no-stdout               disable writing to stdout
  --no-color                disable color in output
  --no-rc                   disable configuration from .mdastrc
  --no-ignore               disable ignore from .mdastignore

Usage:

# Process `readme.md`
$ mdast readme.md -o readme-new.md

# Pass stdin through mdast, with settings, to stdout
$ mdast -s "setext: true, bullet: \"*\"" < readme.md > readme-new.md

# Use a plugin (with options)
$ npm install mdast-toc
$ mdast --use toc=heading:"contents" readme.md -o

# Rewrite markdown in a directory
$ mdast . -o

See also: man 1 mdast, man 3 mdast, man 3 mdastplugin,
  man 5 mdastrc, man 5 mdastignore, man 7 mdastsetting,
  man 7 mdastconfig, man 7 mdastnode, man 7 mdastplugin.

License

MIT © Titus Wormer

This project was initially a fork of marked.

Copyright (c) 2011-2014, Christopher Jeffrey. (MIT License)

Keywords

FAQs

Package last updated on 21 Dec 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc