npm 中文文档 npm 中文文档
指南
npmjs.com (opens new window)
指南
npmjs.com (opens new window)
  • 快速入门

    • npm 是什么?
    • npm 安装和更新
    • npm 防止权限错误
    • npm package.json 文件
    • npm 安装包
    • npm 更新包
    • npm 卸载包
    • npm 创建 Node.js 模块
    • npm 发布和更新包
    • npm 使用语义化版本
    • npm 使用 Dist-tags 标记包
    • npm 包和模块的了解
  • 命令行
  • 配置 npm

@marp-team/marp-cli


A CLI interface, for Marp (using @marp-team/marp-core ) and any slide deck converter based on Marpit framework.

It can convert Marp / Marpit Markdown files into static HTML / CSS, PDF, PowerPoint document, and image(s) easily.

Try it now!


npx


npx (npm exec) is the best way to use the latest Marp CLI if you wanted one-shot Markdown conversion without install. Just run below if you have installed Node.js 14 and later.

  1. ``` shell
  2. # Convert slide deck into HTML
  3. npx @marp-team/marp-cli@latest slide-deck.md
  4. npx @marp-team/marp-cli@latest slide-deck.md -o output.html

  5. # Convert slide deck into PDF
  6. npx @marp-team/marp-cli@latest slide-deck.md --pdf
  7. npx @marp-team/marp-cli@latest slide-deck.md -o output.pdf

  8. # Convert slide deck into PowerPoint document (PPTX)
  9. npx @marp-team/marp-cli@latest slide-deck.md --pptx
  10. npx @marp-team/marp-cli@latest slide-deck.md -o output.pptx

  11. # Watch mode
  12. npx @marp-team/marp-cli@latest -w slide-deck.md

  13. # Server mode (Pass directory to serve)
  14. npx @marp-team/marp-cli@latest -s ./slides
  15. ```

ℹ️You have to install Google Chrome or Microsoft Edge to convert slide deck into PDF, PPTX, and image(s).


Docker


Don't you like installing Node.js and Chrome to local? We have an official Docker image marpteam/marp-cli ready to use CLI.

Please refer how to use at Docker Hub.

Install


Use package manager


You can use the package manager to install and update Marp CLI easily.

Disclaimer: Package manifests are maintained by the community, not Marp team.

macOS: Homebrew


  1. ``` shell
  2. brew install marp-cli
  3. ```

Windows: Scoop


  1. ``` batchfile
  2. scoop install marp
  3. ```

Local installation


We recommend to install Marp CLI into your Node.js project. You may control the CLI version (and engine if you want) exactly.

ℹ️Marp CLI is working only with actively supported Node.js versions, so Node.js 14 and later is required when installing into your Node.js project.


  1. ``` shell
  2. npm install --save-dev @marp-team/marp-cli
  3. ```

The installed marp command is available in npm-scripts or npx marp.

Global installation


You can install with -g option if you want to use marp command globally.

  1. ``` shell
  2. npm install -g @marp-team/marp-cli
  3. ```

Standalone binary


We also provide standalone binaries for Linux, macOS, and Windows. These have bundled Marp CLI with Node.js binary, so no need to install Node.js separately.

⏩ Download the latest standalone binary from release page.

Basic usage


Convert to HTML


The passed markdown will be converted to HTML file by default. In the below example, a converted slide-deck.html will output to the same directory.

  1. ``` shell
  2. marp slide-deck.md
  3. ```

You can change the output path by --output (-o ) option.

  1. ``` shell
  2. marp slide-deck.md -o output.html
  3. ```

Marp CLI supports converting multiple files by passing multiple paths, directories, and glob patterns. In this case, --output option cannot use.

When you want to output the converted result to another directory with keeping the origin directory structure, you can use --input-dir (-I ) option. --output option would be available for specify the output directory.

Convert to PDF (--pdf)


If you passed --pdf option or the output filename specified by --output (-o ) option ends with .pdf, Marp CLI will try to convert Markdown into PDF file through the browser.

  1. ``` shell
  2. marp --pdf slide-deck.md
  3. marp slide-deck.md -o converted.pdf
  4. ```

All kind of conversions except HTML require to install Google Chrome, Microsoft Edge, or Chromium (flavored) browser.When an unexpected problem has occurred while converting, please update your browser to the latest version or try installing Google Chrome Canary.

ℹ️If you want to use Chromium or flavored browsers to convert, you have to specify the path to the browser binary through CHROME_PATH environment variable. For example: CHROME_PATH=$(which brave) marp --pdf slide-deck.md


PDF output options


--pdf-notes * : Add PDF note annotations to the lower left when the slide page has Marpit presenter notes.
--pdf-outlines * : Add PDF outlines/bookmarks.

--pdf-outlines will make outlines based on slide pages and Markdown headings by default. If necessary, you may prevent making outlines from one of them, by setting --pdf-outlines.pages=false or --pdf-outlines.headings=false.

Convert to PowerPoint document (--pptx)


Do you want more familiar way to present and share your deck? PPTX conversion to create PowerPoint document is available by passing --pptx option or specify the output path with PPTX extension.

  1. ``` shell
  2. marp --pptx slide-deck.md
  3. marp slide-deck.md -o converted.pptx
  4. ```

A created PPTX includes rendered Marp slide pages and the support of Marpit presenter notes. It can open with PowerPoint, Keynote, Google Slides, LibreOffice Impress, and so on...

ℹ️A converted PPTX consists of pre-rendered images. Please note that contents would not be able to modify or re-use in PowerPoint.


Convert to PNG/JPEG image(s)


Multiple images (--images)


You can convert the slide deck into multiple images when specified --images [png|jpeg] option.

  1. ``` shell
  2. # Convert into multiple PNG image files
  3. marp --images png slide-deck.md

  4. # Convert into multiple JPEG image files
  5. marp --images jpeg slide-deck.md
  6. ```

Output files have a suffix of page number, like slide-deck.001.png, slide-deck.002.png, and so on.

Title slide (--image)


When you passed --image option or specified the output path with PNG/JPEG extension, Marp CLI will convert only the first page (title slide)of the targeted slide deck into an image.

  1. ``` shell
  2. # Convert the title slide into an image
  3. marp --image png slide-deck.md
  4. marp slide-deck.md -o output.png
  5. ```

It would be useful for creating Open Graph image that can specify with image global directive and --og-image option.

Scale factor


You can set the scale factor for rendered image(s) through --image-scale option. It is useful for making high-resolution image from the slide.

  1. ``` shell
  2. # Generate high-resolution image of the title slide
  3. marp slide-deck.md -o title-slide@2x.png --image-scale 2
  4. ```

ℹ️--image-scale is not affect to the actual size of presentation.


It is also available for PPTX conversion. By default, Marp CLI will use 2 as the default scale factor in PPTX to suppress deterioration of slide rendering in full-screen presentation.

Export presenter notes (--notes)


You can export presenter notes in Marp / Marpit Markdown as a text file by using --notes option or specifying the output path with TXT extension.

  1. ``` shell
  2. # Export presenter notes as a text
  3. marp --notes slide-deck.md
  4. marp slide-deck.md -o output.txt
  5. ```

Security about local files


Because of the security reason, PDF, PPTX and image(s) conversion cannot use local files by default.

Marp CLI would output incompleted result with warning if the blocked local file accessing is detected. We recommend uploading your assets to online.

If you really need to use local files in these conversion, --allow-local-files option helps to find your local files. Please use only to the trusted Markdown because there is a potential security risk.

  1. ``` shell
  2. marp --pdf --allow-local-files slide-deck.md
  3. ```

Conversion modes


Watch mode (--watch / -w)


Marp CLI will observe a change of Markdown and using theme CSS when passed with --watch (-w ) option. The conversion will be triggered whenever the content of file is updated.

While you are opening the converted HTML in browser, it would refresh the opened page automatically.

Server mode (--server / -s)


Server mode supports on-demand conversion by HTTP request. We require to pass --server (-s ) option and a directory to serve.

In this mode, the converted file outputs as the result of accessing to server, and not to disk. You can set the server port by setting the environment variable PORT, for example PORT=5000 marp -s ./slides would listen on port number 5000.

You would get the converted PDF, PPTX, PNG, and JPEG by adding corresponded query string when requesting. e.g. http://localhost:8080/deck-a.md?pdf returns converted PDF.

index.md / PITCHME.md


Marp CLI server will provide the list of served files by default, but you can place the default Markdown deck like a common web server's index.html.

Place Markdown named index.md or PITCHME.md (GitPitch style ) to served directory. It would be redirected just accessing to http://localhost:8080/.

Preview window (--preview / -p)


When conversions were executed together with --preview (-p ) option, Marp CLI will open preview window(s) to check the converted result immediately.

Unlike opening with browser, you may present deck with the immersive window. Watch mode is automatically enabled while using preview window.

ℹ️--preview option cannot use when you are using Marp CLI through official docker image.


Template


You can choose a built-in HTML templates by --template option. Default template is bespoke.

  1. ``` shell
  2. marp --template bespoke slide-deck.md
  3. ```

bespoke template (default)


The bespoke template is using Bespoke.js as the name implies. It has several features to be useful in a real presentation. A few features may control by CLI options.

Features


Navigation: Navigate the deck through keyboard and swipe geasture.
Fullscreen: Toggle fullscreen by hitting f/ F11key.
On-screen controller: There is a touch-friendly OSC. You may also disable by --bespoke.osc=false if unneccesary.
Fragmented list: Recognize Marpit's fragmented list and appear list one-by-one if used * and 1) as the bullet marker.
Presenter view: Open presenter view in external window by hitting pkey.
Progress bar(optional): By setting --bespoke.progress option, you can add a progress bar on the top of the deck.
Slide transitions : Support transitions (transition local directive) powered by View Transitions API.

