package
Convert a directory of Markdown files to HTML
npm install md-directoryGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Convert a directory of Markdown files to HTML.
Uses the commonmark Markdown renderer and the gray-matter frontmatter parser.
Install with npm:
npm install --save md-directoryor, if using Yarn:
yarn add md-directoryGiven a directory posts with a file hi.md:
---
title: foo
---
# barvar md = 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 the extensions option since it was dropped by read-directory.
Use transform.js to convert calls to md-directory methods into the contents they return. It is highly recommended that you use the synchronous methods md.parseDirSync and md.parseSync with Browserify.
var path = require('path')
var md = require('md-directory')
var contents = md.parseDirSync(path.join(__dirname, 'posts'))browserify index.js -t md-directory/transform -o bundle.js var contents = {"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 with process.nextTick. See brfs for more details on this behavior.
Read the contents of a directory and convert to Markdown asynchronously
Parameters
Examples
var md = require('md-directory')
md.parseDir('./posts', function (err, contents) {
console.log(contents)
})Read the contents of a directory and convert to Markdown synchronously
Parameters
Examples
var md = require('md-directory')
var contents = md.parseDirSync('./posts')Read the contents of a file and convert to Markdown asynchronously
Parameters
Examples
var md = 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
Examples
var md = require('md-directory')
var contents = md.parseSync('./post.md')opts.encoding String – encoding of files, default: utf8opts.filter String – glob pattern for filtering files, default: **\/*.mdopts.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: falseopts.transform Function – A function you can use to transform the contents of files after they are convertedcbopts.encoding String – encoding of files, default: utf8opts.filter String – glob pattern for filtering files, default: **\/*.mdopts.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: falseopts.transform Function – A function you can use to transform the contents of files after they are convertedopts.encoding String – encoding of files, default: utf8opts.transform Function – A function you can use to transform the contents of files after they are convertedcbopts.encoding String – encoding of files, default: utf8opts.transform Function – A function you can use to transform the contents of files after they are convertedEstimated unpacked size across 60 packages.
9.9 MB
Includes dependencies.
7 direct · 3 outdated
^4.17.15
4.18.1
^1.0.3
3.0.0
^3.0.1
5.0.12
^0.29.1
0.31.2
^4.0.2
4.0.3
^3.0.3
3.0.4
^3.0.2
3.0.2