======================== CODE SNIPPETS ======================== TITLE: Marpit Development Setup DESCRIPTION: Commands to clone the Marpit repository, navigate into the project directory, install dependencies using npm, and build the project. SOURCE: https://github.com/marp-team/marpit/blob/main/README.md#_snippet_0 LANGUAGE: bash CODE: ``` git clone https://github.com/marp-team/marpit cd marpit npm install npm run build ``` ---------------------------------------- TITLE: Install Marpit using npm, yarn, or pnpm DESCRIPTION: Marpit can be installed using common package managers like npm, yarn, or pnpm. This step is necessary to add the Marpit library to your project's dependencies. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/introduction.md#_snippet_0 LANGUAGE: bash CODE: ``` npm install @marp-team/marpit ``` LANGUAGE: bash CODE: ``` yarn add @marp-team/marpit ``` LANGUAGE: bash CODE: ``` pnpm add @marp-team/marpit ``` ---------------------------------------- TITLE: Import Marpit Class (Default Export) DESCRIPTION: Demonstrates importing the default Marpit class using ES module syntax. This is the standard way to get the main Marpit functionality. SOURCE: https://github.com/marp-team/marpit/blob/main/api.md#_snippet_0 LANGUAGE: javascript CODE: ``` import Marpit from '@marp-team/marpit' ``` ---------------------------------------- TITLE: Marpit CLI Command for Generating Presentations DESCRIPTION: Shows how to use the Marp CLI to generate a presentation from a Markdown file using Marpit. This example specifies a bare template and the Marpit engine, producing minimal HTML and CSS output. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/inline-svg.md#_snippet_2 LANGUAGE: bash CODE: ``` npm i -g @marp-team/marp-cli npm i @marp-team/marpit marp --template bare --engine @marp-team/marpit marpit-deck.md ``` ---------------------------------------- TITLE: Use Marpit to Render Markdown to HTML DESCRIPTION: This example demonstrates how to use the Marpit library in JavaScript to convert Markdown content into an HTML slide deck. It involves creating a Marpit instance, defining a theme, rendering the Markdown, and saving the output to an HTML file. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/introduction.md#_snippet_1 LANGUAGE: javascript CODE: ``` import Marpit from '@marp-team/marpit' import fs from 'fs' // 1. Create instance (with options if you want) const marpit = new Marpit() // 2. Add theme CSS const theme = ` /* @theme example */ section { background-color: #369; color: #fff; font-size: 30px; padding: 40px; } h1, h2 { text-align: center; margin: 0; } h1 { color: #8cf; } ` marpit.themeSet.default = marpit.themeSet.add(theme) // 3. Render markdown const markdown = ` # Hello, Marpit! Marpit is the skinny framework for creating slide deck from Markdown. --- ## Ready to convert into PDF! You can convert into PDF slide deck through Chrome. ` const { html, css } = marpit.render(markdown) // 4. Use output in your HTML const htmlFile = ` ${html} ` fs.writeFileSync('example.html', htmlFile.trim()) ``` ---------------------------------------- TITLE: Interactive SVG Example with Resizable Container DESCRIPTION: A live example demonstrating how resizing an SVG container affects the slide's background. It uses inline styles and a resizable div to showcase the effect of the `::backdrop` CSS selector on the SVG element. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/inline-svg.md#_snippet_5 LANGUAGE: html CODE: ```
``` ---------------------------------------- TITLE: Basic CSS Theme Definition DESCRIPTION: An example of a basic Marpit theme CSS file. It defines styles for the main slide container (`section`) and heading elements (`h1`, `h2`), setting dimensions, font sizes, and colors. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/theme-css.md#_snippet_1 LANGUAGE: css CODE: ``` /* @theme marpit-theme */ section { width: 1280px; height: 960px; font-size: 40px; padding: 40px; } h1 { font-size: 60px; color: #09c; } h2 { font-size: 50px; } ``` ---------------------------------------- TITLE: Marpit Custom Local Directive DESCRIPTION: Illustrates how to create a custom local directive in Marpit using JavaScript. This example defines a `colorPreset` directive that maps specific string values (like 'sunset' or 'dark') to predefined `backgroundColor` and `color` styles, simplifying complex style application. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/directives.md#_snippet_15 LANGUAGE: javascript CODE: ``` marpit.customDirectives.local.colorPreset = (value, marpit) => { switch (value) { case 'sunset': return { backgroundColor: '#e62e00', color: '#fffff2' } case 'dark': return { backgroundColor: '#303033', color: '#f8f8ff' } default: // Return an empty object if not have to assign new values return {} } } ``` ---------------------------------------- TITLE: Slide Styling with CSS DESCRIPTION: Example CSS rule demonstrating how a custom class can be used to style slide elements. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/directives.md#_snippet_11 LANGUAGE: CSS CODE: ``` section.lead h1 { text-align: center; } ``` ---------------------------------------- TITLE: Split background with size (left:33%) - Marpit Markdown DESCRIPTION: Specifies a custom width for a split background using percentage values. This example sets the left background to occupy 33% of the slide width. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/image-syntax.md#_snippet_8 LANGUAGE: markdown CODE: ``` ![bg left:33%](https://picsum.photos/720?image=27) # Split backgrounds with specified size ``` ---------------------------------------- TITLE: Marpit Custom Global Directive DESCRIPTION: Shows how to define a custom global directive in Marpit using JavaScript. This example creates a `$theme` directive that acts as an alias for the built-in `theme` directive, allowing users to specify themes via a custom syntax in Markdown. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/directives.md#_snippet_14 LANGUAGE: javascript CODE: ``` marpit.customDirectives.global.$theme = (value, marpit) => { return { theme: value } } ``` ---------------------------------------- TITLE: Create Marpit Instance DESCRIPTION: Demonstrates how to import and create a basic instance of the Marpit class. This is the first step to using the library for Markdown conversion. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/usage.md#_snippet_0 LANGUAGE: javascript CODE: ``` const { Marpit } = require('@marp-team/marpit') // Create Marpit instance const marpit = new Marpit() ``` ---------------------------------------- TITLE: Marpit Core API Methods DESCRIPTION: Documentation for core Marpit API methods, including `render` for processing Markdown and `use` for applying markdown-it plugins. This section outlines their purpose, parameters, and return values. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/usage.md#_snippet_12 LANGUAGE: APIDOC CODE: ``` Marpit: __constructor() Initializes a new Marpit instance. render(markdown: string, options?: object): { html: string, css: string, comments: string[][], instance: Marpit } Renders Markdown content into HTML and CSS. - markdown: The input Markdown string. - options: Optional configuration for rendering. - Returns: An object containing rendered HTML, CSS, extracted comments, and the Marpit instance. use(plugin: Function, ...args: any[]): Marpit Applies a markdown-it plugin to the Marpit instance. - plugin: The markdown-it plugin function. - args: Additional arguments to pass to the plugin. - Returns: The Marpit instance for chaining. themeSet: Manages Marpit themes. - default: The default theme. - add(theme: string): Theme Adds a new theme to the theme set. - theme: The theme CSS string. - Returns: The added Theme object. ``` ---------------------------------------- TITLE: Marpit Constructor Options API DESCRIPTION: Provides an overview of the Marpit constructor options, referencing the official JSDoc for a comprehensive list. Key options include markdown parser settings, container customization, and experimental features like inline SVG. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/usage.md#_snippet_8 LANGUAGE: APIDOC CODE: ``` Marpit: __constructor(opts?: MarpitOptions) Options for Marpit instance. MarpitOptions: markdown?: markdown_it.Options Options for markdown-it initializer. See [markdown-it documentation](https://github.com/markdown-it/markdown-it#init-with-presets-and-options). Example: markdown: { html: true, breaks: true } container?: Element | Element[] | false Custom container elements for scoping CSS. Defaults to `new Element('div', { class: 'marpit' })`. Can be `false` to disable containers. Example: container: [ new Element('article', { id: 'presentation' }), new Element('div', { class: 'slides' }) ] slideContainer?: Element | false Custom container element for each slide. Defaults to `null`. Example: slideContainer: new Element('div', { class: 'slide' }) inlineSVG?: boolean Enable inline SVG slide feature (experimental). Defaults to `false`. themeSet?: ThemeSet A ThemeSet instance to use. If not provided, a new ThemeSet is created. Element: __constructor(tagName: string, attributes?: { [key: string]: string }) Represents an HTML element with optional attributes. Example: new Element('div', { class: 'slide' }) ThemeSet: add(css: string): Theme Adds theme CSS to the set. Requires `@theme` meta comment in CSS. Returns the created Theme instance. default: Theme Sets the default theme to be applied automatically. ``` ---------------------------------------- TITLE: Marpit API Documentation DESCRIPTION: Documentation for Marpit's API, covering extended Markdown syntax for slide creation, CSS theming capabilities, and experimental features like inline SVG slides. Links to detailed API documentation are provided. SOURCE: https://github.com/marp-team/marpit/blob/main/README.md#_snippet_1 LANGUAGE: APIDOC CODE: ``` Marpit API Overview: This documentation outlines the features and capabilities of the Marpit framework for creating slide decks from Markdown. Key Features: 1. Marpit Markdown Extensions: - Description: Extends markdown-it parser with custom syntaxes for slide decks. - Features: Includes Directives for slide configuration and Slide backgrounds for visual customization. - Compatibility: Maintains compatibility with general Markdown documents. - Reference: https://marpit.marp.app/markdown 2. Theme CSS System: - Description: A CSS theming system allowing design of slides using pure CSS. - Approach: Focuses on styling HTML elements directly without predefined classes or mixins. - Conversion: Marpit handles the necessary conversion based on the selected theme. - Reference: https://marpit.marp.app/theme-css 3. Inline SVG Slide (Experimental): - Description: Option to use SVG elements as containers for individual slide pages. - Benefits: Enables pixel-perfect scaling via CSS and simplifies handling in integrated applications. - Advanced Backgrounds: Supports advanced backgrounds using while preserving DOM structure. - Reference: https://marpit.marp.app/inline-svg 4. Official API Documentation: - Reference: https://marpit-api.marp.app/ (JSDoc) ``` ---------------------------------------- TITLE: Header and Footer Directives DESCRIPTION: Shows how to use `header` and `footer` local directives to add consistent content to slides. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/directives.md#_snippet_9 LANGUAGE: Markdown CODE: ``` --- header: 'Header content' footer: 'Footer content' --- # Page 1 --- ## Page 2 ``` LANGUAGE: Markdown CODE: ``` --- header: '**bold** _italic_' footer: '![image](https://example.com/image.jpg)' --- NOTE: Wrap by (double-)quotes to avoid parsed as invalid YAML. ``` ---------------------------------------- TITLE: Custom Theme with CSS @import DESCRIPTION: Shows how to create a customized theme by importing a base theme using the CSS `@import` rule. This allows extending existing themes with new styles. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/theme-css.md#_snippet_8 LANGUAGE: css CODE: ``` /* @theme base */ section { background-color: #fff; color: #333; } ``` LANGUAGE: css CODE: ``` /* @theme customized */ @import 'base'; section { background-color: #f80; color: #fff; } ``` ---------------------------------------- TITLE: Render Markdown to HTML DESCRIPTION: Demonstrates the core functionality of Marpit: rendering Markdown content into HTML and CSS. The `render` method returns an object containing `html`, `css`, and `comments`. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/usage.md#_snippet_4 LANGUAGE: javascript CODE: ``` // Output rendered HTML, CSS, and collected HTML comments (See "Advanced") const { html, css, comments } = marpit.render('# Hello, Marpit!') ``` ---------------------------------------- TITLE: Marpit Render Method API DESCRIPTION: Details the `render` method of the Marpit class, which converts Markdown to HTML and CSS. It accepts an optional environment object for advanced rendering options like outputting HTML as an array. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/usage.md#_snippet_9 LANGUAGE: APIDOC CODE: ``` Marpit: render(markdown: string, env?: RenderEnv): RenderResult Converts Markdown string to HTML and CSS. Parameters: markdown: The Markdown content to render. env: Optional environment object for rendering options. Returns: RenderResult: An object containing the rendered HTML, CSS, and comments. RenderEnv: htmlAsArray?: boolean If true, the `html` property in RenderResult will be an array of strings, with each string representing a slide's HTML. Defaults to `false`. RenderResult: html: string | string[] The rendered HTML. Can be a single string or an array of strings if `htmlAsArray` is true. css: string The generated CSS for the slides. comments: string Collected HTML comments from the Markdown input. ``` ---------------------------------------- TITLE: Configure Markdown Parser DESCRIPTION: Shows how to customize the underlying markdown-it parser by passing options to the Marpit constructor. This allows enabling HTML tags or converting line breaks to `
`. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/usage.md#_snippet_1 LANGUAGE: javascript CODE: ``` const marpit = new Marpit({ markdown: { html: true, // Enable HTML tags breaks: true, // Convert line breaks into `
` }, }) ``` ---------------------------------------- TITLE: Extend Marpit with Markdown-it Plugins DESCRIPTION: Shows how to extend Marpit's Markdown parsing capabilities by integrating external markdown-it plugins, such as `markdown-it-container`, to add custom syntax like multi-column layouts. This involves creating a new Marpit instance and applying the plugin using `.use()`. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/usage.md#_snippet_11 LANGUAGE: javascript CODE: ``` 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? ::: `) ``` ---------------------------------------- TITLE: Docsify Configuration for Marpit DESCRIPTION: This snippet shows the configuration object for Docsify, a documentation site generator. It sets various options like repository link, logo, routing, sidebar loading, and plugin hooks for Marpit integration. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/index.html#_snippet_0 LANGUAGE: javascript CODE: ``` window.$docsify = { name: 'Marpit', repo: 'https://github.com/marp-team/marpit', logo: 'marpit.png', nameLink: '/', homepage: 'introduction.md', routerMode: 'history', auto2top: true, loadSidebar: true, subMaxLevel: 3, maxLevel: 4, pagination: { crossChapter: true }, plugins: [ (hook) => { // const tpl = document.getElementById('alert-for-marp-consumers') // hook.afterEach((html) => { // try { // const alertState = sessionStorage.getItem('marpit-alert') // if (alertState === 'read') return html // } catch (e) { // // ignore // } // return tpl.innerHTML + html // }) // hook.mounted(() => { // document.body.addEventListener('click', (e) => { // if (e.target.closest('[data-alert-close]')) { // e.preventDefault() // document // .querySelectorAll('.alert-for-marp-consumers') // .forEach((el) => el.remove()) // try { // sessionStorage.setItem('marpit-alert', 'read') // } catch (e) { // // ignore // } // } // }) // }) } ] } ``` ---------------------------------------- TITLE: Custom Theme with SCSS @import-theme DESCRIPTION: Illustrates creating a customized theme using SCSS and the `@import-theme` rule, which is useful when CSS preprocessors might interfere with standard `@import` paths. It allows dynamic styling based on variables. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/theme-css.md#_snippet_9 LANGUAGE: scss CODE: ``` $bg-color: #f80; $text-color: #fff; @import-theme 'base'; section { background: $bg-color; color: $text-color; } ``` ---------------------------------------- TITLE: Create Marpit Plugin DESCRIPTION: Provides a helper function `marpitPlugin` from `@marp-team/marpit/plugin` for creating Marpit-specific plugins. This helper ensures that the plugin has access to the Marpit instance via the `marpit` member. SOURCE: https://github.com/marp-team/marpit/blob/main/api.md#_snippet_2 LANGUAGE: javascript CODE: ``` import { marpitPlugin } from '@marp-team/marpit/plugin' export default marpitPlugin(({ marpit }) => { // Add your plugin code here (Add theme, define custom directives, etc...) /* marpit.customDirectives.local.yourDirective = (value) => { return { yourDirective: value } } */ }) ``` ---------------------------------------- TITLE: YAML Front-matter Directives DESCRIPTION: Demonstrates using YAML front-matter, enclosed by '---' rulers, as the primary method for defining global Marpit directives at the beginning of a Markdown file. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/directives.md#_snippet_1 LANGUAGE: Markdown CODE: ``` --- theme: default paginate: true --- # Slide Content Starts Here ``` ---------------------------------------- TITLE: Tweak Style via Markdown # Tweak style through Markdown You would see a yellow slide. ``` ---------------------------------------- TITLE: Add Theme CSS DESCRIPTION: Shows how to add custom theme CSS to the Marpit instance's `themeSet` using the `add` method. A `@theme` meta comment is required within the CSS for identification. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/usage.md#_snippet_5 LANGUAGE: javascript CODE: ``` const theme = marpit.themeSet.add(` /* @theme my-first-theme */ section { background-color: #123; color: #fff; font-size: 30px; padding: 40px; } h1 { color: #8cf; } `) ``` ---------------------------------------- TITLE: Set Default Theme DESCRIPTION: Explains how to set a default theme for Marpit by assigning a created `Theme` instance to the `themeSet.default` property. This theme will be applied without needing a directive. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/usage.md#_snippet_6 LANGUAGE: javascript CODE: ``` marpit.themeSet.default = marpit.themeSet.add('/* @theme default-theme */ section { color: black; }') ``` ---------------------------------------- TITLE: Resize Images with Width and Height Keywords in Markdown DESCRIPTION: Demonstrates how to resize images in Marpit presentations using width and height keywords within the image's alternative text. Supports pixel, length units, and shorthand notations like 'w' and 'h'. Inline images have specific limitations on allowed units. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/image-syntax.md#_snippet_0 LANGUAGE: markdown CODE: ``` ![width:200px](image.jpg) ![height:30cm](image.jpg) ![width:200px height:30cm](image.jpg) ![w:32 h:32](image.jpg) ``` ---------------------------------------- TITLE: Global Directives: Theme DESCRIPTION: Shows how to set the overall theme for the slide deck using the `theme` global directive. The theme name must correspond to a theme registered in the Marpit instance's `themeSet`. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/directives.md#_snippet_4 LANGUAGE: Markdown CODE: ``` ``` ---------------------------------------- TITLE: Enable Inline SVG Slide DESCRIPTION: Explains how to enable the experimental inline SVG slide feature by setting the `inlineSVG` option to `true` in the Marpit constructor. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/usage.md#_snippet_3 LANGUAGE: javascript CODE: ``` const marpit = new Marpit({ inlineSVG: true, }) ``` ---------------------------------------- TITLE: Marpit CSS Styling DESCRIPTION: This CSS defines the core styling for Marpit slide decks, including layout, typography, and print-specific adjustments. It ensures a consistent visual presentation across different slides and environments. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/assets/how-to-use/example.html#_snippet_0 LANGUAGE: css CODE: ``` div.marpit > section { width: 1280px; height: 720px; box-sizing: border-box; overflow: hidden; position: relative; scroll-snap-align: center center; } div.marpit > section::after { bottom: 0; content: attr(data-marpit-pagination); padding: inherit; pointer-events: none; position: absolute; right: 0; } div.marpit > section:not(\[data-marpit-pagination\])::after { display: none; } /* Normalization */ div.marpit > section h1 { font-size: 2em; margin: 0.67em 0; } @page { size: 1280px 720px; margin: 0; } @media print { html, body { margin: 0; page-break-inside: avoid; } div.marpit > section { page-break-before: always; } div.marpit > section, div.marpit > section * { -webkit-print-color-adjust: exact !important; color-adjust: exact !important; } div.marpit > svg { display: block; height: 100vh; width: 100vw; } } /* @theme example */ div.marpit > section { background-color: #369; color: #fff; font-size: 30px; padding: 40px; } div.marpit > section h1, div.marpit > section h2 { text-align: center; margin: 0; } div.marpit > section h1 { color: #8cf; } ``` ---------------------------------------- TITLE: Marpit Fragmented Bullet List Syntax DESCRIPTION: Demonstrates how Marpit parses bullet lists using '*' as a marker to create fragmented content, appearing one by one. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/fragmented-list.md#_snippet_0 LANGUAGE: markdown CODE: ``` # Bullet list - One - Two - Three --- # Fragmented list * One * Two * Three ``` ---------------------------------------- TITLE: Local Page Directives DESCRIPTION: Explains how to apply directives to a specific slide and subsequent pages using standard HTML comment syntax. This allows for per-slide configuration changes. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/directives.md#_snippet_2 LANGUAGE: Markdown CODE: ``` This page has aqua background. --- The second page also has same color. ``` ---------------------------------------- TITLE: HTML Structure for Marpit Slides DESCRIPTION: Demonstrates the basic HTML structure for Marpit presentations, where each `
` element corresponds to a single slide page. This is analogous to how frameworks like reveal.js handle slide markup. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/theme-css.md#_snippet_0 LANGUAGE: html CODE: ```

First page

Second page

``` ---------------------------------------- TITLE: Split + Multiple backgrounds - Marpit Markdown DESCRIPTION: Combines split backgrounds with multiple backgrounds. An image is placed on the right side, and subsequent images are stacked horizontally on the left, shrinking the content area to the right. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/image-syntax.md#_snippet_7 LANGUAGE: markdown CODE: ``` ![bg right](https://picsum.photos/720?image=3) ![bg](https://picsum.photos/720?image=20) # Split + Multiple BGs The space of a slide content will shrink to the left side. ``` ---------------------------------------- TITLE: Render HTML as Array DESCRIPTION: Details how to render Markdown into an array of HTML strings, where each string represents a slide. This is achieved by passing `htmlAsArray: true` as the second argument to `marpit.render()`. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/usage.md#_snippet_7 LANGUAGE: javascript CODE: ``` const markdown = ` # Page 1 --- # Page 2 ` const { html } = marpit.render(markdown, { htmlAsArray: true }) /* [ '

Page 1

', '

Page 2

' ] */ ``` ---------------------------------------- TITLE: Marpit Constructor API Reference DESCRIPTION: Details on the Marpit constructor for setting default heading divider levels. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/directives.md#_snippet_7 LANGUAGE: APIDOC CODE: ``` Marpit: __constructor__(options?: MarpitOptions) options: Configuration options for Marpit. headingDivider?: number The default level of heading divider. If set to 0, then no heading divider will be inserted. Example: `new Marpit({ headingDivider: 3 })` ``` ---------------------------------------- TITLE: HTML Rendering of Header/Footer DESCRIPTION: Shows the resulting HTML structure when `header` and `footer` directives are used. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/directives.md#_snippet_12 LANGUAGE: HTML CODE: ```
Header content

Page 1

Footer content
Header content

Page 2

Footer content
``` ---------------------------------------- TITLE: Import Marpit Classes (Named Export) DESCRIPTION: Shows how to import Marpit classes using named exports. This approach is recommended when using TypeScript or when specific Marpit components are needed. SOURCE: https://github.com/marp-team/marpit/blob/main/api.md#_snippet_1 LANGUAGE: javascript CODE: ``` import { Element, Marpit, Theme, ThemeSet } from '@marp-team/marpit' ``` ---------------------------------------- TITLE: Global Directives: Style Tweak DESCRIPTION: Illustrates using the `style` global directive to inject custom CSS for tweaking the theme. This is an alternative to using ` # Red text --- # Blue text (only in the current slide page) --- # Red text ``` ---------------------------------------- TITLE: Setting Classic 4:3 Slide Size DESCRIPTION: Provides CSS to configure Marpit slides to a classic 4:3 aspect ratio by setting the `width` and `height` properties. These values must be static lengths in absolute units. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/theme-css.md#_snippet_4 LANGUAGE: css CODE: ``` /* Change to the classic 4:3 slide */ section { width: 960px; height: 720px; } ``` ---------------------------------------- TITLE: HTML with Polyfill for WebKit SVG Rendering DESCRIPTION: Includes the necessary HTML structure for inline SVG slides along with a script tag to load a polyfill. This polyfill addresses known rendering issues with HTML elements inside SVG foreignObjects in WebKit-based browsers. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/inline-svg.md#_snippet_3 LANGUAGE: html CODE: ```

Page 1

``` ---------------------------------------- TITLE: Spot Directives (Single Page) DESCRIPTION: Details how to apply a directive exclusively to the current slide by prefixing the directive name with an underscore (_). This prevents the setting from affecting subsequent pages. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/directives.md#_snippet_3 LANGUAGE: Markdown CODE: ``` Add underscore prefix `_` to the name of local directives. --- The second page would not apply setting of directives. ``` ---------------------------------------- TITLE: Multiple backgrounds (vertical) - Marpit Markdown DESCRIPTION: Shows how to arrange multiple background images vertically on a slide using the `vertical` keyword. This changes the stacking direction from the default horizontal. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/image-syntax.md#_snippet_5 LANGUAGE: markdown CODE: ``` ![bg vertical](https://fakeimg.pl/800x600/0288d1/fff/?text=A) ![bg](https://fakeimg.pl/800x600/02669d/fff/?text=B) ![bg](https://fakeimg.pl/800x600/67b8e3/fff/?text=C) ``` ---------------------------------------- TITLE: Marpit Theme Metadata DESCRIPTION: Illustrates the mandatory metadata declaration for Marpit themes. The `@theme` directive must be included as a CSS comment to identify the theme name. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/theme-css.md#_snippet_3 LANGUAGE: css CODE: ``` /* @theme name */ ``` ---------------------------------------- TITLE: Marpit Fragmented List HTML Rendering DESCRIPTION: Illustrates the HTML structure generated by Marpit for fragmented lists, including the `data-marpit-fragment` and `data-marpit-fragments` attributes. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/fragmented-list.md#_snippet_2 LANGUAGE: html CODE: ```

Bullet list

  • One
  • Two
  • Three

Fragmented list

  • One
  • Two
  • Three
``` ---------------------------------------- TITLE: Header and Footer Styling DESCRIPTION: Demonstrates how to position header and footer elements on Marpit slides using CSS absolute positioning. This allows for custom placement in the margins of the slide. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/theme-css.md#_snippet_7 LANGUAGE: css CODE: ``` section { padding: 50px; } header, footer { position: absolute; left: 50px; right: 50px; height: 20px; } header { top: 30px; } footer { bottom: 30px; } ``` ---------------------------------------- TITLE: Customizing Pagination Content DESCRIPTION: Shows how to customize the content of the pagination indicator using CSS `content` property and `attr()` function. It includes the current page number (`data-marpit-pagination`) and total page number (`data-marpit-pagination-total`). SOURCE: https://github.com/marp-team/marpit/blob/main/docs/theme-css.md#_snippet_6 LANGUAGE: css CODE: ``` /* Add "Page" prefix and total page number */ section::after { content: 'Page ' attr(data-marpit-pagination) ' / ' attr(data-marpit-pagination-total); } ``` ---------------------------------------- TITLE: HTML Comment Directives DESCRIPTION: Specifies how to use HTML comments to define global Marpit directives. Directives within HTML comments are parsed but not included in the Marpit render output's comments. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/directives.md#_snippet_0 LANGUAGE: Markdown CODE: ``` ``` ---------------------------------------- TITLE: Global Directives: Heading Divider DESCRIPTION: Explains the `headingDivider` global directive, which automatically divides slides at specified heading levels. It accepts a number (level >= value) or an array of levels. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/directives.md#_snippet_6 LANGUAGE: Markdown CODE: ``` # 1st page The content of 1st page ## 2nd page ### The content of 2nd page Hello, world! --- # 3rd page 😃 ``` ---------------------------------------- TITLE: Marpit Slide Structure DESCRIPTION: Demonstrates how to structure Marpit slides using Markdown. Slides are separated by horizontal rulers (`---`). An empty line before the ruler might be required by CommonMark specifications. Alternative rulers like `___`, `***`, or `- - -` can also be used. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/markdown.md#_snippet_0 LANGUAGE: markdown CODE: ``` # Slide 1 foo --- # Slide 2 bar ``` ---------------------------------------- TITLE: CSS `::backdrop` Selector for Marpit SVG Backgrounds DESCRIPTION: Illustrates how the `::backdrop` CSS pseudo-element is redirected to the SVG container when inline SVG mode is enabled. This allows styling the background of the SVG container, effectively controlling the slide's letterbox or pillarbox appearance. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/inline-svg.md#_snippet_4 LANGUAGE: css CODE: ``` ::backdrop { background-color: #448; } ``` ---------------------------------------- TITLE: Disable Backdrop Selector DESCRIPTION: Disables the `::backdrop` selector redirection to prevent conflicts with application styles. This is achieved by setting the `backdropSelector` option to `false` within the `inlineSVG` configuration. SOURCE: https://github.com/marp-team/marpit/blob/main/docs/inline-svg.md#_snippet_6 LANGUAGE: javascript CODE: ``` const marpit = new Marpit({ inlineSVG: { backdropSelector: false }, }) ```