Miss any of our Open RFC calls?Watch the recordings here! »

m2i

0.2.0 • Public • Published

m2i

Build Status NPM Downloads NPM Version License Dependency Status devDependency Status Code Style

A minimalist markdown to image converter

Installation

$ npm install m2i
 
# or yarn 
$ yarn add m2i

People in China can use npm.taobao.org mirror to increase installation speed.

.npmrc

# other configs 
puppeteer_download_host = https://npm.taobao.org/mirrors

or env

$ PUPPETEER_DOWNLOAD_HOST=https://npm.taobao.org/mirrors npm i m2i

Usage

const m2i = require('m2i')
 
await m2i('./readme.md')
// readme.md => readme.png
 
await m2i('./readme.md', { 
  output: './foo.png', 
  width: 1280 
})
// readme.md => foo.png

API

m2i(input[, options])

input

  • Type: string
  • Details: markdown file path

options

output
  • Type: string
  • Details: output image path
  • Default: '<input>.png'
width
  • Type: number
  • Details: output image width
  • Default: 800

CLI Usage

$ npm install m2i -g
 
# or yarn  
$ yarn global add m2i
$ m2i --help
Usage: m2i <input>
 
Options:
  -V, --version          output the version number
  -o, --output <output>  output filename
  -w, --width <width>    output image width
  -h, --help             display help for command
 
Example:
  $ m2i example.md -o output.png -w 800

or use npx

$ npx m2i example.md -o output.png -w 800

Advanced Usage

By default, the conversion process of markdown does not do extra things. If you want to change the output format, you can customize the template of markdown or HTML in the configuration file.

This is good for customizing some shared content, or import custom style file.

.m2irc example:

markdown: |
  ${content.trim()}
 
  ## License
 
  Licensed under the MIT License.
html: |
  <link rel="stylesheet" href="https://unpkg.com/github-markdown-css">
  <article class="markdown-body" style="padding: 2.5em">
  ${content.trim()}
  </article>

This configuration file is loaded through cosmoconfig, so you can place the corresponding file according to its rules, such as ~/.m2irc.

Recipes

Code highlighting

Code highlighting through Prism.

.m2irc

html: |
  <link rel="stylesheet" href="https://unpkg.com/github-markdown-css">
  <link rel="stylesheet" href="https://unpkg.com/prismjs/themes/prism-okaidia.css">
  <article class="markdown-body" style="padding: 2.5em">${content.trim()}</article>
  <script src="https://unpkg.com/prismjs"></script>

Contributing

  1. Fork it on GitHub!
  2. Clone the fork to your own machine.
  3. Checkout your feature branch: git checkout -b my-awesome-feature
  4. Commit your changes to your own branch: git commit -am 'Add some feature'
  5. Push your work back up to your fork: git push -u origin my-awesome-feature
  6. Submit a Pull Request so that we can review your changes.

NOTE: Be sure to merge the latest from "upstream" before making a pull request!

License

MIT © 汪磊

Install

npm i m2i

DownloadsWeekly Downloads

3

Version

0.2.0

License

MIT

Unpacked Size

373 kB

Total Files

7

Last publish

Collaborators

  • avatar