class CommonMark
- CommonMark
- Reference
- Object
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.crConstructors
-
.new(text : String, sourcepos = false, hardbreaks = false, normalize = false, validate_utf8 = false, smart = false, unsafe = false)
Initializes a new CommonMark parser.
Instance Method Summary
-
#hardbreaks?
Returns true if the
hardbreaks
option was set. -
#normalize?
Returns true if the
normalize
option was set. - #parse(&)
-
#smart?
Returns true if the
smart
option was set. -
#sourcepos?
Returns true if the
sourcepos
option was set. -
#text : String
The original markdown text.
-
#to_commonmark(width = 80)
Renders
#text
as a commonmark page. -
#to_html
Renders
#text
as HTML. -
#to_latex(width = 80)
Renders
#text
as a latex page. -
#to_man(width = 80)
Renders
#text
as a man page. -
#to_xml
Renders
#text
as XML. -
#unsafe?
Returns true if the
unsafe
option was set. -
#validate_utf8?
Returns true if the
validate_utf8
option was set.
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
— rendersoftbreak
elements as hard line breaks.unsafe
— keep raw HTML and unsafe links (javascript:
,vbscript:
,file:
, anddata:
, except forimage/png
,image/gif
,image/jpeg
, orimage/webp
mime types). Raw HTML is replaced by a placeholder HTML comment. Unsafe links are replaced by empty strings.sourcepos
— include adata-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.