Skip to content

millermedeiros/gh-markdown-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Github Flavored Markdown Node.js CLI

Batch convert Markdown files into HTML.

Installation

Install node.js 0.6.0+ and run:

sudo npm install gh-markdown-cli -g

This will create an alias to the executable on your /usr/local/bin folder, if you install it without the -g flag you won't be able use it as global command-line utility.

Usage example

Basic

mdown --input "**/*.md" --output doc

This will convert any .md files it can find inside the --input directory and it's child folders and output them into the --output folder.

If you want to convert only files inside the directory itself but ignore child folders change the --input glob to "*.md":

mdown -i "src/*.md" -o doc

And to convert just a single file and output it into the current folder:

mdown -i "foo.md" -o .

Header / Footer

You can specify HTML files to be used as header and footer of all the pages:

mdown -i "*.md" -o dist --header "assets/header.html" --footer "assets/header.html"

stdin / stdout

It also works with stdin and stdout, so you can pipe other command-line tools like echo, cat, curl, etc...

cat foo.md | mdown > foo.html
echo "# foo" | mdown
curl https://raw.github.com/millermedeiros/gh-markdown-cli/master/README.md | mdown

If you don't specify the --output it will echo the result to stdout by default.

Vim and other text editors

Since this tool works with the stdin and stdout you can use it from inside Vim to convert the selected text into HTML:

vnoremap <silent> <leader>md :! mdown<CR>

Or if you want to convert the whole file content:

:%!mdown

Plugins for other text editors can probably be easily coded.

More

For a list of all available options run mdown -h:

$ mdown -h

  Usage: mdown [options]

  Options:

    -h, --help             output usage information
    -V, --version          output the version number
    -o, --output <name>    Output directory or output file name if using stdin for input.
    -i, --input <glob>     Glob used for inclusion. Eg: "**/*.md" will convert all the ".md" files inside current folder and all its child folders.
    --exclude <globs>      Comma separated list of globs used for exclusion. Defaults to "node_modules/**"
    --header <path>        Path to HTML file used as header on all documents.
    --footer <path>        Path to HTML file used as footer on all documents.
    --encoding <encoding>  File encoding. Defaults to "utf-8".

Important

The real work was done by the creators of the open source libraries used by this project (node-glob, minimatch, wrench-js, github-flavored-markdown, commander.js), I only assembled things together to make it easier to use, the credit should go to them.

License

WTFPL

About

Node.js command-line tool to batch convert Markdown files into HTML

Resources

Stars

Watchers

Forks

Packages

No packages published