Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

📂 Convert a directory of Markdown files to HTML

License

NotificationsYou must be signed in to change notification settings

s3ththompson/md-directory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npm versionbuild statusstability

Convert a directory of Markdown files to HTML.

Uses thecommonmark Markdown renderer and thegray-matter frontmatter parser.

Install

Install withnpm:

npm install --save md-directory

or, if usingYarn:

yarn add md-directory

Usage

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.

Inlining results with Browserify

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.

Source

varpath=require('path')varmd=require('md-directory')varcontents=md.parseDirSync(path.join(__dirname,'posts'))

Browserify

browserify index.js -t md-directory/transform -o bundle.js

Output

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.

API

parseDir

Read the contents of a directory and convert to Markdown asynchronously

Parameters

  • dirString – The directory to read
  • optsObject
    • opts.mdFunction alternate function to parse markdown, default: commonmark
    • opts.frontmatterFunction alternate function to parse frontmatter, default: gray-matter
    • opts.encodingString – encoding of files, default:utf8
    • opts.filterString – glob pattern for filtering files, default:**\/*.md
    • opts.ignoreString – glob pattern for ignoring files
    • opts.ignoreArray – array of glob patterns for ignoring files
    • opts.dirnamesBoolean – include or exclude subdirectory names in keys of returned object, default:false
    • opts.transformFunction – 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)})

parseDirSync

Read the contents of a directory and convert to Markdown synchronously

Parameters

  • dirString – The directory to read
  • optsObject
    • opts.mdFunction alternate function to parse markdown, default: commonmark
    • opts.frontmatterFunction alternate function to parse frontmatter, default: gray-matter
    • opts.encodingString – encoding of files, default:utf8
    • opts.filterString – glob pattern for filtering files, default:**\/*.md
    • opts.ignoreString – glob pattern for ignoring files
    • opts.ignoreArray – array of glob patterns for ignoring files
    • opts.dirnamesBoolean – include or exclude subdirectory names in keys of returned object, default:false
    • opts.transformFunction – A function you can use to transform the contents of files after they are converted

Examples

varmd=require('md-directory')varcontents=md.parseDirSync('./posts')

parse

Read the contents of a file and convert to Markdown asynchronously

Parameters

  • filenameString – The filename to read
  • optsObject
    • opts.mdFunction alternate function to parse markdown, default: commonmark
    • opts.frontmatterFunction alternate function to parse frontmatter, default: gray-matter
    • opts.encodingString – encoding of files, default:utf8
    • opts.transformFunction – 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)})

parseSync

Read the contents of a file and convert to Markdown synchronously

Parameters

  • filenameString – The filename to read
  • optsObject
    • opts.mdFunction alternate function to parse markdown, default: commonmark
    • opts.frontmatterFunction alternate function to parse frontmatter, default: gray-matter
    • opts.encodingString – encoding of files, default:utf8
    • opts.transformFunction – 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')

See also

License

MIT

About

📂 Convert a directory of Markdown files to HTML

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp