mirror of
https://github.com/Hopiu/python-markdown-oembed.git
synced 2026-03-16 22:10:24 +00:00
Markdown extension to allow media embedding using the oEmbed standard.
- **Removed legacy build files**: - Deleted obsolete `.travis.yml`, `flake.lock`, and `flake.nix` files that were no longer needed for the current build and dependency management setup. - **Updated versioning**: - Incremented the package version from `0.4.0` to `0.5.0` in `version.py` and made adjustments in `pyproject.toml` to reflect the new versioning mechanism. - **Refined package structure**: - Moved source files from `src/python_markdown_oembed_extension` to `mdx_oembed` and renamed references accordingly for better clarity and organization of the codebase. - **Enhanced OEmbed functionality**: - Added dedicated endpoint handling in the new `endpoints.py`. - Refactored the `oembed.py` file to implement a minimal oEmbed consumer, replacing the earlier dependency on `python-oembed`. - **Improved test coverage**: - Transitioned tests from `unittest` to `pytest` framework for better maintainability. - Expanded unit tests, including better error handling and validation for various media types. - **Updated dependency requirements**: - Raised minimum Python version from `3.9` to `3.12` in `pyproject.toml`. - Removed non-essential dependencies and restructured the dependency declarations to streamline package management. These changes focus on modernizing the codebase, improving adherence to current Python standards, and enhancing overall functionality and maintainability. |
||
|---|---|---|
| mdx_oembed | ||
| .gitignore | ||
| LICENSE | ||
| pyproject.toml | ||
| README.md | ||
| tests.py | ||
| uv.lock | ||
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