defmodule Html2Markdown do @moduledoc """ Convert HTML documents to clean, readable Markdown. Html2Markdown intelligently extracts content from HTML while filtering out navigation, advertisements, and other non-content elements. It's designed for web scraping, content migration, and any scenario where you need to convert HTML to Markdown. ## Basic Usage iex> Html2Markdown.convert("

Hello

World

") "\\n# Hello\\n\\n\\n\\nWorld\\n" ## Configuration The library supports extensive configuration through the second parameter: Html2Markdown.convert(html, %{ navigation_classes: ["nav", "menu", "sidebar"], non_content_tags: ["script", "style", "iframe"], markdown_flavor: :basic, normalize_whitespace: true }) ## Features - **Smart filtering** - Automatically removes common non-content elements - **HTML5 support** - Handles modern semantic elements - **Table conversion** - Converts HTML tables to Markdown tables - **Entity decoding** - Automatically handled by Floki - **Whitespace normalization** - Optional cleanup of excessive whitespace - **Configurable** - Customize filtering behavior to your needs ## Examples ### Web Scraping # Extract article content from a web page {:ok, %{body: html}} = HTTPoison.get("https://example.com/article") content = Html2Markdown.convert(html, %{ navigation_classes: ["header", "footer", "nav", "sidebar"], normalize_whitespace: true }) ### Content Migration # Convert WordPress posts to Markdown post_html |> Html2Markdown.convert() |> File.write!("post.md") ### Email Processing # Clean up HTML emails email_body |> Html2Markdown.convert(%{ non_content_tags: ["style", "meta", "link"], navigation_classes: ["unsubscribe", "footer"] }) ## Supported HTML Elements ### Text Elements - Headings: `

` through `

` - Paragraphs: `

` - Emphasis: ``, `` → `*italic*` - Strong: ``, `` → `**bold**` - Strikethrough: `` → `~~strikethrough~~` - Code: `` → `` `code` `` - Preformatted: `

` → ``` code blocks ```

  ### Lists
  - Unordered lists: `