Skip to main content

Convert URL content to markdown for better LLM context.

Project description

site2markdown

A robust Python utility to convert web pages into clean, structured Markdown. Optimized for generating high-quality context for Large Language Models (LLMs).

Installation

pip install site2markdown

Usage

site2markdown usage example

Quick Start

from site2markdown import UrlToMarkdown

converter = UrlToMarkdown()

# Convert URL to Markdown
markdown = converter.convert(
    url="https://www.example.com",
    inline_title=True,        # Include the page title as an H1
    ignore_links=False,       # Preserve hyper-links
    improve_readability=True  # Use readability algorithm to filter boilerplate
)

print(markdown)

Converting HTML Content

from site2markdown import UrlToMarkdown

converter = UrlToMarkdown()
html_content = "<html><body><h1>Example</h1><p>Text content.</p></body></html>"

markdown = converter.convert_html(
    html=html_content,
    url="https://www.example.com",  # Optional: base URL for resolving relative paths
    inline_title=True,
    improve_readability=True
)

print(markdown)

Core Features

  • LLM Optimized: Produces clean text with minimal noise, ideal for RAG and LLM context.
  • Smart Filtering: Automatic removal of scripts, styles, and non-content elements.
  • Specialized Handling: Custom parsing logic for sites like Stack Overflow, Wikipedia, and Medium.
  • Readability Engine: Integration with Mozilla's Readability algorithm to extract the main article body and skip navigation/sidebars.
  • Structure Preservation: Reliable conversion of code blocks, tables, and nested lists.
  • URL Resolution: Automatically converts relative links and image paths to absolute URLs.

Configuration Options

Option Type Description Default
inline_title bool Includes the page title as an H1 heading at the top. True
ignore_links bool Removes all hyperlinks from the output. False
improve_readability bool Processes the page through a readability filter before conversion. True

License

This project is licensed under the MIT License.

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

site2markdown-1.0.1.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

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

site2markdown-1.0.1-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file site2markdown-1.0.1.tar.gz.

File metadata

  • Download URL: site2markdown-1.0.1.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for site2markdown-1.0.1.tar.gz
Algorithm Hash digest
SHA256 c00ba79e339d6578a6e5a2b0f77cba75ecf188d7a297759e40bad2fb3662cf4b
MD5 5fa8b38190e813f91a98a75fc56ac0d1
BLAKE2b-256 9fd83307a0e8ea80c4ac57229b2782f86f0a20734b8e9ab037217d97f97fc70f

See more details on using hashes here.

File details

Details for the file site2markdown-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: site2markdown-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for site2markdown-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d39064839e183fa4b6b6de4471a70dbe1b811b40c386daacfcae6511785ddba2
MD5 ba3347f12061d6fce9ec6be17ececd67
BLAKE2b-256 dae9af59c1216cb6e8030a90df2d4d81349f4da9b3151ce8e239d3e3effece09

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