- Notifications
You must be signed in to change notification settings - Fork7
📂 Convert a directory of Markdown files to HTML
License
s3ththompson/md-directory
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Convert a directory of Markdown files to HTML.
Uses thecommonmark Markdown renderer and thegray-matter frontmatter parser.
Install withnpm:
npm install --save md-directory
or, if usingYarn:
yarn add md-directory
Given a directoryposts
with a filehi.md
:
---title:foo---#bar
varmd=require('md-directory')md.parseDirSync('./posts')
returns:
{"hi.md":{"data":{"title":"foo"},"content":"<h1>bar</h1>\n"}}
Since version 1.0,md-directory
no longer supports theextensions
option since it was dropped byread-directory.
Usetransform.js to convert calls tomd-directory
methods into the contents they return. It is highly recommended that you use the synchronous methodsmd.parseDirSync
andmd.parseSync
with Browserify.
varpath=require('path')varmd=require('md-directory')varcontents=md.parseDirSync(path.join(__dirname,'posts'))
browserify index.js -t md-directory/transform -o bundle.js
varcontents={"hi":{"data":{"title":"foo"},"content":"<h1>bar</h1>\n"}};
Note: to use this transform, the path to the file directory can not be a variable. If you use the async methods, the callback must be an ES5 function (not an ES6 arrow function) and the results will be inlined withprocess.nextTick
. Seebrfs for more details on this behavior.
Read the contents of a directory and convert to Markdown asynchronously
Parameters
dir
String – The directory to readopts
Objectopts.md
Function alternate function to parse markdown, default: commonmarkopts.frontmatter
Function alternate function to parse frontmatter, default: gray-matteropts.encoding
String – encoding of files, default:utf8
opts.filter
String – glob pattern for filtering files, default:**\/*.md
opts.ignore
String – glob pattern for ignoring filesopts.ignore
Array – array of glob patterns for ignoring filesopts.dirnames
Boolean – include or exclude subdirectory names in keys of returned object, default:false
opts.transform
Function – A function you can use to transform the contents of files after they are converted
cb
Examples
varmd=require('md-directory')md.parseDir('./posts',function(err,contents){console.log(contents)})
Read the contents of a directory and convert to Markdown synchronously
Parameters
dir
String – The directory to readopts
Objectopts.md
Function alternate function to parse markdown, default: commonmarkopts.frontmatter
Function alternate function to parse frontmatter, default: gray-matteropts.encoding
String – encoding of files, default:utf8
opts.filter
String – glob pattern for filtering files, default:**\/*.md
opts.ignore
String – glob pattern for ignoring filesopts.ignore
Array – array of glob patterns for ignoring filesopts.dirnames
Boolean – include or exclude subdirectory names in keys of returned object, default:false
opts.transform
Function – A function you can use to transform the contents of files after they are converted
Examples
varmd=require('md-directory')varcontents=md.parseDirSync('./posts')
Read the contents of a file and convert to Markdown asynchronously
Parameters
filename
String – The filename to readopts
Objectopts.md
Function alternate function to parse markdown, default: commonmarkopts.frontmatter
Function alternate function to parse frontmatter, default: gray-matteropts.encoding
String – encoding of files, default:utf8
opts.transform
Function – A function you can use to transform the contents of files after they are converted
cb
Examples
varmd=require('md-directory')md.parse('./post.md',function(err,contents){console.log(contents)})
Read the contents of a file and convert to Markdown synchronously
Parameters
filename
String – The filename to readopts
Objectopts.md
Function alternate function to parse markdown, default: commonmarkopts.frontmatter
Function alternate function to parse frontmatter, default: gray-matteropts.encoding
String – encoding of files, default:utf8
opts.transform
Function – A function you can use to transform the contents of files after they are converted
Examples
varmd=require('md-directory')varcontents=md.parseSync('./post.md')
About
📂 Convert a directory of Markdown files to HTML
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.