# marp-core
**Repository Path**: stdu-jtxy_liwx/marp-core
## Basic Information
- **Project Name**: marp-core
- **Description**: The core of Marp converter
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: main
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2021-08-31
- **Last Updated**: 2021-08-31
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# @marp-team/marp-core
[](https://circleci.com/gh/marp-team/marp-core/)
[](https://codecov.io/gh/marp-team/marp-core)
[](https://www.npmjs.com/package/@marp-team/marp-core)
[](./LICENSE)
**The core of [Marp](https://github.com/marp-team/marp) converter.**
In order to use on Marp tools, we have extended from the slide deck framework **[Marpit](https://github.com/marp-team/marpit)**. You can use the practical Markdown syntax, advanced features, and official themes.
## Usage
We provide `Marp` class, that is inherited from [Marpit](https://github.com/marp-team/marpit).
```javascript
import Marp from '@marp-team/marp-core'
// Convert Markdown slide deck into HTML and CSS
const marp = new Marp()
const { html, css } = marp.render('# Hello, marp-core!')
```
## Features
_We will only explain features extended in marp-core._ Please refer to [@marp-team/marpit](https://github.com/marp-team/marpit) repository if you want to know the basic feature of Marpit framework.
### Marp Markdown
Marp Markdown is based on [Marpit](https://github.com/marp-team/marpit) and [CommonMark](https://commonmark.org/), and there are these additional features:
- **Marpit**
- Enable [inline SVG mode](https://github.com/marp-team/marpit#inline-svg-slide-experimental) and loose YAML parsing by default.
* **CommonMark**
- For security reason, HTML tag only allows `
` by default.
- Support [table](https://github.github.com/gfm/#tables-extension-) and [strikethrough](https://github.github.com/gfm/#strikethrough-extension-) syntax, based on [GitHub Flavored Markdown](https://github.github.com/gfm/).
- Line breaks in paragraph will convert to `
` tag.
- Auto convert URL like text into hyperlink.
### [Built-in official themes][themes]
We provide bulit-in official themes for Marp. See more details in [themes].
| Default | Gaia | Uncover |
| :-----------------------------------: | :-----------------------------------: | :-----------------------------------: |
| [][themes] | [][themes] | [][themes] |
| `` | `` | `` |
[themes]: ./themes/
### `size` global directive
Do you want a traditional 4:3 slide size? We've added the support of `size` global directive only for Marp Core. Our extended theming system can use `960`x`720` slide in built-in themes easier: `size: 4:3`.
```markdown
---
theme: gaia
size: 4:3
---
# A traditional 4:3 slide
```
If you want to use more size presets in your theme, you have to define `@size` metadata(s) in theme CSS. [Learn in the document of theme metadata for Marp Core][metadata].
Theme author does not have to worry an unintended design being used with unexpected slide size because user only can use pre-defined presets by author.
[metadata]: ./themes#metadata-for-additional-features
### Emoji support
Emoji shortcode (like `:smile:`) and Unicode emoji 😄 will convert into the SVG vector image provided by [twemoji](https://github.com/twitter/twemoji)
. It could render emoji with high resolution.
### Math typesetting
We have [Pandoc's Markdown style](https://pandoc.org/MANUAL.html#math) math typesetting support. Surround your formula by `$...$` to render math as inline, and `$$...$$` to render as block.
| Markdown |
Rendered slide |
|
```tex
Render inline math such as $ax^2+bc+c$.
$$ I_{xx}=\int\int_Ry^2f(x,y)\cdot{}dydx $$
$$
f(x) = \int_{-\infty}^\infty
\hat f(\xi)\,e^{2 \pi i \xi x}
\,d\xi
$$
```
|

|
You can choose using library for math from [KaTeX](https://khan.github.io/KaTeX/) and [MathJax](https://www.mathjax.org/) in [`math` global directive](#math-global-directive) (or [JS constructor option](#math-constructor-option)). By default, we prefer KaTeX for compatibility and performance, but MathJax has better rendering and syntax support than KaTeX.
#### `math` global directive
Through `math` global directive, Marp Core is supporting to declare math library that will be used within current Markdown.
Set **`katex`** or **`mathjax`** in the `math` global directive like this:
```markdown
---
# Declare to use MathJax in this Markdown
math: mathjax
---
$$
\begin{align}
x &= 1+1 \tag{1} \\
&= 2
\end{align}
$$
```
If not declared, Marp Core will use the default library to render math (KaTeX in v2).
We may change the default in the future and would break existing slides, so recommend to declare the library whenever to use math typesetting.
> :warning: The declaration of math library is given priority over [`math` JS constructor option](#math-constructor-option), but you cannot turn on again via `math` global directive if disabled math typesetting by the constructor.
### Auto-scaling features
Auto-scaling is available only if enabled [Marpit's `inlineSVG` mode](https://github.com/marp-team/marpit#inline-svg-slide-experimental) and defined [`@auto-scaling` metadata][metadata] in an using theme CSS.
```css
/*
* @theme enable-all-auto-scaling
* @auto-scaling true
*/
```
Marp Core's scaling features will be realized by manipulating the original DOM to use inline SVG. So the theme author must take care of updated DOM in styling. Refer to [the source code of offical themes][themes].
`@auto-scaling` meta can also pick the favorite features to enable by using keyword(s).
```css
/*
* @theme enable-auto-scaling-for-fitting-header-and-math
* @auto-scaling fittingHeader,math
*/
```
> :warning: In the math block and the code block, Marp Core won't detect whether they actually protrude from the slide. It might not work scaling correctly when there are many elements in a slide.
#### Fitting header
When the headings contains `` comment, the size of headings will resize to fit onto the slide size.
```markdown
# Fitting header
```
This syntax is similar to [Deckset's `[fit]` keyword](https://docs.decksetapp.com/English.lproj/Formatting/01-headings.html), but we use HTML comment to hide a fit keyword on Markdown rendered as document.
> :information_source: `@auto-scaling fittingHeader` is a keyword of the `@auto-scaling` meta to enable fitting header.
#### KaTeX Math block
We can scale-down the viewing size of KaTeX math block (surrounded by `$$`) to fit a slide automatically.
| Traditional rendering | Auto-scaling |
| :----------------------------------------------: | :-------------------------------------: |
|  |  |
> :information_source: `@auto-scaling math` is a keyword of the `@auto-scaling` meta to enable math block scaling.
>
> _Please notice that the math block rendered by MathJax would always be scaled-down and cannot control whether scale via metadata._
#### Code block
Several themes also can scale-down the viewing size of the code block to fit a slide.
| Traditional rendering | Auto-scaling |
| :----------------------------------------------: | :-------------------------------------: |
|  |  |
These features means that the contents on a slide are not cropped, and not shown unnecessary scrollbars in code.
> :information_source: `@auto-scaling code` is a keyword of the `@auto-scaling` meta to enable code block scaling.
>
> `uncover` theme has disabled code block scaling because we use elastic style that has not compatible with it.
## Constructor options
You can customize a behavior of Marp parser by passing an options object to the constructor. You can also pass together with [Marpit constructor options](https://marpit-api.marp.app/marpit#Marpit).
> :information_source: [Marpit's `markdown` option](https://marpit-api.marp.app/marpit#Marpit) is accepted only object options because of always using CommonMark.
```javascript
const marp = new Marp({
// marp-core constructor options
html: true,
emoji: {
shortcode: true,
unicode: false,
twemoji: {
base: '/resources/twemoji/',
},
},
math: 'mathjax',
minifyCSS: true,
script: {
source: 'cdn',
nonce: 'xxxxxxxxxxxxxxx',
},
// It can be included Marpit constructor options
looseYAML: false,
markdown: {
breaks: false,
},
})
```
### `html`: _`boolean`_ | _`object`_
Setting whether to render raw HTML in Markdown. It's an alias to `markdown.html` ([markdown-it option](https://markdown-it.github.io/markdown-it/#MarkdownIt.new)) but has additional feature about HTML allowlist.
- `true`: The all HTML will be allowed.
- `false`: All HTML except supported in Marpit Markdown will be disallowed.
By passing `object`, you can set the allowlist to specify allowed tags and attributes.
```javascript
// Specify tag name as key, and attributes to allow as string array.
{
a: ['href', 'target'],
br: [],
}
```
```javascript
// You may use custom attribute sanitizer by passing object.
{
img: {
src: (value) => (value.startsWith('https://') ? value : '')
}
}
```
Marp core allows only `
` tag by default, that is defined in [`Marp.html`](https://github.com/marp-team/marp-core/blob/5c3593320f1c1234f3b2556ecd1ff1f91d69c77a/src/marp.ts#L45).
Whatever any option is selected, `` and `