{"id":13405527,"url":"https://github.com/matthewwithanm/python-markdownify","last_synced_at":"2025-05-12T13:31:32.025Z","repository":{"id":3758526,"uuid":"4834499","full_name":"matthewwithanm/python-markdownify","owner":"matthewwithanm","description":"Convert HTML to Markdown","archived":false,"fork":false,"pushed_at":"2025-04-28T10:37:33.000Z","size":229,"stargazers_count":1577,"open_issues_count":20,"forks_count":158,"subscribers_count":13,"default_branch":"develop","last_synced_at":"2025-05-01T16:17:41.921Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"jason-thinkbridge/Dangarassociates.com","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/matthewwithanm.png","metadata":{"files":{"readme":"README.rst","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":"2012-06-29T16:30:23.000Z","updated_at":"2025-05-01T01:34:01.000Z","dependencies_parsed_at":"2024-04-04T19:51:36.506Z","dependency_job_id":"f9b33aad-2998-4d20-8bd4-18229a191daa","html_url":"https://github.com/matthewwithanm/python-markdownify","commit_stats":{"total_commits":216,"total_committers":29,"mean_commits":7.448275862068965,"dds":0.5462962962962963,"last_synced_commit":"43dbe20aaf9d11c38c9dab7d0e8f30dfdedf19e7"},"previous_names":[],"tags_count":46,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthewwithanm%2Fpython-markdownify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthewwithanm%2Fpython-markdownify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthewwithanm%2Fpython-markdownify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthewwithanm%2Fpython-markdownify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matthewwithanm","download_url":"https://codeload.github.com/matthewwithanm/python-markdownify/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253747741,"owners_count":21957797,"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":[],"created_at":"2024-07-30T19:02:04.666Z","updated_at":"2025-05-12T13:31:31.983Z","avatar_url":"https://github.com/matthewwithanm.png","language":"Python","funding_links":[],"categories":["Python","📝 Content \u0026 Text Extraction","📦 Additional Python Libraries","🙏 Acknowledgments"],"sub_categories":["Ruby","Documentation \u0026 File Processing","Example 2: Research a Topic"],"readme":"|build| |version| |license| |downloads|\n\n.. |build| image:: https://img.shields.io/github/actions/workflow/status/matthewwithanm/python-markdownify/python-app.yml?branch=develop\n    :alt: GitHub Workflow Status\n    :target: https://github.com/matthewwithanm/python-markdownify/actions/workflows/python-app.yml?query=workflow%3A%22Python+application%22\n\n.. |version| image:: https://img.shields.io/pypi/v/markdownify\n    :alt: Pypi version\n    :target: https://pypi.org/project/markdownify/\n\n.. |license| image:: https://img.shields.io/pypi/l/markdownify\n    :alt: License\n    :target: https://github.com/matthewwithanm/python-markdownify/blob/develop/LICENSE\n\n.. |downloads| image:: https://pepy.tech/badge/markdownify\n    :alt: Pypi Downloads\n    :target: https://pepy.tech/project/markdownify\n\nInstallation\n============\n\n``pip install markdownify``\n\n\nUsage\n=====\n\nConvert some HTML to Markdown:\n\n.. code:: python\n\n    from markdownify import markdownify as md\n    md('\u003cb\u003eYay\u003c/b\u003e \u003ca href=\"http://github.com\"\u003eGitHub\u003c/a\u003e')  # \u003e '**Yay** [GitHub](http://github.com)'\n\nSpecify tags to exclude:\n\n.. code:: python\n\n    from markdownify import markdownify as md\n    md('\u003cb\u003eYay\u003c/b\u003e \u003ca href=\"http://github.com\"\u003eGitHub\u003c/a\u003e', strip=['a'])  # \u003e '**Yay** GitHub'\n\n\\...or specify the tags you want to include:\n\n.. code:: python\n\n    from markdownify import markdownify as md\n    md('\u003cb\u003eYay\u003c/b\u003e \u003ca href=\"http://github.com\"\u003eGitHub\u003c/a\u003e', convert=['b'])  # \u003e '**Yay** GitHub'\n\n\nOptions\n=======\n\nMarkdownify supports the following options:\n\nstrip\n  A list of tags to strip. This option can't be used with the\n  ``convert`` option.\n\nconvert\n  A list of tags to convert. This option can't be used with the\n  ``strip`` option.\n\nautolinks\n  A boolean indicating whether the \"automatic link\" style should be used when\n  a ``a`` tag's contents match its href. Defaults to ``True``.\n\ndefault_title\n  A boolean to enable setting the title of a link to its href, if no title is\n  given. Defaults to ``False``.\n\nheading_style\n  Defines how headings should be converted. Accepted values are ``ATX``,\n  ``ATX_CLOSED``, ``SETEXT``, and ``UNDERLINED`` (which is an alias for\n  ``SETEXT``). Defaults to ``UNDERLINED``.\n\nbullets\n  An iterable (string, list, or tuple) of bullet styles to be used. If the\n  iterable only contains one item, it will be used regardless of how deeply\n  lists are nested. Otherwise, the bullet will alternate based on nesting\n  level. Defaults to ``'*+-'``.\n\nstrong_em_symbol\n  In markdown, both ``*`` and ``_`` are used to encode **strong** or\n  *emphasized* texts. Either of these symbols can be chosen by the options\n  ``ASTERISK`` (default) or ``UNDERSCORE`` respectively.\n\nsub_symbol, sup_symbol\n  Define the chars that surround ``\u003csub\u003e`` and ``\u003csup\u003e`` text. Defaults to an\n  empty string, because this is non-standard behavior. Could be something like\n  ``~`` and ``^`` to result in ``~sub~`` and ``^sup^``.  If the value starts\n  with ``\u003c`` and ends with ``\u003e``, it is treated as an HTML tag and a ``/`` is\n  inserted after the ``\u003c`` in the string used after the text; this allows\n  specifying ``\u003csub\u003e`` to use raw HTML in the output for subscripts, for\n  example.\n\nnewline_style\n  Defines the style of marking linebreaks (``\u003cbr\u003e``) in markdown. The default\n  value ``SPACES`` of this option will adopt the usual two spaces and a newline,\n  while ``BACKSLASH`` will convert a linebreak to ``\\\\n`` (a backslash and a\n  newline). While the latter convention is non-standard, it is commonly\n  preferred and supported by a lot of interpreters.\n\ncode_language\n  Defines the language that should be assumed for all ``\u003cpre\u003e`` sections.\n  Useful, if all code on a page is in the same programming language and\n  should be annotated with `````python`` or similar.\n  Defaults to ``''`` (empty string) and can be any string.\n\ncode_language_callback\n  When the HTML code contains ``pre`` tags that in some way provide the code\n  language, for example as class, this callback can be used to extract the\n  language from the tag and prefix it to the converted ``pre`` tag.\n  The callback gets one single argument, an BeautifylSoup object, and returns\n  a string containing the code language, or ``None``.\n  An example to use the class name as code language could be::\n\n    def callback(el):\n        return el['class'][0] if el.has_attr('class') else None\n\n  Defaults to ``None``.\n\nescape_asterisks\n  If set to ``False``, do not escape ``*`` to ``\\*`` in text.\n  Defaults to ``True``.\n\nescape_underscores\n  If set to ``False``, do not escape ``_`` to ``\\_`` in text.\n  Defaults to ``True``.\n\nescape_misc\n  If set to ``True``, escape miscellaneous punctuation characters\n  that sometimes have Markdown significance in text.\n  Defaults to ``False``.\n\nkeep_inline_images_in\n  Images are converted to their alt-text when the images are located inside\n  headlines or table cells. If some inline images should be converted to\n  markdown images instead, this option can be set to a list of parent tags\n  that should be allowed to contain inline images, for example ``['td']``.\n  Defaults to an empty list.\n\ntable_infer_header\n  Controls handling of tables with no header row (as indicated by ``\u003cthead\u003e``\n  or ``\u003cth\u003e``). When set to ``True``, the first body row is used as the header row.\n  Defaults to ``False``, which leaves the header row empty.\n\nwrap, wrap_width\n  If ``wrap`` is set to ``True``, all text paragraphs are wrapped at\n  ``wrap_width`` characters. Defaults to ``False`` and ``80``.\n  Use with ``newline_style=BACKSLASH`` to keep line breaks in paragraphs.\n  A `wrap_width` value of `None` reflows lines to unlimited line length.\n\nstrip_document\n  Controls whether leading and/or trailing separation newlines are removed from\n  the final converted document. Supported values are ``LSTRIP`` (leading),\n  ``RSTRIP`` (trailing), ``STRIP`` (both), and ``None`` (neither). Newlines\n  within the document are unaffected.\n  Defaults to ``STRIP``.\n\nbeautiful_soup_parser\n  Specify the Beautiful Soup parser to be used for interpreting HTML markup. Parsers such\n  as `html5lib`, `lxml` or even a custom parser as long as it is installed on the execution\n  environment. Defaults to ``html.parser``.\n\n.. _BeautifulSoup: https://www.crummy.com/software/BeautifulSoup/\n\nOptions may be specified as kwargs to the ``markdownify`` function, or as a\nnested ``Options`` class in ``MarkdownConverter`` subclasses.\n\n\nConverting BeautifulSoup objects\n================================\n\n.. code:: python\n\n    from markdownify import MarkdownConverter\n\n    # Create shorthand method for conversion\n    def md(soup, **options):\n        return MarkdownConverter(**options).convert_soup(soup)\n\n\nCreating Custom Converters\n==========================\n\nIf you have a special usecase that calls for a special conversion, you can\nalways inherit from ``MarkdownConverter`` and override the method you want to\nchange.\nThe function that handles a HTML tag named ``abc`` is called\n``convert_abc(self, el, text, parent_tags)`` and returns a string\ncontaining the converted HTML tag.\nThe ``MarkdownConverter`` object will handle the conversion based on the\nfunction names:\n\n.. code:: python\n\n    from markdownify import MarkdownConverter\n\n    class ImageBlockConverter(MarkdownConverter):\n        \"\"\"\n        Create a custom MarkdownConverter that adds two newlines after an image\n        \"\"\"\n        def convert_img(self, el, text, parent_tags):\n            return super().convert_img(el, text, parent_tags) + '\\n\\n'\n\n    # Create shorthand method for conversion\n    def md(html, **options):\n        return ImageBlockConverter(**options).convert(html)\n\n.. code:: python\n\n    from markdownify import MarkdownConverter\n\n    class IgnoreParagraphsConverter(MarkdownConverter):\n        \"\"\"\n        Create a custom MarkdownConverter that ignores paragraphs\n        \"\"\"\n        def convert_p(self, el, text, parent_tags):\n            return ''\n\n    # Create shorthand method for conversion\n    def md(html, **options):\n        return IgnoreParagraphsConverter(**options).convert(html)\n\n\nCommand Line Interface\n======================\n\nUse ``markdownify example.html \u003e example.md`` or pipe input from stdin\n(``cat example.html | markdownify \u003e example.md``).\nCall ``markdownify -h`` to see all available options.\nThey are the same as listed above and take the same arguments.\n\n\nDevelopment\n===========\n\nTo run tests and the linter run ``pip install tox`` once, then ``tox``.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatthewwithanm%2Fpython-markdownify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatthewwithanm%2Fpython-markdownify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatthewwithanm%2Fpython-markdownify/lists"}