ℹ️Presenter view may be disabled if the browser restricted using localStorage (e.g. Open HTML in the old Safari with private browsing, or open the localHTML file with Chrome that has blocked 3rd party cookies in chrome://settings/content/cookies ).


Docs


Slide transitions in bespoke template * Learn all about of slide transitions for bespoke template: Built-in transitions, custom transitions, and morphing animations.

bare template


The bare template is a primitive template, and there is no extra features. It only has minimum assets to give your presentation with browser.

Zero-JS slide deck


When the conversion engine is changed to Marpit framework by setting engine option, it would not use any scripts.Even then, it has enough to use for the browser-based presentation.

  1. ``` shell
  2. marp --template bare --engine @marp-team/marpit slide-deck.md
  3. ```

Metadata


Through global directives or CLI options, you can set metadata for a converted HTML, PDF, and PPTX slide deck.

Global directives CLI option Description Available in
:--- :--- :---
title --title Define title of the slide deck HTML, PDF, PPTX
description --description Define description of the slide HTML, PDF, PPTX
author --author Define author of the slide deck HTML, PDF, PPTX
keywords --keywords Define comma-separated keywords HTML, PDF
url --url Define canonical URL * HTML
image --og-image Define Open Graph image URL HTML

*: If could not parse a specified value as valid, the URL will be ignored.


By global directives


Marp CLI supports additional global directives to specify metadata in Markdown. You can define meta values in Markdown front-matter.

  1. ``` gfm
  2. ---
  3. title: Marp slide deck
  4. description: An example slide deck created by Marp CLI
  5. author: Yuki Hattori
  6. keywords: marp,marp-cli,slide
  7. url: https://marp.app/
  8. image: https://marp.app/og-image.jpg
  9. ---

  10. # Marp slide deck
  11. ```

By CLI option


Marp CLI prefers CLI option to global directives. You can override metadata values by --title, --description, --author, --keywords, --url, and --og-image.

Theme


Override theme


You can override theme you want to use by --theme option. For example to use Gaia built-in theme in Marp Core:

  1. ``` shell
  2. marp --theme gaia
  3. ```

Use custom theme


A custom theme created by user also can use easily by passing the path of CSS file.

  1. ``` shell
  2. marp --theme custom-theme.css
  3. ```

ℹ️Normally Marpit theme CSS requires @theme meta comment, but it's not required in this usage.


Theme set


--theme-set option has to specify theme set composed by multiple theme CSS files. The registed themes are usable in Marpit's theme directive.

  1. ``` shell
  2. # Multiple theme CSS files
  3. marp --theme-set theme-a.css theme-b.css theme-c.css -- deck-a.md deck-b.md

  4. # Theme directory
  5. marp --theme-set ./themes -- deck.md
  6. ```

Engine


Marp CLI is calling the Marpit framework based converter as "Engine". Normally we use the bundled Marp Core, but you may swap the conversion engine to another Marpit based engine through --engine option.

You can use Marp (and compatible markdown-it) plugins while converting, or completely swap the converter to the other Marpit-based engine which published to npm.

Use Marpit framework


For example, you can convert Markdown with using the pure Marpit framework.

  1. ``` shell
  2. # Install Marpit framework
  3. npm i @marp-team/marpit

  4. # Specify engine to use Marpit
  5. marp --engine @marp-team/marpit marpit-deck.md
  6. ```

Notice that Marpit has not provided theme. It would be good to include inline style in Markdown, or pass CSS file by --theme option.

If you want to use the Marpit-based custom engine by the module name, the specified module must be exporting a class inherited from Marpit as the default export.


Functional engine


When you specified the path to JavaScript file (.js, .cjs, or .mjs ) in --engine option, you may use more customized engine by a JavaScript function.

Spec


The functional engine should export a function as the default export, which should have a single argument representing the constructor option of Marpit /Marp Core.

The function must return a class inherited from Marpit, or an instance of Marpit-based engine made by the parameter passed by argument.

  1. ``` js
  2. // engine.mjs (ES modules)
  3. import { MarpitBasedEngine } from 'marpit-based-engine'

  4. export default () => MarpitBasedEngine // Return a class inherited from Marpit
  5. ```

  1. ``` js
  2. // engine.cjs (CommonJS)
  3. const { MarpitBasedEngine } = require('marpit-based-engine')

  4. module.exports = function (constructorOptions) {
  5.   // Return an instance of Marpit initialized by passed constructor options
  6.   return new MarpitBasedEngine(constructorOptions)
  7. }
  8. ```

This function can return Promise object so you can use async function to
Last Updated: 2023-08-23 08:37:36