Skip to main content

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

  1. An after_request handler intercepts responses when ?format=md is present
  2. Only processes HTML 200 responses (JSON, XML, errors pass through)
  3. Extracts the content area using BeautifulSoup (#main-content by default)
  4. Strips unwanted elements (scripts, styles, nav, hidden elements, data-md-strip)
  5. Converts remaining HTML to Markdown via markdownify
  6. Prepends YAML frontmatter extracted from <head> meta tags
  7. 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)

Source distribution for canonicalwebteam.markdown-response 0.3.0
File Size Uploaded
canonicalwebteam_markdown_response-0.3.0.tar.gz 8.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for canonicalwebteam.markdown-response 0.3.0
File Interpreter ABI Platform
canonicalwebteam_markdown_response-0.3.0-py3-none-any.whl Python 3 none any Details

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 log

Release 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 log

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page