mdheadline

helper functions for processing Markdown headlines


Keywords
markdown, headline, anchor, attributes
License
MIT
Install
npm install mdheadline@0.3.0

Documentation

MdHeadline

npm package dependency status build status

helper functions for processing Markdown headlines

Functions

To use a function require MdHeadline and call the function as a member of the module.

// require MdHeadline
var mdheadline = require('mdheadline');

// call a function from the module
var href = '#' + mdheadline.anchor('## 1. Einführung'); // -> '#einführung'

anchor(title)

Derives an HTML anchor for a headline. Uses the same rules as Pandoc.

getAttributes(title)

Parses the attributes of a headline and returnes a map with the found attributes. Supportes the PHP Markdown Extra syntax,

The following attribute types are supported:

  • ID attributes like # Chapter 1 { #ch_1 } (is mapped to the key id)
  • Class attributes # Chapter 1 { .highlighted .pivot } (are mapped as an array to the key classes)
  • Explicit key value pairs ## Section 1. 2. { level=2 number="1. 2." } (are mapped under thier given name)

Example:

var title = '## Chapter 1 { #ch_1 level=2 .highlighted .pivot }';
var attributes = mdheadline.getAttributes(title);

Result:

{
  "id": "ch_1",
  "classes": [ "highlighted", "pivot" ],
  "level": "2"
} 

removeFormat(title)

Strippes a headline from all formatting and optional attributes.

License

MdHeadline is published under MIT license.