Home

Awesome

markd

Language Tag Build Status

THIS PROJECT IS LOOKING FOR MAINTAINER

Unfortunately, the maintainer no longer has the time and/or resources to work on markd further. This means that bugs will not be fixed and features will not be added unless someone else does so.

If you're interested in fixing up markd, please file an issue let me know.

<hr />

Yet another markdown parser built for speed, written in Crystal, Compliant to CommonMark specification (v0.29). Copy from commonmark.js.

Installation

Add this to your application's shard.yml:

dependencies:
  markd:
    github: icyleaf/markd

Quick start

require "markd"

markdown = <<-MD
# Hello Markd

> Yet another markdown parser built for speed, written in Crystal, Compliant to CommonMark specification.
MD

html = Markd.to_html(markdown)

Also here are options to configure the parse and render.

options = Markd::Options.new(smart: true, safe: true)
Markd.to_html(markdown, options)

Options

NameTypeDefault valueDescription
timeBoolfalserender parse cost time during read source, parse blocks, parse inline.
smartBoolfalseif true, straight quotes will be made curly,<br />-- will be changed to an en dash,<br />--- will be changed to an em dash, and<br />... will be changed to ellipses.
source_posBoolfalseif true, source position information for block-level elements<br />will be rendered in the data-sourcepos attribute (for HTML)
safeBoolfalseif true, raw HTML will not be passed through to HTML output (it will be replaced by comments)
prettyprintBoolfalseif true, code tags generated by code blocks will have a prettyprint class added to them, to be used by Google code-prettify.
gfmBoolfalseNot supported for now
tocBoolfalseNot supported for now
base_urlURI?nilif not nil, relative URLs of links are resolved against this URI. It act's like HTML's <base href="base_url"> in the context of a Markdown document.

Advanced

If you want to use a custom renderer, it can!


class CustomRenderer < Markd::Renderer

  def strong(node, entering)
  end

  # more methods following in render.
end

options = Markd::Options.new(time: true)
document = Markd::Parser.parse(markdown, options)
renderer = CustomRenderer.new(options)

html = renderer.render(document)

Performance

Here is the result of a sample markdown file parse at MacBook Pro Retina 2015 (2.2 GHz):

Crystal Markdown (no longer present)   3.28k (305.29µs) (± 0.92%)       fastest
           Markd                       305.36 (  3.27ms) (± 5.52%) 10.73× slower

Recently, I'm working to compare the other popular commonmark parser, the code is stored in benchmarks.

How to Contribute

Your contributions are always welcome! Please submit a pull request or create an issue to add a new question, bug or feature to the list.

All Contributors are on the wall.

You may also like

License

MIT License © icyleaf