class CommonMark

Overview

Crystal wrapper for libcmark, the reference CommonMark C library.

md = CommonMark.new(text)

Render to another format:

md.to_html  # => HTML
md.to_man   # => man page

Defined in:

common_mark.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(text : String, sourcepos = false, hardbreaks = false, normalize = false, validate_utf8 = false, smart = false, unsafe = false) #

Initializes a new CommonMark parser.

md = CommonMark.new(text, smart: true)
md.to_html

Options:

  • hardbreak — render softbreak elements as hard line breaks.
  • unsafe — keep raw HTML and unsafe links (javascript:, vbscript:, file:, and data:, except for image/png, image/gif, image/jpeg, or image/webp mime types). Raw HTML is replaced by a placeholder HTML comment. Unsafe links are replaced by empty strings.
  • sourcepos — include a data-sourcepos attribute on all block elements.
  • smart — convert straight quotes to curly, --- to em dashes, -- to en dashes.
  • normalize — normalize tree by consolidating adjacent text nodes.
  • validate_utf8 — Validate UTF-8 in the input before parsing, replacing illegal sequences with the replacement character U+FFFD.

[View source]

Instance Method Detail

def hardbreaks? #

Returns true if the hardbreaks option was set.


[View source]
def normalize? #

Returns true if the normalize option was set.


[View source]
def parse(&) #

[View source]
def smart? #

Returns true if the smart option was set.


[View source]
def sourcepos? #

Returns true if the sourcepos option was set.


[View source]
def text : String #

The original markdown text.


[View source]
def to_commonmark(width = 80) #

Renders #text as a commonmark page.


[View source]
def to_html #

Renders #text as HTML.


[View source]
def to_latex(width = 80) #

Renders #text as a latex page.


[View source]
def to_man(width = 80) #

Renders #text as a man page.


[View source]
def to_xml #

Renders #text as XML.


[View source]
def unsafe? #

Returns true if the unsafe option was set.


[View source]
def validate_utf8? #

Returns true if the validate_utf8 option was set.


[View source]