defmodule MDEx do @moduledoc """ A fast 100% CommonMark-compatible GitHub Flavored Markdown parser and formatter. Use Rust's [comrak crate](https://crates.io/crates/comrak) under the hood. """ alias MDEx.Native @doc """ Convert `markdown` to HTML. ## Examples iex> MDEx.to_html("# MDEx") "

MDEx

\\n" iex> MDEx.to_html("Implemented with:\\n1. Elixir\\n2. Rust") "

Implemented with:

\\n
    \\n
  1. Elixir
  2. \\n
  3. Rust
  4. \\n
\\n" """ @spec to_html(String.t()) :: String.t() def to_html(markdown) do Native.to_html(markdown) end @doc """ Convert `markdown` to HTML with custom `opts`. ## Options Accepts all available [Comrak Options](https://docs.rs/comrak/latest/comrak/struct.ComrakOptions.html) as keyword lists. * `:extension` - https://docs.rs/comrak/latest/comrak/struct.ComrakExtensionOptions.html * `:parse` - https://docs.rs/comrak/latest/comrak/struct.ComrakParseOptions.html * `:render` - https://docs.rs/comrak/latest/comrak/struct.ComrakRenderOptions.html ## Examples iex> MDEx.to_html("# MDEx") "

MDEx

\\n" iex> MDEx.to_html("Implemented with:\\n1. Elixir\\n2. Rust") "

Implemented with:

\\n
    \\n
  1. Elixir
  2. \\n
  3. Rust
  4. \\n
\\n" iex> MDEx.to_html("Hello ~world~ there", extension: [strikethrough: true]) "

Hello world there

\\n" iex> MDEx.to_html("visit https://https://beaconcms.org", extension: [autolink: true], render: [unsafe_: true]) "

visit https://https://beaconcms.org

\\n" """ @spec to_html(String.t()) :: String.t() def to_html(markdown, opts) do extension = Keyword.get(opts, :extension, %{}) parse = Keyword.get(opts, :parse, %{}) render = Keyword.get(opts, :render, %{}) opts = %MDEx.Options{ extension: struct(MDEx.ExtensionOptions, extension), parse: struct(MDEx.ParseOptions, parse), render: struct(MDEx.RenderOptions, render) } Native.to_html_with_options(markdown, opts) end end