commonmark

July 4, 2024 ยท View on GitHub

Package Version Hex Docs Erlang-compatible JavaScript-compatible

gleam add commonmark
import commonmark/html as commonmark
import gleam/io

pub fn main() {
  "# Hello, Gleam!

This is a test."
  |> commonmark.render_to_html
  |> io.println
  // -> "<h1>Hello, Gleam!</h1>\n<p>This is a test.</p>\n"
}

Further documentation can be found at https://hexdocs.pm/commonmark.

You can view this README as an AST here.

There is also an interactive demo which you can use to test how this library interacts with your documents.

Syntax support

Warning

๐Ÿšง This package is still heavily under construction ๐Ÿšง

Legend

  • โœ… - Completed
  • ๐Ÿšง - In Progress
  • โŒ - Unsupported

CommonMark

The current version of CommonMark targetted is 0.31.2.

  • โœ… Thematic breaks
  • โœ… ATX headings
  • โœ… Setext headings
  • โœ… Indented code blocks
  • โœ… Fenced code blocks
  • โŒ Link reference definitions
  • โœ… Paragraphs
  • โœ… Block quotes
  • ๐Ÿšง Ordered lists
  • ๐Ÿšง Unordered lists
  • โœ… Code spans
  • ๐Ÿšง Emphasis and strong emphasis
  • ๐Ÿšง Links
  • ๐Ÿšง Images
  • โœ… Autolinks
  • โœ… Hard line breaks
  • โœ… Soft line breaks

Raw HTML features will be tackled last as the potential security issues around this need to be considered.

  • โŒ HTML blocks
  • โŒ Inline HTML

Github Flavoured Markdown

The current version of GFM targetted is 0.29-gfm.

  • โŒ Tables
  • โœ… Strikethrough

Other extensions

Project structure

The commonmark package is just the parser as well as a simple HTML renderer which returns a string, mostly to facilitate checking CommonMark spec compliance. Most likely you want a specialised render for whatever framework you're using though.

Known renderer projects:

  • commonmark/commonmark is a CommonMark renderer, useful if you want to generate an AST and write out a document based on it.
  • commonmark/html is a HTML renderer included as part of this package.

Development

gleam test              # Run the tests
gleam shell             # Run an Erlang shell

Tools

cd tools/
gleam run -m benchmark  # Run the benchmarks
gleam run -m codegen    # Run the codegen tasks (these are committed in the repo)