Marp Markdown Presentation Ecosystem

repository·main·Indexed 11 days ago

https://github.com/marp-team/marp

A Markdown-based presentation ecosystem for creating professional slide decks. The ecosystem includes Marpit (a lightweight framework), Marp Core (the core converter with built-in themes), Marp CLI (a command-line tool for exporting to HTML, PDF, PPTX, and images), and an extension for VS Code. Key features include support for MathJax and KaTeX, custom CSS transitions via the View Transitions API in Marp CLI v2, and theme customization.

Tokens
12.1K
Snippets
49
Records
73
Agent score
95%

What's inside Marp

  1. Overview of the Marp ecosystem

    main
    Marp is a Markdown Presentation Ecosystem that allows you to create slide decks using plain Markdown. The ecosystem is divided into several specialized components including core frameworks, command-line tools, and editor integrations.
  2. Marp Web (PWA)

    main

    Marp Web is a web-based interface for writing Marp presentations. It is designed as a Progressive Web App (PWA), meaning:

    • Offline Support: Once accessed, resources are cached in your browser, allowing you to use the interface without an internet connection.
    • Cross-Device Compatibility: Works on desktop browsers, mobile devices (Android/iOS), tablets (iPad), and Chrome OS.
    • Live Preview: Provides a high-performance live preview that updates as you type without blocking the UI, even for large documents.
  3. Handle backward navigation in custom transitions

    main

    When creating custom transitions, animations might behave incorrectly during backward navigation (e.g., sliding in the wrong direction). You can solve this using two methods:

    1. Use the --marp-transition-direction CSS variable: This variable is available within @keyframes. It evaluates to 1 for forward navigation and -1 for backward navigation. Use calc() to adjust positions based on this value.
    2. Declare specific backward keyframes: Use the backward- prefix in your @keyframes name (e.g., marp-incoming-transition-backward-name). Marp will prioritize these keyframes during backward navigation and fall back to the standard ones if the backward version is not defined. To prevent unintended fallback, you can declare an empty @keyframes for the backward version.
    /* Method 1: Using the direction variable */
    @keyframes marp-outgoing-transition-slide-up {
      from { transform: translateY(0%); }
      to { transform: translateY(calc(var(--marp-transition-direction, 1) * -100%)); }
    }
    
    /* Method 2: Using the backward prefix */
    @keyframes marp-incoming-transition-triangle {
      from { clip-path: polygon(0% 0%, 0% 0%, 0% 0%); }
      to { clip-path: polygon(0% 0%, 200% 0%, 0% 200%); }
    }
    @keyframes marp-incoming-transition-backward-triangle {
      from { clip-path: polygon(100% 100%, 100% 100%, 100% 100%); }
      to { clip-path: polygon(-100% 100%, 100% -100%, 100% 100%); }
    }
  4. Create custom transitions using CSS @keyframes

    main

    Custom transitions can be defined by adding @keyframes at-rules within an inline <style> element or a custom theme's CSS.

    To create a custom transition named my-custom-name, you must define the corresponding Marp-specific keyframe names:

    1. marp-incoming-transition-my-custom-name (for the entrance animation)
    2. marp-outgoing-transition-my-custom-name (for the exit animation, optional)
    3. marp-incoming-transition-backward-my-custom-name (for backward navigation, optional)
    4. marp-outgoing-transition-backward-my-custom-name (for backward navigation, optional)

    This allows for complex, creative CSS animations to be used as slide transitions.

    /* Simple definition: "dissolve" custom transition */
    @keyframes marp-transition-dissolve {
      from { opacity: 1; }
      to { opacity: 0; }
    }
    
    /* Splitted definitions: "triangle" custom transition */
    @keyframes marp-incoming-transition-triangle {
      from { clip-path: polygon(0% 0%, 0% 0%, 0% 0%); }
      to { clip-path: polygon(0% 0%, 200% 0%, 0% 200%); }
    }
    @keyframes marp-incoming-transition-backward-triangle {
      from { clip-path: polygon(100% 100%, 100% 100%, 100% 100%); }
      to { clip-path: polygon(-100% 100%, 100% -100%, 100% 100%); }
    }
  5. How fragmented lists work in Marp

    main

    Fragmented lists (also known as incremental lists or builds) allow list content to appear incrementally during a presentation.

    Key Behaviors:

    • Export Dependency: Fragmented lists only function when exporting to HTML. In PDF and PPTX exports, they render as normal, fully visible lists.
    • Rendering Implementation: The syntax merely indicates that a list should be fragmented. The actual animation depends on the tool used. In the official Marp toolset, the Marp CLI's default HTML template bespoke is required to reproduce the fragmented list as a build animation.
    • Usage Warning: While they can help focus attention, they can also cause confusion regarding hidden items. Use them judiciously.
  6. Understand the Marp ecosystem concepts

    main

    Marp (Markdown Presentation Ecosystem) is a system for creating presentations using Markdown. It is built on several core principles:

    • Markdown-based: Uses CommonMark for maximum compatibility. You focus on logical structure rather than presentation code.
    • Theme CSS: Uses standard HTML and CSS for styling. It follows the principle of separation of content and style, allowing you to apply community themes to your content easily.
    • Multi-format Export: Supports conversion to PDF, PPTX, and HTML. Marp prioritizes reproducible rendering so that layouts remain consistent across these formats.
    • Pluggable Architecture: Built on the Marpit framework, which allows developers to extend functionality via plugins (e.g., adding new Markdown syntax via markdown-it plugins, custom directives, or custom theme sets).
  7. Identify the right Marp component for your needs

    main

    The Marp ecosystem is split into different packages depending on whether you need a framework, a CLI, or an editor extension:

    Framework / Core

    • Marpit: A lightweight framework for creating slide decks from Markdown.
    • Marp Core: The core converter featuring practical features and built-in themes.

    Apps

    • Marp CLI: A command-line interface for Marp Core/Marpit that converts Markdown into HTML, PDF, PPTX, or images.

    Integrations

    • Marp for VS Code: A Visual Studio Code extension that provides a live preview of your Marp Markdown slide decks.
  8. Understand Workspace Trust restrictions in Marp for VS Code

    main

    Marp for VS Code supports VS Code's Workspace Trust security model. If you are working in an untrusted workspace, only basic Marp features are available (Markdown preview and IntelliSense).

    To use advanced features, you must trust the workspace. The following features are restricted in untrusted workspaces:

    • The Export command (to PDF/PPTX).
    • Using custom themes configured via the markdown.marp.themes setting.
    • Enabling HTML tags in Markdown via the markdown.marp.enableHtml setting.
  9. Understand Marp's extended Markdown syntax

    main

    Marp is based on CommonMark but includes several extensions and specific behaviors:

    Line Breaks

    • Line breaks within a paragraph are automatically converted to <br /> tags.
    • You can manually use the <br /> tag for explicit line breaks (e.g., inside a fitting header).

    GitHub Flavored Markdown (GFM) Features

    • Automatic linking: URLs are automatically converted to links.
    • Emoji shortcodes: Supported via markdown-it-emoji and twemoji.
    • Strikethrough: Use ~~text~~ to strike through text.
    • Syntax highlighting: Supported in code blocks via highlight.js.
    • Tables: GFM table syntax is enabled.

    List Markers

    • Certain uncommon list markers like * and 1) have special meanings for creating fragmented lists.
  10. How custom slide transitions work in Marp

    main

    Marp implements slide transitions by treating the current slide and the next slide as two separate layers presented simultaneously. To create a smooth effect, you must follow two principles:

    1. The Outgoing Slide: The slide being navigated away from must have an animation to hide it.
    2. The Incoming Slide: The new slide appearing must have an animation to show it.

    When navigating, Marp's bespoke HTML template creates these two layers and applies the appropriate CSS animation keyframes to each.

  11. Define global macros in KaTeX

    main

    When using KaTeX, standard \def macros are local to the specific math environment (the current block). To define a macro that persists and can be used in subsequent math environments throughout the Markdown document, use \gdef (\global\def).

    $$
    % macroA is local to this block
    \def\macroA{{\color{red}A}}
    
    % macroB is global
    \gdef\macroB{{\color{blue}B}}
    
    \macroA + \macroB
    $$
    
    ---
    
    $$
    % macroA will not work here, but macroB will
    \macroA + \macroB
    $$
  12. Configure HTML tag usage in Marp

    main

    By default, most HTML tags are disabled for security reasons. Marp only allows two specific tags out of the box:

    1. <style>: Used for tweaking the current theme.
    2. <br />: Used for line breaks.

    If you need to use other HTML tags, you must explicitly opt-in via the specific Marp tool or CLI configuration you are using.