Coder Social home page Coder Social logo

mdast-util-heading-range's Introduction

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 bower, component, and duo, and as an AMD, CommonJS, and globals module, uncompressed and compressed.

Table of Contents

Usage

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

Callback invoked when a heading is found.

function onrun(start, nodes, end) {
    return [
        start,
        {
            'type': 'paragraph',
            'children': [
                {
                    'type': 'text',
                    'value': 'Qux.'
                }
            ]
        },
        end
    ];
}

Process a document.

var doc = mdast().use(heading('foo', onrun)).process(
    '# Foo\n' +
    '\n' +
    'Bar.\n' +
    '\n' +
    '# Baz\n'
);

Yields:

# Foo

Qux.

# Baz

API

heading(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

  • 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.

Returns

Function — Should be passed to mdast.use().

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

mdast-util-heading-range's People

Contributors

justjake avatar wooorm avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.