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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a3097a1cc6ae762fbae1468974d0cc5460ef8197d5c33a574255ac4d5b50abf
|
|
| MD5 |
6e3ced987452cbac46a69e0dc53de64e
|
|
| BLAKE2b-256 |
064172297213db40853bd4d9f73e827c26cdc152c21fa9db3dc5484da3acb5ad
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mkdocs_md_preview-1.0.0.tar.gz -
Subject digest:
4a3097a1cc6ae762fbae1468974d0cc5460ef8197d5c33a574255ac4d5b50abf - Sigstore transparency entry: 427313847
- Sigstore integration time:
-
Permalink:
Paulkm2006/mkdocs-md-preview@b2499624be33af4a601c8aed62b7eded476c4812 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Paulkm2006
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@b2499624be33af4a601c8aed62b7eded476c4812 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file mkdocs_md_preview-1.0.0-py3-none-any.whl.
File metadata
- Download URL: mkdocs_md_preview-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15c9ebf492afa1862a88406ba9853f8b3f9594d9c275c52db5441e2b3fe98ec4
|
|
| MD5 |
92aa25101af6fef7c5349f81903d1a7e
|
|
| BLAKE2b-256 |
b42e6f623ef895c0324999041a2732b4ea4859add924ad80bf966b19c2e9502d
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mkdocs_md_preview-1.0.0-py3-none-any.whl -
Subject digest:
15c9ebf492afa1862a88406ba9853f8b3f9594d9c275c52db5441e2b3fe98ec4 - Sigstore transparency entry: 427313851
- Sigstore integration time:
-
Permalink:
Paulkm2006/mkdocs-md-preview@b2499624be33af4a601c8aed62b7eded476c4812 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Paulkm2006
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@b2499624be33af4a601c8aed62b7eded476c4812 -
Trigger Event:
workflow_dispatch
-
Statement type: