Skip to main content

MkDocs plugin for side-by-side markdown preview

Project description

MkDocs Markdown Preview Plugin

A MkDocs plugin that renders markdown code blocks with md preview syntax into side-by-side boxes, showing both the original source code and the rendered output.

Features

  • Side-by-side preview: Shows markdown source and rendered output simultaneously
  • Customizable headers: Configure titles for source and rendered sections
  • Responsive design: Automatically adapts to mobile devices
  • Easy integration: Simple setup with existing MkDocs projects
  • Horizontal scrolling: Handles wide content without truncation
  • Nested code blocks: Properly handles code blocks within preview blocks

Installation

Install the plugin using pip:

pip install mkdocs-md-preview

Usage

1. Add to MkDocs configuration

Add the plugin to your mkdocs.yml file:

plugins:
  - md-preview

2. Configure (optional)

You can customize the plugin with these options:

plugins:
  - md-preview:
      enable: true
      left_title: "Markdown Source"
      right_title: "Rendered Output"

3. Add CSS (recommended)

Add the CSS styles to your extra.css file:

/* Markdown Preview Plugin Styles */
.markdown-preview-container {
    margin: 1.5em 0;
    border: 1px solid var(--md-default-fg-color--lighter);
    border-radius: 0.2rem;
    background-color: var(--md-code-bg-color);
    overflow: hidden;
}

.markdown-preview-wrapper {
    display: flex;
    min-height: 200px;
    overflow-x: auto;
    min-width: 100%;
}

.markdown-preview-left,
.markdown-preview-right {
    flex: 1;
    min-width: 300px;
    max-width: 50%;
    display: flex;
    flex-direction: column;
    white-space: nowrap;
}

.markdown-preview-left {
    border-right: 1px solid var(--md-default-fg-color--lighter);
}

.markdown-preview-header {
    background-color: var(--md-default-fg-color--lightest);
    padding: 0.5rem 1rem;
    font-weight: 600;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--md-default-fg-color--lighter);
    color: var(--md-default-fg-color--light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.markdown-preview-content {
    flex: 1;
    padding: 1rem;
    overflow: auto;
    white-space: nowrap;
}

.markdown-preview-left .markdown-preview-content {
    background-color: var(--md-code-bg-color);
}

.markdown-preview-left .markdown-preview-content pre {
    margin: 0;
    background-color: transparent;
    border: none;
    padding: 0;
    white-space: pre;
    overflow-x: auto;
    overflow-y: auto;
}

.markdown-preview-left .markdown-preview-content code {
    background-color: transparent;
    padding: 0;
    font-size: 0.85em;
    line-height: 1.4;
    white-space: pre;
    display: block;
    overflow-x: auto;
}

.markdown-preview-right .markdown-preview-content {
    background-color: var(--md-default-bg-color);
    white-space: normal;
}

.markdown-preview-rendered {
    min-width: 100%;
    overflow-x: auto;
}

.markdown-preview-rendered > *:first-child {
    margin-top: 0 !important;
}

.markdown-preview-rendered > *:last-child {
    margin-bottom: 0 !important;
}

.markdown-preview-rendered table {
    min-width: 100%;
    white-space: nowrap;
}

.markdown-preview-rendered pre {
    overflow-x: auto;
    white-space: pre;
}

.markdown-preview-rendered code {
    white-space: pre;
}

/* Responsive design */
@media screen and (max-width: 768px) {
    .markdown-preview-wrapper {
        flex-direction: column;
        overflow-x: visible;
    }
    
    .markdown-preview-left,
    .markdown-preview-right {
        max-width: none;
        min-width: 100%;
    }
    
    .markdown-preview-left {
        border-right: none;
        border-bottom: 1px solid var(--md-default-fg-color--lighter);
    }
    
    .markdown-preview-content {
        overflow-x: auto;
        white-space: nowrap;
    }
    
    .markdown-preview-right .markdown-preview-content {
        white-space: normal;
    }
}

4. Use in your markdown files

Use the md preview syntax in your markdown files:

```md preview
# Example Heading

This is **bold text** and this is *italic text*.

- List item 1
- List item 2
- List item 3

```python
def hello_world():
    print("Hello, World!")

\```

This will render as a side-by-side view showing both the markdown source and the rendered HTML output.

## Configuration Options

| Option | Type | Default | Description |
|--------|------|---------|-------------|
| enable | bool | 	rue | Enable or disable the plugin |
| left_title | string | "Markdown Source" | Title for the source code panel |
| 
ight_title | string | "Rendered Output" | Title for the rendered output panel |

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mkdocs_md_preview-1.0.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mkdocs_md_preview-1.0.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file mkdocs_md_preview-1.0.0.tar.gz.

File metadata

  • Download URL: mkdocs_md_preview-1.0.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mkdocs_md_preview-1.0.0.tar.gz
Algorithm Hash digest
SHA256 4a3097a1cc6ae762fbae1468974d0cc5460ef8197d5c33a574255ac4d5b50abf
MD5 6e3ced987452cbac46a69e0dc53de64e
BLAKE2b-256 064172297213db40853bd4d9f73e827c26cdc152c21fa9db3dc5484da3acb5ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for mkdocs_md_preview-1.0.0.tar.gz:

Publisher: python-publish.yml on Paulkm2006/mkdocs-md-preview

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mkdocs_md_preview-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mkdocs_md_preview-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 15c9ebf492afa1862a88406ba9853f8b3f9594d9c275c52db5441e2b3fe98ec4
MD5 92aa25101af6fef7c5349f81903d1a7e
BLAKE2b-256 b42e6f623ef895c0324999041a2732b4ea4859add924ad80bf966b19c2e9502d

See more details on using hashes here.

Provenance

The following attestation bundles were made for mkdocs_md_preview-1.0.0-py3-none-any.whl:

Publisher: python-publish.yml on Paulkm2006/mkdocs-md-preview

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page