Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docs to explain usage of plugin #120

Merged
merged 2 commits into from
Jan 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Add `env` argument to [`Marpit.render()`](https://marpit-api.marp.app/marpit#render) ([#118](https://github.com/marp-team/marpit/pull/118))
- Output HTML per slide page as array by passing `htmlAsArray` env ([#119](https://github.com/marp-team/marpit/pull/119))
- Update docs to explain SVG slide polyfill ([#117](https://github.com/marp-team/marpit/pull/117))
- Update docs to explain usage of plugin ([#120](https://github.com/marp-team/marpit/pull/120))

## v0.5.0 - 2018-12-28

Expand Down
Binary file added docs/assets/plugin-custom-container.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,48 @@ The returned value is a two-dimensional array composed by comments per slide pag
]
```

### Extend Marpit by plugins

You can extend Marpit Markdown parser by [`marpit.use()`](https://marpit-api.marp.app/marpit#use) with [markdown-it plugin](https://www.npmjs.com/search?q=keywords:markdown-it-plugin).

Due to our policy, Marpit has not extended Markdown syntax such as to break CommonMark. But you may use plugins if you want the aggressive extended syntax.

For example, let's say you want to use the custom container by [markdown-it-container](https://github.com/markdown-it/markdown-it-container) to support multi-column block.

```javascript
const { Marpit } = require('@marp-team/marpit')
const markdownItContainer = require('markdown-it-container')

// Create the extended Marpit instance
const marpit = new Marpit().use(markdownItContainer, 'columns')

// Setting default theme for styling multi-column
marpit.themeSet.default = marpit.themeSet.add(`
/* @theme custom-container */
section { padding: 50px; }
.columns { column-count: 2; }
`)

// Render HTML and CSS from Markdown that includes custom container
const { html, css } = marpit.render(`
::: columns
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Perspiciatis
perferendis, dolorem amet adipisci quas rem iusto excepturi ipsam aperiam quo
expedita totam a laborum ut voluptatibus voluptate fugit voluptatem eum?
:::
`)
```

You're ready to use multi-column through custom container! The rendered slide is as follows.

<p align="center">

[<img src="/assets/plugin-custom-container.png" alt="Rendered custom container" style="box-shadow:0 5px 15px #ccc;max-height:720px;" />](/assets/plugin-custom-container.png)

</p>

!> Marpit has already many extends to support converting Markdown into slide deck. So some markdown-it plugins that are not created for Marpit would not work as expected because of existing extends.

## Full API documentation

The documentation of Marpit API, created by JSDoc, is hosted on another site. Please refer to **[https://marpit-api.marp.app/](https://marpit-api.marp.app/)**.