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

mdast-util-directive

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mdast-util-directive

mdast extension to parse and serialize generic directives (`:cite[smith04]`)

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
511K
increased by3.79%
Maintainers
2
Weekly downloads
 
Created

What is mdast-util-directive?

The `mdast-util-directive` package is a utility for working with directives in Markdown Abstract Syntax Trees (MDAST). It allows you to parse, transform, and stringify custom directives in Markdown documents, enabling more advanced and customizable Markdown processing.

What are mdast-util-directive's main functionalities?

Parsing Directives

This feature allows you to parse custom directives in Markdown content into an MDAST. The code sample demonstrates how to set up a processor with `remark-parse` and `mdast-util-directive` to parse a custom directive.

const { fromMarkdown } = require('mdast-util-directive');
const { unified } = require('unified');
const markdown = require('remark-parse');

const processor = unified()
  .use(markdown)
  .use(fromMarkdown);

const mdContent = ':::{.example}
This is a custom directive
:::';

const tree = processor.parse(mdContent);
console.log(tree);

Transforming Directives

This feature allows you to transform custom directives in the MDAST. The code sample shows how to use `unist-util-visit` to visit and transform a custom directive node in the syntax tree.

const { visit } = require('unist-util-visit');
const { fromMarkdown } = require('mdast-util-directive');
const { unified } = require('unified');
const markdown = require('remark-parse');

const processor = unified()
  .use(markdown)
  .use(fromMarkdown);

const mdContent = ':::{.example}
This is a custom directive
:::';

const tree = processor.parse(mdContent);

visit(tree, 'containerDirective', (node) => {
  node.data = { hName: 'div', hProperties: { className: 'example' } };
});

console.log(tree);

Stringifying Directives

This feature allows you to stringify custom directives back into Markdown. The code sample demonstrates how to set up a processor to parse and then stringify a custom directive.

const { toMarkdown } = require('mdast-util-directive');
const { unified } = require('unified');
const markdown = require('remark-parse');
const stringify = require('remark-stringify');

const processor = unified()
  .use(markdown)
  .use(fromMarkdown)
  .use(stringify)
  .use(toMarkdown);

const mdContent = ':::{.example}
This is a custom directive
:::';

const tree = processor.parse(mdContent);
const output = processor.stringify(tree);
console.log(output);

Other packages similar to mdast-util-directive

Keywords

FAQs

Package last updated on 11 Jul 2023

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