JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 16404
  • Score
    100M100P100Q141063F
  • License MIT

Manipulate sections in a markdown string. A 'section' is a block of content preceded by a valid markdown ATX heading.

Package Exports

  • sections

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (sections) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

sections NPM version NPM downloads Build Status

Manipulate sections in a markdown string. A 'section' is a block of content preceded by a valid markdown ATX heading.

Install

Install with npm:

$ npm install --save sections

Usage

This is meant to be fast and opinionated, and only works with ATX headings.

var sections = require('sections');

API

.parse

Parses sections in a string of markdown and returns an object with two properties:

  • sections: an array of markdown "sections", delimited by ATX headings,
  • result: the cumulative result of whatever is returned by the (optional) function that is passed as the second argument. Returns an object that looks something like this

Params

  • string {String}
  • fn {Function}
  • returns {Object}

Example

var fs = require('fs');
var readme = fs.readFileSync('example/basic.md', 'utf8');
var sections = require('sections');
console.log(sections.parse(readme));

.format

Format sections. By default, if no filter function is passed, this:

  • filters out empty sections
  • fixes whitespace between sections

Params

  • str {String}: Markdown string
  • fn {Function}: optional filter function
  • returns {String}

Example object

The parsed object that is returned looks something like this:

{ sections:
   [ Section {
       pos: 12,
       count: 0,
       string: '# sections \n',
       heading: '# sections',
       level: 1,
       title: 'sections',
       body: '' },
     Section {
       pos: 32,
       count: 1,
       string: '\n## Foo\nThis is foo\n',
       heading: '## Foo',
       level: 2,
       title: 'Foo',
       body: 'This is foo' },
     Section {
       pos: 52,
       count: 2,
       string: '\n## Bar\nThis is bar\n',
       heading: '## Bar',
       level: 2,
       title: 'Bar',
       body: 'This is bar' },
     Section {
       pos: 72,
       count: 3,
       string: '\n## Baz\nThis is baz\n',
       heading: '## Baz',
       level: 2,
       title: 'Baz',
       body: 'This is baz' } ],
  result: '',
  headings: [ 'sections', 'Foo', 'Bar', 'Baz' ] }

About

Contributing

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

Building docs

(This document was generated by verb-generate-readme (a verb generator), please don't edit the readme directly. Any changes to the readme must be made in .verb.md.)

To generate the readme and API documentation with verb:

$ npm install -g verb verb-generate-readme && verb

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Jon Schlinkert

License

Copyright © 2016, Jon Schlinkert. Released under the MIT license.


This file was generated by verb-generate-readme, v0.1.28, on August 04, 2016.