Malt can render Markdown via Kramdown.
Lets say we have a Markdown document called ‘test.md’ containing:
# Example This is an example of Markdown rendering.
Markdown documents are recognized by the .markdown
or .md
file extensions. These engine used by setting the :engine option.
html = Malt.render(:file=>'test.md', :engine=>:kramdown)
Notice that Kramdown provides some bonus features compared to the other rendering engines.
html.assert.include?('<h1 id="example">Example</h1>')
We can access the file via the Malt.file
method. Markdown documents are recognized by the .markdown
or .md
file extensions.
mark = Malt.file('test.md', :engine=>:kramdown)
We can the convert the document to a Malt Html object via the #to_html method.
html = mark.to_html
Notice that the output is an instance of Malt::Format::HTML.
html.class.assert == Malt::Format::HTML
And that by calling #to_s we can get the rendered HTML document.
html.to_s.assert.include?('<h1 id="example">Example</h1>')
Or we can convert the document directly to HTML via the #html method.
out = mark.html out.assert.include?('<h1 id="example">Example</h1>')