Skip to content

Latest commit

 

History

History
191 lines (127 loc) · 3.49 KB

Reference.md

File metadata and controls

191 lines (127 loc) · 3.49 KB

Flatdoc

Basic Flatdoc module.

The main entry point is Flatdoc.run(), which invokes the Runner.

Flatdoc.run({
  fetcher: Flatdoc.github('rstacruz/backbone-patterns');
});

Flatdoc.run()

Creates a runner. See Flatdoc.

Flatdoc.file()

File fetcher function.

Fetches a given url via AJAX. See Runner#run() for a description of fetcher functions.

Flatdoc.github()

Github fetcher. Fetches from repo repo (in format 'user/repo').

If the parameter filepath is supplied, it fetches the contents of that given file in the repo.

See Runner#run() for a description of fetcher functions.

See: http://developer.github.com/v3/repos/contents/

Parser

Parser module. Parses a given Markdown document and returns a JSON object with data on the Markdown document.

var data = Flatdoc.parser.parse('markdown source here');
console.log(data);
data == {
  title: 'My Project',
  content: '<p>This project is a...',
  menu: {...}
}

Parser.parse()

Parses a given Markdown document. See Parser for more info.

Transformer

Transformer module. This takes care of any HTML mangling needed. The main entry point is .mangle() which applies all transformations needed.

var $content = $("<p>Hello there, this is a docu...");
Flatdoc.transformer.mangle($content);

If you would like to change any of the transformations, decorate any of the functions in Flatdoc.transformer.

Transformer.mangle()

Takes a given HTML $content and improves the markup of it by executing the transformations.

See: Transformer

Transformer.addIDs()

Adds IDs to headings.

Transformer.getMenu()

Returns menu data for a given HTML.

menu = Flatdoc.transformer.getMenu($content);
menu == {
  level: 0,
  items: [{
    section: "Getting started",
    level: 1,
    items: [...]}, ...]}

Transformer.buttonize()

Changes "button >" text to buttons.

Transformer.smartquotes()

Applies smart quotes to a given element. It leaves code and pre blocks alone.

Highlighters

Syntax highlighters.

You may add or change more highlighters via the Flatdoc.highlighters object.

Flatdoc.highlighters.js = function(code) {
};

Each of these functions

Highlighters.js

JavaScript syntax highlighter.

Thanks @visionmedia!

MenuView

Menu view. Renders menus

Runner

A runner module that fetches via a fetcher function.

var runner = new Flatdoc.runner({
  fetcher: Flatdoc.url('readme.txt')
});
runner.run();

The following options are available:

  • fetcher - a function that takes a callback as an argument and executes that callback when data is returned.

See: Flatdoc.run()

Runner#run()

Loads the Markdown document (via the fetcher), parses it, and applies it to the elements.

Runner#applyData()

Applies given doc data data to elements in object elements.