Skip to content

Latest commit

 

History

History
100 lines (71 loc) · 2.23 KB

API.md

File metadata and controls

100 lines (71 loc) · 2.23 KB

mdextract

mdextract(src, options)

Extracts source documents.

var mdextract = require('mdextract');
var doc = mdextract(source);

console.log(doc.toMarkdown());

Returns a Document instance.

Document

new Document(options)

A document represents a bunch of source code. A mdextract call will return a Document instance.

var mdextract = require('mdextract');
var doc = mdextract(source);

Options available:

  • forceHeadings (boolean) If true, sections without headings will be ignored.
  • lang (string) Language to be used. Defaults to "js".

When invoking mdextract from the command line with a --json option, the result is a JSONified Document instance.

options

The available options as received through the Document constructor. Example:

doc = mdextract(source);

doc.options
=> { lang: "js" }

blocks

The list of section blocks as parsed away from the source. This is an array of Block instances.

doc = mdextract(source);

doc.blocks
=> [
  { internal: false,
    docline: 55,
    codeline: 66,
    level: 3,
    heading: "A heading",
    body: "This is the body in *markdown* format." },
  { ... },
  ...
]

toMarkdown

.toMarkdown(options)

Converts the document to markdown. Returns the Markdown string.

doc = mdextract(source);
console.log(doc.toMarkdown());
=> "## heading\nthis is stuff extracted from your source.\n..."

Available options are:

  • showInternal (boolean) renders internal/private API if true.

Block

A section block. Options:

  • docline (number) line number where the documentation starts
  • codeline (number) line number where code starts
  • level (number) heading level
  • heading (string) heading text
  • subheading (string, optional) optional subheading text
  • body (string) body text