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
hardbreaksoption was set. -
#normalize?
Returns true if the
normalizeoption was set. - #parse(&)
-
#smart?
Returns true if the
smartoption was set. -
#sourcepos?
Returns true if the
sourceposoption was set. -
#text : String
The original markdown text.
-
#to_commonmark(width = 80)
Renders
#textas a commonmark page. -
#to_html
Renders
#textas HTML. -
#to_latex(width = 80)
Renders
#textas a latex page. -
#to_man(width = 80)
Renders
#textas a man page. -
#to_xml
Renders
#textas XML. -
#unsafe?
Returns true if the
unsafeoption was set. -
#validate_utf8?
Returns true if the
validate_utf8option 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— rendersoftbreakelements as hard line breaks.unsafe— keep raw HTML and unsafe links (javascript:,vbscript:,file:, anddata:, except forimage/png,image/gif,image/jpeg, orimage/webpmime types). Raw HTML is replaced by a placeholder HTML comment. Unsafe links are replaced by empty strings.sourcepos— include adata-sourceposattribute 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.