• Stars
    star
    202
  • Rank 193,691 (Top 4 %)
  • Language
    CSS
  • Created about 13 years ago
  • Updated about 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

node.js markdown powered documentation generator

mdoc - a simple markdown based documentation generator

This is a simple markdown based documentation generator, it will search all the markdown files inside the "input" directory and output an HTML file for each document, it will also generate a "TOC" (table of contents) for each file and links to all the pages on the index page, it also provides a basic search feature and quick browsing between classes/methods/properties.

Reasoning behind it: inline documentation, why I'm ditching it .

Markdown syntax

mdoc uses the github "codeblock syntax" to highlight code. E.g.:

```js
  //code will be highlighted as JavaScript
```

```python
  //code will be highlighted as Python
```

Currently the parser considers H2 as sections/methods/properties names and will add them to the TOC at the top of each file and automatically generate deep-links to them. It's important to notice that mdoc only recognizes headers on the atx-style as a new section.

The first paragraph after the H2 will be used as description on the sidebar. Currently the search feature only searches copy from the title and description.

For a markdown syntax reference check: http://daringfireball.net/projects/markdown/dingus And also check the structure of the example files.

Install

You can install it through NPM:

npm install -g mdoc

Basic Usage

In a nodeJS file, create the basic outline with the desired configuration options listed below

require('mdoc').run({
    // configuration options (specified below)
    inputDir: 'docs',
    outputDir: 'dist'
});

Run the file node build.js. The outputDir will contain the finished HTML site.

Configuration

Source/Destination Directories (Required)

The following two options contain the source directory to read the documentation from and the destination directory to write the finished product to.

inputDir: 'docs'
outputDir: 'dist'

Basic settings (Optional)

Index File

These two options both specify what should go in to the index file. The indexContent setting will take precedence and overwrite anything specified in indexContentPath.

indexContentPath: 'path/to/index.md'
indexContent: '<h1>Custom markup to be inserted</h1>'

Site Title Tag

This controls what goes in the <title></title> tag in the outputted HTML. The format is Filename : WhatIsInbaseTitle.

baseTitle: 'mdocs title tag'

Advanced settings (Optional)

Custom Templates

Specify the path to the custom templates to use. These should be Handlebar template files

templatePath: 'path/to/template'

Static Assets

Specify the path to the static asset files (JS/CSS/images, etc)

assetsPath: 'path/to/assets'

Outputted File Names

Change the name of the outputted HTML files using a custom replacement string

mapOutName: function (outputName) {
 return outputName.replace('.html', '_doc.html');
}

Display Name

Change the name displayed on the sidebar and on the index TOC

mapTocName: function (fileName, tocObject, title) {
 return fileName.replace('_doc.html', '');
}

Include Files

Pattern that matches files that should be parsed

include: '*.mdown,*.md,*.markdown'

Exclude Files

Pattern that matches files that shouldn't be parsed

exclude: '.*'

Filter Files

Filters file. Return false to remove files and true to keep them

filterFiles: function (fileInfo) {
  return (/math/).test(fileInfo.input);
}

Heading Level

Sets which heading should be treated as a section start (and is used for TOC) defaults to 2

headingLevel: 3

Handlebars Helpers

You can also pass custom Handlebars helpers to be used during the compilation.

hbHelpers : {
  currency: function(val){
    var format = require('mout/number/currencyFormat');
    return format(val);
  },
  first: function(context, block) {
    return block.fn(context[0]);
  }
}

Handlebars context

You can also extend the context that gets provided to the Handlebars templates.

ctx : {
  version: '1.0.0'
  menu: [
    { name: 'Home', link: '/'},
    { name: 'Documentation', link: '/docs'},
    { name: 'API', link: '/docs/api'}
  ],
  site: {
    page: {
      title: 'API Documentation'
    }
  }
}

Those could be used inside your custom template as follow

