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

mdast-util-heading-range

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mdast-util-heading-range

Markdown heading as ranges in mdast

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

mdast-util-heading-range Build Status Coverage Status

Markdown heading as ranges in mdast.

Installation

npm:

npm install mdast-util-heading-range

mdast-util-heading-range is also available for duo, and as an AMD, CommonJS, and globals module, uncompressed and compressed.

Usage

var heading = require('mdast-util-heading-range');
var remark = require('remark');

Process a document.

var doc = remark()
    .use(function () {
        return function (node) {
            heading(node, 'foo', function (start, nodes, end) {
                return [
                    start,
                    {
                        'type': 'paragraph',
                        'children': [
                            {
                                'type': 'text',
                                'value': 'Qux.'
                            }
                        ]
                    },
                    end
                ];
            });
        }
    }).process([
        '# Foo',
        '',
        'Bar.',
        '',
        '# Baz',
        ''
    ].join('\n'));

Yields:

# Foo

Qux.

# Baz

API

heading(node, test, onrun)

Transform part of a document without affecting other parts, by changing a section: a heading which passes test, until the next heading of the same or lower depth, or the end of the document.

Parameters

  • node (Node) — Node to search;

  • test (string, RegExp, function(string, Node): boolean) — Heading to look for:

    • When string, wrapped in new RegExp('^(' + value + ')$', 'i');

    • Then, when RegExp, wrapped in function (value) {expression.test(value)}.

  • onrun (Array.<Node>? = function (start, nodes, end)) — Callback invoked when a range is found.

function onrun(start, nodes, end?, scope)

Parameters

  • start (Heading) — Start of range;

  • nodes (Array.<Node>) — Nodes between start and end;

  • end (Heading?) — End of range, if any.

  • scope (Object):

    • parent (Node) — Parent of the range;
    • start (number) — Index of start in parent;
    • end (number?) — Index of end in parent.

Returns

Array.<Node>? — Zero or more nodes to replace the range (including start, and end) with.

License

MIT © Titus Wormer

Keywords

FAQs

Package last updated on 17 Jan 2016

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