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.2.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.2-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: site2markdown-1.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 58e128bc8fd48428e830330ae776d7e7e29660369ed0740241264f3dd3198653
MD5 0c2bd649283fc4ebc57c0ccd7f42160a
BLAKE2b-256 f1c988e78ffd405fe9000f04ad7502f0ee7d0da707b0904ac183463365f6da45

See more details on using hashes here.

File details

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

File metadata

  • Download URL: site2markdown-1.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c30729a8dadf94096f69ec41ab0bdeb41350134854ae177487cffa7c6b853314
MD5 e9e099d7e2ab09bcf7a8b7299b50c33f
BLAKE2b-256 2fce4efa64595608b6f905c9f668bee6b42269e0efa42f9d18a6418d928437e8

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