{"id":27648150,"url":"https://github.com/goldziher/html-to-markdown","last_synced_at":"2025-04-24T02:33:14.168Z","repository":{"id":284809753,"uuid":"926648217","full_name":"Goldziher/html-to-markdown","owner":"Goldziher","description":"HTML to markdown converter","archived":false,"fork":false,"pushed_at":"2025-04-19T08:50:07.000Z","size":392,"stargazers_count":30,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-19T15:03:49.415Z","etag":null,"topics":["html-converter","markdown-converter","rag","text-extraction","text-processing"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Goldziher.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-02-03T16:18:12.000Z","updated_at":"2025-04-19T08:50:10.000Z","dependencies_parsed_at":"2025-03-28T04:01:28.690Z","dependency_job_id":null,"html_url":"https://github.com/Goldziher/html-to-markdown","commit_stats":null,"previous_names":["goldziher/html-to-markdown"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Goldziher%2Fhtml-to-markdown","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Goldziher%2Fhtml-to-markdown/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Goldziher%2Fhtml-to-markdown/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Goldziher%2Fhtml-to-markdown/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Goldziher","download_url":"https://codeload.github.com/Goldziher/html-to-markdown/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250548055,"owners_count":21448597,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["html-converter","markdown-converter","rag","text-extraction","text-processing"],"created_at":"2025-04-24T02:33:11.424Z","updated_at":"2025-04-24T02:33:14.162Z","avatar_url":"https://github.com/Goldziher.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# html-to-markdown\n\nA modern, fully typed Python library for converting HTML to Markdown. This library is a completely rewritten fork\nof [markdownify](https://pypi.org/project/markdownify/) with a modernized codebase, strict type safety and support for\nPython 3.9+.\n\n## Features\n\n- Full type safety with strict MyPy adherence\n- Functional API design\n- Extensive test coverage\n- Configurable conversion options\n- CLI tool for easy conversions\n- Support for pre-configured BeautifulSoup instances\n- Strict semver versioning\n\n## Installation\n\n```shell\npip install html-to-markdown\n```\n\n## Quick Start\n\nConvert HTML to Markdown with a single function call:\n\n```python\nfrom html_to_markdown import convert_to_markdown\n\nhtml = \"\"\"\n\u003carticle\u003e\n    \u003ch1\u003eWelcome\u003c/h1\u003e\n    \u003cp\u003eThis is a \u003cstrong\u003esample\u003c/strong\u003e with a \u003ca href=\"https://example.com\"\u003elink\u003c/a\u003e.\u003c/p\u003e\n    \u003cul\u003e\n        \u003cli\u003eItem 1\u003c/li\u003e\n        \u003cli\u003eItem 2\u003c/li\u003e\n    \u003c/ul\u003e\n\u003c/article\u003e\n\"\"\"\n\nmarkdown = convert_to_markdown(html)\nprint(markdown)\n```\n\nOutput:\n\n```markdown\n# Welcome\n\nThis is a **sample** with a [link](https://example.com).\n\n* Item 1\n* Item 2\n```\n\n### Working with BeautifulSoup\n\nIf you need more control over HTML parsing, you can pass a pre-configured BeautifulSoup instance:\n\n```python\nfrom bs4 import BeautifulSoup\nfrom html_to_markdown import convert_to_markdown\n\n# Configure BeautifulSoup with your preferred parser\nsoup = BeautifulSoup(html, \"lxml\")  # Note: lxml requires additional installation\nmarkdown = convert_to_markdown(soup)\n```\n\n## Advanced Usage\n\n### Customizing Conversion Options\n\nThe library offers extensive customization through various options:\n\n```python\nfrom html_to_markdown import convert_to_markdown\n\nhtml = \"\u003cdiv\u003eYour content here...\u003c/div\u003e\"\nmarkdown = convert_to_markdown(\n    html,\n    heading_style=\"atx\",  # Use # style headers\n    strong_em_symbol=\"*\",  # Use * for bold/italic\n    bullets=\"*+-\",  # Define bullet point characters\n    wrap=True,  # Enable text wrapping\n    wrap_width=100,  # Set wrap width\n    escape_asterisks=True,  # Escape * characters\n    code_language=\"python\",  # Default code block language\n)\n```\n\n### Custom Converters\n\nYou can provide your own conversion functions for specific HTML tags:\n\n```python\nfrom bs4.element import Tag\nfrom html_to_markdown import convert_to_markdown\n\n# Define a custom converter for the \u003cb\u003e tag\ndef custom_bold_converter(*, tag: Tag, text: str, **kwargs) -\u003e str:\n    return f\"IMPORTANT: {text}\"\n\nhtml = \"\u003cp\u003eThis is a \u003cb\u003ebold statement\u003c/b\u003e.\u003c/p\u003e\"\nmarkdown = convert_to_markdown(html, custom_converters={\"b\": custom_bold_converter})\nprint(markdown)\n# Output: This is a IMPORTANT: bold statement.\n```\n\nCustom converters take precedence over the built-in converters and can be used alongside other configuration options.\n\n### Configuration Options\n\n| Option               | Type | Default        | Description                                            |\n| -------------------- | ---- | -------------- | ------------------------------------------------------ |\n| `autolinks`          | bool | `True`         | Auto-convert URLs to Markdown links                    |\n| `bullets`            | str  | `'*+-'`        | Characters to use for bullet points                    |\n| `code_language`      | str  | `''`           | Default language for code blocks                       |\n| `heading_style`      | str  | `'underlined'` | Header style (`'underlined'`, `'atx'`, `'atx_closed'`) |\n| `escape_asterisks`   | bool | `True`         | Escape * characters                                    |\n| `escape_underscores` | bool | `True`         | Escape _ characters                                    |\n| `wrap`               | bool | `False`        | Enable text wrapping                                   |\n| `wrap_width`         | int  | `80`           | Text wrap width                                        |\n\nFor a complete list of options, see the [Configuration](#configuration) section below.\n\n## CLI Usage\n\nConvert HTML files directly from the command line:\n\n```shell\n# Convert a file\nhtml_to_markdown input.html \u003e output.md\n\n# Process stdin\ncat input.html | html_to_markdown \u003e output.md\n\n# Use custom options\nhtml_to_markdown --heading-style atx --wrap --wrap-width 100 input.html \u003e output.md\n```\n\nView all available options:\n\n```shell\nhtml_to_markdown --help\n```\n\n## Migration from Markdownify\n\nFor existing projects using Markdownify, a compatibility layer is provided:\n\n```python\n# Old code\nfrom markdownify import markdownify as md\n\n# New code - works the same way\nfrom html_to_markdown import markdownify as md\n```\n\nThe `markdownify` function is an alias for `convert_to_markdown` and provides identical functionality.\n\n## Configuration\n\nFull list of configuration options:\n\n- `autolinks`: Convert valid URLs to Markdown links automatically\n- `bullets`: Characters to use for bullet points in lists\n- `code_language`: Default language for fenced code blocks\n- `code_language_callback`: Function to determine code block language\n- `convert`: List of HTML tags to convert (None = all supported tags)\n- `default_title`: Use default titles for elements like links\n- `escape_asterisks`: Escape * characters\n- `escape_misc`: Escape miscellaneous Markdown characters\n- `escape_underscores`: Escape _ characters\n- `heading_style`: Header style (underlined/atx/atx_closed)\n- `keep_inline_images_in`: Tags where inline images should be kept\n- `newline_style`: Style for handling newlines (spaces/backslash)\n- `strip`: Tags to remove from output\n- `strong_em_symbol`: Symbol for strong/emphasized text (\\* or \\_)\n- `sub_symbol`: Symbol for subscript text\n- `sup_symbol`: Symbol for superscript text\n- `wrap`: Enable text wrapping\n- `wrap_width`: Width for text wrapping\n- `convert_as_inline`: Treat content as inline elements\n- `custom_converters`: A mapping of HTML tag names to custom converter functions\n\n## Contribution\n\nThis library is open to contribution. Feel free to open issues or submit PRs. Its better to discuss issues before\nsubmitting PRs to avoid disappointment.\n\n### Local Development\n\n1. Clone the repo\n\n1. Install the system dependencies\n\n1. Install the full dependencies with `uv sync`\n\n1. Install the pre-commit hooks with:\n\n    ```shell\n    pre-commit install \u0026\u0026 pre-commit install --hook-type commit-msg\n    ```\n\n1. Make your changes and submit a PR\n\n## License\n\nThis library uses the MIT license.\n\n## Acknowledgments\n\nSpecial thanks to the original [markdownify](https://pypi.org/project/markdownify/) project creators and contributors.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoldziher%2Fhtml-to-markdown","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoldziher%2Fhtml-to-markdown","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoldziher%2Fhtml-to-markdown/lists"}