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

remark-code-blocks

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remark-code-blocks

Extract code blocks from an MDAST tree

  • 2.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.2K
decreased by-16.67%
Maintainers
1
Weekly downloads
 
Created
Source

remark-code-blocks

Remark plugin to extract code nodes from markdown.

Travis Coverage
Status

Install

npm i -S remark-code-blocks

Usage

const toVfile = require('to-vfile')
const unified = require('unified')
const parser = require('remark-parser')
const stringify = require('remark-stringify')
const codeblocks = require('remark-code-blocks')

unified()
    .use(parser)
    .use(stringify)
    .use(codeblocks, { /* options */ })
    .process(toVfile('./example.md'))
    .then(file => {
        /* file.data.codeblocks = [ ... ] */
    })

or use the standalone function which takes a tree as its first argument.

const toVfile = require('to-vfile')
const unified = require('unified')
const parser = require('remark-parser')
const { codeblocks } = require('remark-code-blocks')

const tree = unified().use(parser).parse(toVfile('./example.md'))
const code = codeblocks(tree, { /* options */ })

API

.use(codeblocks[, options])

Use as a plugin to extract code nodes.

The results are stored in file.data in a codeblocks property by default. You can override the name of the property using options.name.

.codeblocks(tree[, options])

Also exports a standalone function.

Options

lang

Type: string Default: all

Specify a language and only extract code nodes with that language. Otherwise all code nodes are extracted.

name

Type: string Default: codeblocks

Specify the name of the property in file.data

formatter

Type: function Default: none

Add a function to run over the nodes values before storing them in file.data

License

MIT © Paul Zimmer

Keywords

FAQs

Package last updated on 10 Dec 2019

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