defmodule Htmd do @moduledoc """ A fast HTML to Markdown converter for Elixir, powered by Rust. Htmd provides a high-performance HTML to Markdown conversion using the Rust htmd crate as a Native Implemented Function (NIF). It supports extensive customization options for controlling the output format. ## Basic Usage iex> Htmd.convert("
Simple paragraph
") {:ok, "Simple paragraph"} """ @spec convert(html) :: {:ok, markdown} | {:error, error_reason} def convert(html) when is_binary(html) do Native.convert(html) end @doc """ Converts HTML string to Markdown with options. ## Options * `:heading_style` - `:atx` (default) or `:setex` * `:hr_style` - `:dashes` (default), `:underscores`, or `:stars` * `:br_style` - `:two_spaces` (default) or `:backslash` * `:link_style` - `:inlined` (default), `:inlined_prefer_autolinks`, or `:referenced` * `:link_reference_style` - `:full` (default), `:collapsed`, or `:shortcut` * `:code_block_style` - `:indented` (default) or `:fenced` * `:code_block_fence` - `:backticks` (default) or `:tildes` * `:bullet_list_marker` - `:asterisk` (default) or `:dash` * `:ul_bullet_spacing` - non-negative integer for spaces between bullet and content * `:ol_number_spacing` - non-negative integer for spaces between number and content * `:preformatted_code` - boolean to preserve whitespace in inline code tags * `:skip_tags` - list of tag names to skip during conversion ## Examples iex> Htmd.convert("
", skip_tags: ["img"])
{:ok, ""}
"""
@spec convert(html, options) :: {:ok, markdown} | {:error, error_reason}
def convert(html, options) when is_binary(html) do
convert_options = build_options(options)
Native.convert_with_options(html, convert_options)
end
@doc """
Converts HTML string to Markdown, silently returning an empty string on error.
## Examples
iex> Htmd.convert!("Simple paragraph
") "Simple paragraph" """ @spec convert!(html, options) :: binary() def convert!(html, options \\ []) when is_binary(html) do case convert(html, options) do {:ok, markdown} -> markdown {:error, _} -> "" end end defp build_options(options) when is_list(options) do struct(ConvertOptions, options) end defp build_options(%ConvertOptions{} = options), do: options end