better-markdown-walker

0.0.16 • Public • Published

markdown-walker Build Status

Utility for walking a directory structure and parsing markdown files into html

Getting Started

To install this package you simply run this from the command line:

npm install better-markdown-walker --save

This utility uses the process.cwd() as the root when it is passed a relative file path. You can override this by passing { cwd: "anyPath" } to any of the constructors.

MarkdownFile

You can process files individually if you like. Let's say we would like to write a file my-markdown.md.

var mw = require("better-markdown-walker");
var markdownFile = new mw.MarkdownFile("./relative-path/my-markdown.md");
markdownFile.write("#anyMarkdownContent");

Ideally you would then load the file again using the parse method to get hold of the html and various other info.

var mw = require("better-markdown-walker");
var markdownFile = new mw.MarkdownFile("./relative-path/my-markdown.md");
var result = markdownFile.parse();

This would give you an object of the following shape:

{ fullPath: '/usr/local/src/nodejs/markdown-walker/relative-path/my-markdown.md',
  relativePath: './relative-path/my-markdown.md',
  markdown: '#anyMarkdownContent',
  html: '<h1 id="anymarkdowncontent">anyMarkdownContent</h1>' }

MarkdownDirectory

You can also work with directories en masse if you need to by creating a MarkdownDirectory object. Let's say we would like to parse the same file above but instead we use a directory object. This would trawl through the root directory parsing out files that have a .md extension.

var mw = require("better-markdown-walker");
var markdownDirectory = new mw.MarkdownDirectory("./relative-path/");
var results = markdownDirectory.parse();

Instead of getting just one file it will find all of them. A naf example but the only difference in this case would be that you would get an array.

[{ fullPath: '/usr/local/src/nodejs/markdown-walker/relative-path/my-markdown.md',
  relativePath: './relative-path/my-markdown.md',
  markdown: '#anyMarkdownContent',
  html: '<h1 id="anymarkdowncontent">anyMarkdownContent</h1>' }]

There you have it folks. A short note to also thank the guys who wrote 'showdown'. Watch this space for file system hooks, express middleware and github integration :)

Readme

Keywords

none

Package Sidebar

Install

npm i better-markdown-walker

Weekly Downloads

14

Version

0.0.16

License

none

Last publish

Collaborators

  • fir3pho3nixx