<ul>
{{#each ctx.menu}}
  <li><a href="{{link}}">{{name}}</a></li>
{{/each}}
</ul>

<h2>{{ ctx.site.page.title }}</h2>

Also you can use Handlebars template in your markdown files:

## {{ ctx.site.page.title }}

Current version: {{ ctx.version }}

Parser override

If you want to use another markdown parser you can override the parsing function:

parsingFunction: function(markdownText): {
	return myParser.markdownToHtml(markdownText);
}

Examples

For a live example check: MOUT documentation or the unofficial NodeJS api (uses markdown files from nodejs repository as source)

Command line interface

mdoc -i examples/basic/content -o examples/basic/out

For a list of available commands run:

mdoc -h

Node module

Check files inside the "examples" folder. Run:

cd examples/basic
node build.js

Check output inside "examples/basic/doc".

Check "examples/advanced" for all the available settings.

License

Released under the MIT license.

More Repositories

1

js-signals

Custom Event/Messaging system for JavaScript inspired by AS3-Signals
JavaScript
1,959
star
2

crossroads.js

JavaScript Routes
JavaScript
1,445
star
3

esformatter

ECMAScript code beautifier/formatter
JavaScript
970
star
4

requirejs-plugins

RequireJS Plugins
JavaScript
932
star
5

Hasher

Browser history manager for rich media websites
JavaScript
492
star
6

rocambole

Recursively walk and transform EcmaScript AST
JavaScript
171
star
7

amd-utils

modular JavaScript utilities written in the AMD format
JavaScript
143
star
8

vim-statline

Add useful informations to Vim statusline
Vim Script
83
star
9

gh-markdown-cli

Node.js command-line tool to batch convert Markdown files into HTML
JavaScript
81
star
10

requirejs-hogan-plugin

RequireJS Hogan / Mustache Plugin
JavaScript
77
star
11

nodefy

convert AMD modules into a node.js compatible format
JavaScript
64
star
12

disparity

colorized string diff (char or unified) ideal for text/code that spans through multiple lines
JavaScript
56
star
13

vim-esformatter

run esformatter from inside vim (automatically formats JavaScript source code)
Vim Script
34
star
14

basis.css

A base CSS stylesheet for rapid development
31
star
15

CompoundSignal

Special Signal type used to listen for multiple Signals dispatches
JavaScript
31
star
16

node-ant

Experimental Apache Ant adapter for node.js
Shell
27
star
17

esformatter-quotes

esformatter plugin: enforces coding style that string literals are delimited with single or double quotes
JavaScript
26
star
18

domr

fast and async DOM updates for modern browsers
JavaScript
21
star
19

swffit

swffit repository
JavaScript
17
star
20

SVGParser

AS3 SVG parser to FIVe3D and HTML5 canvas
ActionScript
16
star
21

MM_js_lib

My Modular JavaScript Library
JavaScript
16
star
22

trainwreck.js

JavaScript method chaining made easy
JavaScript
15
star
23

MM_boilerplate

My Basic Project Boilerplate
JavaScript
13
star
24

CanvasContext2DWrapper

enable Canvas method chaining without overwritting any native objects/prototypes
JavaScript
13
star
25

esindent

[deprecated] ECMAScript code indenter based on Esprima AST and Rocambole
JavaScript
6
star
26

rocambole-token

Helpers for rocambole AST token manipulation
JavaScript
5
star
27

prototype-week-view

prototype for gaia calendar v2.1
JavaScript
5
star
28

Hasher_AS3_helper

Actionscript 3 helper classes to use together with Hasher.js
JavaScript
4
star
29

rtf.js

JavaScript RTF document generator
4
star
30

rocambole-node

Helpers for rocambole AST node manipulation
JavaScript
4
star
31

esformatter-semicolon-first

esformatter plugin to add semicolon before `[` and `(` if they are the first things on the line
JavaScript
3
star
32

esformatter-flow

esformatter plugin: enforces coding style for Flow type annotations
JavaScript
3
star
33

MM_php_lib

My Modular PHP5 Library
PHP
3
star
34

MM_as3_lib

My Modular AS3 Library
ActionScript
3
star
35

eclipse_monkey_scripts

Scripts for extending Eclipse and Aptana functionalities through the Eclipse Monkey plugin.
JavaScript
3
star
36

SceneGraph.js

[abandoned] JavaScript implementation of a Scene Graph (a.k.a. display list) initially targeting HTML5 canvas but with plans to support other rendering engines in the future.
3
star
37

esformatter-parser

JavaScript parser used by esformatter (babylon+rocambole)
JavaScript
1
star
38

rocambole-linebreak

helpers to manipulate rocambole AST line break tokens
JavaScript
1
star
39

rocambole-whitespace

helpers for rocambole AST whitespace manipulation
JavaScript
1
star
40

YUI_to_Jasmine

Simple tool to convert YUI Test assertions into Jasmine expect() calls
JavaScript
1
star
41

rocambole-indent

helpers for rocambole AST indentation
JavaScript
1
star