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

mdast-zone

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mdast-zone

HTML comments as ranges in remark

  • 3.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.3K
decreased by-31.02%
Maintainers
1
Weekly downloads
 
Created
Source

mdast-zone

Build Coverage Downloads Size Sponsors Backers Chat

mdast utility to treat HTML comments as ranges.

Useful in remark plugins.

Install

npm:

npm install mdast-zone

Usage

Say we have the following file, example.md:

<!--foo start-->

Foo

<!--foo end-->

And our script, example.js, looks as follows:

var vfile = require('to-vfile')
var remark = require('remark')
var zone = require('mdast-zone')

remark()
  .use(plugin)
  .process(vfile.readSync('example.md'), function(err, file) {
    if (err) throw err
    console.log(String(file))
  })

function plugin() {
  return transform

  function transform(tree) {
    zone(tree, 'foo', mutate)
  }

  function mutate(start, nodes, end) {
    return [
      start,
      {type: 'paragraph', children: [{type: 'text', value: 'Bar'}]},
      end
    ]
  }
}

Now, running node example yields:

<!--foo start-->

Bar

<!--foo end-->

API

zone(tree, name, handler)

Search tree for comment ranges (“zones”).

Parameters
  • tree (Node) — Tree to search for ranges
  • name (string) — Name of ranges to search for
  • handler (Function) — Function invoked for each found range
function handler(start, nodes, end)

Invoked with the two markers that determine a range: the first start and the last end, and the content inside.

Parameters
  • start (Node) — Start of range (an HTML comment node)
  • nodes (Array.<Node>) — Nodes between start and end
  • end (Node) — End of range (an HTML comment node)
Returns

Array.<Node>? — List of nodes to replace start, nodes, and end with, optional.

Contribute

See contributing.md in syntax-tree/.github for ways to get started. See support.md for ways to get help.

This project has a Code of Conduct. By interacting with this repository, organisation, or community you agree to abide by its terms.

License

MIT © Titus Wormer

Keywords

FAQs

Package last updated on 24 May 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