canonicalwebteam.markdown-response
Flask extension that adds ?format=md support to all HTML responses, converting pages to clean Markdown with YAML frontmatter. Designed for LLM and crawler optimization.
Installation
pip install canonicalwebteam.markdown-response
Usage
from canonicalwebteam.markdown_response import MarkdownResponse
app = Flask(__name__)
MarkdownResponse(app)
Or with the application factory pattern:
md = MarkdownResponse()
md.init_app(app)
Any page can now be accessed as Markdown by appending ?format=md to the URL.
Configuration
MarkdownResponse(app,
content_selector="#main-content", # CSS selector for content extraction
strip_elements=["script", "style", "nav", "noscript"], # Tags to remove
strip_classes=["u-hide", "u-off-screen"], # Classes to remove
query_param="format", # Query parameter name
query_value="md", # Query parameter value
title_suffixes=[ # Suffixes stripped from the end of <title>
" | Canonical",
" | Trusted open source for enterprises",
" | Ubuntu",
],
)
The query_param (e.g. format=md) is also removed from the frontmatter
url and from the base URL used to resolve relative links, so links and
the extracted og:url don't carry the Markdown query string. Other query
parameters (e.g. UTM parameters) are preserved.
Template-level exclusion
Add data-md-strip to any HTML element to exclude it from the Markdown output:
<section data-md-strip>
<form>This form won't appear in markdown output</form>
</section>
How it works
- An
after_requesthandler intercepts responses when?format=mdis present - Only processes HTML 200 responses (JSON, XML, errors pass through)
- Extracts the content area using BeautifulSoup (
#main-contentby default) - Strips unwanted elements (scripts, styles, nav, hidden elements,
data-md-strip) - Converts remaining HTML to Markdown via markdownify
- Prepends YAML frontmatter extracted from
<head>meta tags - Returns with
Content-Type: text/markdown; charset=utf-8
Metadata
Release files for canonicalwebteam.markdown-response 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| canonicalwebteam_markdown_response-0.3.0.tar.gz | 8.6 kB | With provenance | Details for canonicalwebteam_markdown_response-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| canonicalwebteam_markdown_response-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for canonicalwebteam_markdown_response-0.3.0-py3-none-any.whl |
Total release size: 19.6 kB
Release files / canonicalwebteam_markdown_response-0.3.0.tar.gz
| Download URL | canonicalwebteam_markdown_response-0.3.0.tar.gz |
|---|---|
| Size | 8.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f9f1825697ded22a9dcac1ed5b350b9d64c5aef40c774537fab980ce67bdbe49
|
|
BLAKE2b-256 checksum How to use checksums |
77a20ae94247e18e6e8c6e7744ef363f643721db93123874c2302d065a6b434c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 28, 2026.
Transparency logRelease files / canonicalwebteam_markdown_response-0.3.0-py3-none-any.whl
| Download URL | canonicalwebteam_markdown_response-0.3.0-py3-none-any.whl |
|---|---|
| Size | 11.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
040df301bb9f545a2ea8b9aaf93b08b724dacf213138ac4048b67995cd08feb7
|
|
BLAKE2b-256 checksum How to use checksums |
41d3c42d1c92180a87f0414764643946ab2842dc947c98018e868794ae6b5975
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 28, 2026.
Transparency logSecurity for canonicalwebteam.markdown-response 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for canonicalwebteam_markdown_response-0.3.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 28, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.