Skip to content
/ cmark.ex Public
forked from asaaki/cmark.ex

Elixir NIF for cmark (C), a parser library following the CommonMark spec, a compatible implementation of Markdown.

License

Notifications You must be signed in to change notification settings

lowks/cmark.ex

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cmark

Hex.pm package version Hex.pm package license Build Status (master) Coverage Status (master) Inline docs Support via Gratipay

Elixir NIF for cmark (C), a parser library following the CommonMark spec.

CommonMark

A strongly specified, highly compatible implementation of Markdown

For more information visit http://commonmark.org/.

Install

Prerequisites

You need a C compiler like gcc or clang.

mix.exs

{ :cmark, "~> 0.5" }

Usage

Quick example

Cmark.to_html "a markdown string"
#=> "<p>a markdown string</p>\n"

Cmark.to_html/1

"test" |> Cmark.to_html
#=> "<p>test</p>\n"
["# also works", "* with list", "`of documents`"] |> Cmark.to_html
#=> ["<h1>also works</h1>\n",
#    "<ul>\n<li>with list</li>\n</ul>\n",
#    "<p><code>of documents</code></p>\n"]

Cmark.to_html/2

callback = fn (html) -> "HTML is #{html}" |> String.strip end
"test" |> Cmark.to_html(callback)
#=> "HTML is <p>test</p>"
callback = fn (htmls) ->
 Enum.map(htmls, &String.strip/1) |> Enum.join("<hr>")
end
["list", "test"] |> Cmark.to_html(callback)
#=> "<p>list</p><hr><p>test</p>"

Cmark.to_html_each/2

callback = fn (html) -> "HTML is #{html |> String.strip}" end
["list", "test"] |> Cmark.to_html_each(callback)
#=> ["HTML is <p>list</p>", "HTML is <p>test</p>"]

Licenses

About

Elixir NIF for cmark (C), a parser library following the CommonMark spec, a compatible implementation of Markdown.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 99.0%
  • Other 1.0%