Flask extension to serve HTML pages as Markdown via ?format=md query parameter.
Project description
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
)
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
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 canonicalwebteam_markdown_response-0.1.1.tar.gz.
File metadata
- Download URL: canonicalwebteam_markdown_response-0.1.1.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6cf9e70e7eafb4ab57c3d9af507403ce817ac9509eeed8a3282160853f1e108
|
|
| MD5 |
adf6f92ca275864e97862fcc415c3389
|
|
| BLAKE2b-256 |
0daf0d39551801fabe2b9c1b2b17c116f1712545962cbef9e5b04c4e7be65756
|
Provenance
The following attestation bundles were made for canonicalwebteam_markdown_response-0.1.1.tar.gz:
Publisher:
publish.yaml on canonical/canonicalwebteam.markdown-response
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
canonicalwebteam_markdown_response-0.1.1.tar.gz -
Subject digest:
a6cf9e70e7eafb4ab57c3d9af507403ce817ac9509eeed8a3282160853f1e108 - Sigstore transparency entry: 1246752582
- Sigstore integration time:
-
Permalink:
canonical/canonicalwebteam.markdown-response@01d53656369861f63c4e9c4751f39f843eee5a81 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/canonical
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@01d53656369861f63c4e9c4751f39f843eee5a81 -
Trigger Event:
push
-
Statement type:
File details
Details for the file canonicalwebteam_markdown_response-0.1.1-py3-none-any.whl.
File metadata
- Download URL: canonicalwebteam_markdown_response-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
967f79d6968483203da6ad0d5956fabdcd050e7f5ece6d89d072fedbc9984610
|
|
| MD5 |
d47df359bdf1044395687ae5b1d8b6a5
|
|
| BLAKE2b-256 |
e01aa7f5860ca3122174d8c1014817d2b3ba37852d8b8d300b68625f1b809df3
|
Provenance
The following attestation bundles were made for canonicalwebteam_markdown_response-0.1.1-py3-none-any.whl:
Publisher:
publish.yaml on canonical/canonicalwebteam.markdown-response
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
canonicalwebteam_markdown_response-0.1.1-py3-none-any.whl -
Subject digest:
967f79d6968483203da6ad0d5956fabdcd050e7f5ece6d89d072fedbc9984610 - Sigstore transparency entry: 1246752742
- Sigstore integration time:
-
Permalink:
canonical/canonicalwebteam.markdown-response@01d53656369861f63c4e9c4751f39f843eee5a81 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/canonical
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@01d53656369861f63c4e9c4751f39f843eee5a81 -
Trigger Event:
push
-
Statement type: