defmodule MDEx do @external_resource "README.md" @moduledoc "README.md" |> File.read!() |> String.split("") |> Enum.fetch!(1) 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) when is_binary(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 * `:features` - see the available options below ### Features Options * `:sanitize` (default `false`) - sanitize output using [ammonia](https://crates.io/crates/ammonia).\n Recommended if passing `render: [unsafe_: true]` * `:syntax_highlight_theme` (default `"onedark"`) - syntax highlight code fences using [autumn themes](https://github.com/leandrocp/autumn/tree/main/priv/themes), you should pass the filename without special chars and without extension, for example you should pass `syntax_highlight_theme: "adwaita_dark"` to use the [Adwaita Dark](https://github.com/leandrocp/autumn/blob/main/priv/themes/adwaita-dark.toml) theme. ## 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" iex> MDEx.to_html("# Title with ", render: [unsafe_: true], features: [sanitize: true]) "

Title with

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