Markdown extension to allow media embedding using the oEmbed standard.
Project description
Python Markdown oEmbed
Markdown extension to allow media embedding using the oEmbed standard.
Requirements
- Python >= 3.9
- Markdown >= 3.2
Installation
pip install python-markdown-oembed
Or with uv:
uv add python-markdown-oembed
Usage
import markdown
md = markdown.Markdown(extensions=['oembed'])
md.convert('')
Output is wrapped in a <figure class="oembed"> element by default:
<figure class="oembed"><iframe width="459" height="344" ...></iframe></figure>
Configuration
| Option | Default | Description |
|---|---|---|
allowed_endpoints |
YouTube, Flickr, Vimeo, Slideshare | List of oembed.OEmbedEndpoint objects |
wrapper_class |
"oembed" |
CSS class(es) for the <figure> wrapper. Set to "" to disable wrapping |
Example with custom configuration:
from mdx_oembed.endpoints import YOUTUBE, VIMEO
md = markdown.Markdown(
extensions=['oembed'],
extension_configs={
'oembed': {
'allowed_endpoints': [YOUTUBE, VIMEO],
'wrapper_class': 'embed-responsive',
}
}
)
Security
oEmbed HTML responses are sanitized using nh3
to prevent XSS from compromised oEmbed providers. Only safe tags (iframe,
video, audio, img, etc.) and attributes are allowed.
Links
License
A Public Domain work. Do as you wish.
Changelog
0.4.0
- Breaking: requires Python >= 3.9 and Markdown >= 3.2
- Migrated from deprecated
PatterntoInlineProcessor(Markdown 3.2+ compatible) - Added HTML sanitization of oEmbed responses (XSS protection via nh3)
- Added support for oEmbed
phototype responses - Improved image URL detection (case-insensitive, handles query strings)
- All oEmbed API endpoints now use HTTPS
- Slideshare URL patterns now accept both HTTP and HTTPS
- Configurable
<figure>wrapper class (previously hardcoded Bootstrap classes) - Migrated to
pyproject.tomlwith hatchling build backend - Tests modernized: uses pytest + unittest.mock, all HTTP calls mocked
- Centralized version management in
mdx_oembed/version.py
0.2.1
- add Slideshare endpoint (thanks to anantshri)
0.2.0
- backwards incompatible changes
- allows arbitrary endpoints (commit)
- works with modern Markdown (>=2.6)
- dropped support for python 2.6
- added support python 3.x
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
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 python_markdown_oembed_extension-0.5.0.tar.gz.
File metadata
- Download URL: python_markdown_oembed_extension-0.5.0.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21b1dbbc01e7be4cb482fba56c514e2df7630569f8fabf9404f2c8f019cca593
|
|
| MD5 |
343f79b470a657cc2a355134b87b843c
|
|
| BLAKE2b-256 |
937160b75f268a8b2fc1ed122b832123e412c17de52306f3a1f7faed75b2da53
|
File details
Details for the file python_markdown_oembed_extension-0.5.0-py3-none-any.whl.
File metadata
- Download URL: python_markdown_oembed_extension-0.5.0-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f27c303dcb54645de3bc702899b849d90fb45ed27ee05d333188377ef9cd079
|
|
| MD5 |
a48b73da4d364a2951e8da279f51d244
|
|
| BLAKE2b-256 |
b6a661a6717093240878fd53b43f20c27789ff3faf94ccd79e928cdf5f698305
|