erlmark_gleam

Fast Markdown to HTML conversion, powered by erlmark: a pure Erlang CommonMark 0.31.2 converter with the GFM tables, strikethrough and task-list extensions.

import erlmark_gleam as erlmark

pub fn main() {
  erlmark.to_html("# Hello *world*")
  // -> "<h1>Hello <em>world</em></h1>\n"

  "see www.example.com"
  |> erlmark.to_html_with(erlmark.new() |> erlmark.autolink)
}

Raw HTML in the input is passed through unchanged, as CommonMark requires. Sanitise the output if the input is untrusted. This package only runs on the Erlang target.

Types

Conversion options. Start from new and adjust with the builder functions.

pub opaque type Options

How many schedulers to convert a large document on. The output is identical to sequential conversion. Documents under 16 KB are never split.

pub type Parallel {
  Sequential
  Auto
  Workers(Int)
}

Constructors

  • Sequential

    Convert on the calling scheduler only. The default.

  • Auto

    Use every online scheduler.

  • Workers(Int)

    Use this many schedulers.

When to hand a conversion to a short-lived helper process with a pre-sized heap, which avoids most garbage collection.

pub type Threshold {
  Bytes(Int)
  Never
}

Constructors

  • Bytes(Int)

    Inputs larger than this many bytes use a helper process. The default is 256.

  • Never

    Always convert in the calling process.

Values

pub fn autolink(options: Options) -> Options

Turn bare www., http(s):// and ftp:// URLs and e-mail addresses into links. Conversion with extensions is always sequential.

pub fn new() -> Options

The default options: no extensions, sequential conversion, helper process above 256 bytes.

pub fn parallel(options: Options, parallel: Parallel) -> Options

Set the parallelism. Workers with fewer than one worker means Sequential.

pub fn spawn_above(
  options: Options,
  threshold: Threshold,
) -> Options

Set when conversion moves to a helper process. A negative byte count means zero.

pub fn tagfilter(options: Options) -> Options

Escape <script>, <style> and similar tags, as the GFM tagfilter does. Conversion with extensions is always sequential.

pub fn to_html(markdown: String) -> String

Convert Markdown to HTML with the default options.

to_html("*emphasis* and **strong**")
// -> "<p><em>emphasis</em> and <strong>strong</strong></p>\n"
pub fn to_html_with(markdown: String, options: Options) -> String

Convert Markdown to HTML with the given options.

"visit www.example.com"
|> to_html_with(new() |> autolink)
// -> "<p>visit <a href=\"http://www.example.com\">www.example.com</a></p>\n"
✨ Search Document