m2i
A markdown to image parser
Last updated 7 months ago by zce .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install m2i 
SYNC missed versions from official npm registry.

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 © 汪磊

Current Tags

  • 0.2.0                                ...           latest (5 months ago)

2 Versions

  • 0.2.0                                ...           5 months ago
  • 0.1.0                                ...           7 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 1
Dependencies (5)
Dev Dependencies (1)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |