Skip to content

Snapdragon plugin that adds a capture method to the parser instance, which allows you to capture tokens with a single line of code

License

Notifications You must be signed in to change notification settings

here-be/snapdragon-capture

Repository files navigation

snapdragon-capture NPM version NPM monthly downloads NPM total downloads Linux Build Status

Snapdragon plugin that adds a capture method to the parser instance.

Install

Install with npm:

$ npm install --save snapdragon-capture

Usage

Requires snapdragon v0.9.0 or higher.

var capture = require('snapdragon-capture');
var Snapdragon = require('snapdragon');
var snapdragon = new Snapdragon();
snapdragon.use(capture());

API

Example

var Snapdragon = require('snapdragon');
var capture = require('snapdragon-capture');
var parser = new Snapdragon.Parser();
parser.use(capture());

Create a node of the given type using the specified regex or function.

Params

  • type {String}
  • regex {RegExp|Function}: Pass the regex to use for capturing. Pass a function if you need access to the parser instance.
  • returns {Object}: Returns the parser instance for chaining

Example

parser
  .capture('slash', /^\//)
  .capture('comma', /^,/)
  .capture('foo', function() {
    var pos = this.position();
    var match = this.match(/^\./);
    if (match) {
      return pos(this.node(match[0]));
    }
  });

About

Related projects

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Please read the contributing guide for advice on opening issues, pull requests, and coding standards.

Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Running tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test

Author

Jon Schlinkert

License

Copyright © 2017, Jon Schlinkert. MIT


This file was generated by verb-generate-readme, v0.4.2, on February 08, 2017.

About

Snapdragon plugin that adds a capture method to the parser instance, which allows you to capture tokens with a single line of code

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

  •  
  •  

Packages

No packages published