Markdown Preview for Sublime Text

repository·master·Indexed 19 days ago

https://github.com/facelessuser/markdownpreview

A Sublime Text plugin to preview and build markdown files in a web browser. It supports multiple rendering engines including Python Markdown (offline), GitHub API, and GitLab API. Key features include MathJax and KaTeX support for mathematical notation, UML rendering via Mermaid or sequence/flow diagrams, YAML support, and LiveReload integration.

Tokens
12.1K
Snippets
37
Records
48
Agent score
66%

What's inside Markdown Preview

  1. Overview of Markdown Preview for Sublime Text

    master

    Markdown Preview is a Sublime Text plugin that allows you to preview and build markdown files in a web browser. It supports multiple conversion engines:

    • Python Markdown (Offline): Uses the python-markdown parser with Pygments for syntax highlighting. It includes pymdown-extensions by default.
    • GitHub Markdown API (Online): Converts markdown using GitHub's official API.
    • GitLab Markdown API (Online): Converts markdown using GitLab's API.
    • External Parsers: Supports the use of other external Markdown parsers.

    Key capabilities include MathJax support for mathematical notation, YAML support, image embedding as base64, and the ability to build markdown files using the Sublime Text build system.

  2. Use Meta Data and YAML Frontmatter

    master

    Markdown Preview supports extracting metadata from files.

    Meta Data

    When the meta extension is enabled, keys are written to the HTML head as <meta name="key" content="value">. The title key is special and populates the HTML <title> tag.

    YAML Frontmatter

    Set strip_yaml_front_matter: true to remove the YAML header from the rendered output. If both YAML and meta extension are present, YAML keys take precedence.

    Special YAML Keys

    • basepath: Absolute path for resolving relative paths (like images).
    • references: File path or array of paths for external reference files (footnotes, etc.).
    • destination: Absolute or relative path for where the HTML should be saved.
    • settings: A dictionary to override settings from the main configuration file.
    ---
        basepath: /absolute/path/to/images
        references:
            - references.md
        destination: output.html
        title: My Page
        settings:
          markdown_extensions:
            - pymdownx.highlight: { pygments_style: github }
    ---
  3. Use GitHub Emojis in Markdown

    master

    The Markdown previewer supports GitHub-style emoji shortcodes. Emojis are rendered as images linked to GitHub assets. You can use colon-wrapped shortcodes like :smile: or :octocat: to insert emojis into your document.

    Supported categories include:

    • People: e.g., :smile:, :heart_eyes:, :thumbsup:
    • Nature: e.g., :dog:, :moon:, :sunflower:
    • Objects: e.g., :apple:, :camera:, :guitar:
    • Places: e.g., :airplane:, :restaurant:, :train:
    • Symbols: e.g., :arrow_right:, :check_mark:, :copyright:
    This is a test for emoji :smile:.  The emojis are images linked to github assets :octocat:.
  4. Configure Markdown Preview conversion engines

    master

    Markdown Preview provides different ways to render your markdown depending on whether you need offline capability or specific API styling:

    1. Offline Mode: Uses the local python-markdown parser. This is ideal for working without an internet connection.
    2. GitHub Mode: Uses the GitHub Markdown API to render markdown, ensuring it looks like GitHub's implementation.
    3. GitLab Mode: Uses the GitLab Markdown API for GitLab-compatible rendering.
    4. Custom Parsers: You can configure the plugin to use other external Markdown parsers.
  5. Set up LiveReload for Markdown previews

    master

    To get live updates in your browser while editing a file, follow these steps:

    1. Enable auto-reload in MarkdownPreview.sublime-settings:
      "enable_autoreload": true,
      Note: This will not work with GitHub or GitLab parsers unless an oauth key is specified.
    2. Install the LiveReload package via Package Control.
    3. Restart Sublime Text.
    4. Open the Command Palette and select LiveReload: Enable/disable plug-ins.
    5. Select Simple Reload with delay (400ms). (Using Simple Reload without a delay may cause the preview to be one revision behind).

    Once configured, files will auto-reload in the browser whenever you save the document.

    "enable_autoreload": true,
  6. Configure Mermaid UML Support

    master

    Mermaid provides an alternative for rendering UML. Like the standard UML support, this requires the SuperFences extension to create custom fences. You must include the Mermaid library, a configuration file (or your own), and the Mermaid loader in your JavaScript configuration.

    "js": [
        // Mermaid library
        "https://unpkg.com/mermaid@8.8.4/dist/mermaid.min.js",
        // User configuration, should be loaded before the loader
        "res://MarkdownPreview/js/mermaid_config.js",
        // Mermaid loader
        "res://MarkdownPreview/js/mermaid.js"
    ]
  7. Install MarkdownPreview via Package Control

    master

    The recommended way to install MarkdownPreview is through Package Control in Sublime Text.

    1. Ensure Package Control is installed in your Sublime Text environment.
    2. Open the Command Palette using the shortcut Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (macOS).
    3. Type and select Package Control: Install Package.
    4. Search for MarkdownPreview in the list and select it to complete the installation.
    1. Ctrl+Shift+P (or Cmd+Shift+P)
    2. Package Control: Install Package
    3. MarkdownPreview
  8. Use nested fences and code blocks

    master

    The parser supports nested code blocks, including those inside lists or blockquotes. This allows you to document code examples within structured Markdown content without breaking the parser.

    - This is a list that contains multiple code blocks.
    
        - Here is an indented block
    
                ```
                This will still be parsed
                as a normal indented code block.
                ```
    
        - Here is a fenced code block:
    
            ```
            This will still be parsed
            as a fenced code block.
            ```
    
            > ```
            > Blockquotes? 
            > Not a problem!
            > ```
  9. Configure Markdown Preview via YAML Frontmatter

    master

    You can configure the Markdown Preview engine directly within your markdown file using a YAML frontmatter block. This allows you to define references, output destinations, metadata, and deep settings overrides for the rendering engine.

    Key configuration sections include:

    • references: A list of markdown files containing reference links, abbreviations, or footnotes.
    • destination: The target HTML filename.
    • title and author: Metadata for the document.
    • settings: Overrides for the rendering engine, including pygments_style, js (external JavaScript libraries), and markdown_extensions (Python-Markdown extensions).
    ---
        # Builtin values
        references:
            - references.md
            - abbreviations.md
            - footnotes.md
    
        destination: destination.html
    
        # Meta Data
        title: Test Page
        author:
            - John Doe
            - Jane Doe
    
        # Settings overrides
        settings:
            pygments_style: github_dynamic
            js:
              - https://cdnjs.cloudflare.com/ajax/libs/raphael/2.2.7/raphael.min.js
            markdown_extensions:
              - markdown.extensions.footnotes
              - pymdownx.details
    ---