Skip to main content

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('![video](http://www.youtube.com/watch?v=zqnh_YJBvOI)')

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 Pattern to InlineProcessor (Markdown 3.2+ compatible)
  • Added HTML sanitization of oEmbed responses (XSS protection via nh3)
  • Added support for oEmbed photo type 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.toml with 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

python_markdown_oembed_extension-0.4.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file python_markdown_oembed_extension-0.4.0.tar.gz.

File metadata

  • Download URL: python_markdown_oembed_extension-0.4.0.tar.gz
  • Upload date:
  • Size: 4.7 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

Hashes for python_markdown_oembed_extension-0.4.0.tar.gz
Algorithm Hash digest
SHA256 487086e08c2f7c453d03877d3e7f9daa0282fa4734c9f77f0a18f7ce7a889731
MD5 596247bdd2a02a46a42b1b0f1f3344e8
BLAKE2b-256 6372f1adcb67256f24dcb0c2eaee2ea83d6afa72db340b9688fbe3c4d7e4f71a

See more details on using hashes here.

File details

Details for the file python_markdown_oembed_extension-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: python_markdown_oembed_extension-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 3.6 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

Hashes for python_markdown_oembed_extension-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fcfb5dc65363a116ff1dad57a44f149c65df008b1fec66cf4d0988f63697539d
MD5 ebbc56162bf40c9d8a633f5816a6cecd
BLAKE2b-256 ee0abd3ab388e84b07c59803eb401ba9bd34f05a264093d2adab30bb6ccb6f83

See more details on using hashes here.

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