lua-resty-hoedown
is a Markdown, SmartyPants, buffer, and html and href/url escaping library implementing LuaJIT bindings to
Hoedown.
local hoedown = require "resty.hoedown"
hoedown[[
# Are you ready for the truth?
Now that there is the Tec-9, a crappy spray gun from South Miami.
This gun is advertised as the most popular gun in American crime.
Do you believe that shit? It actually says that in the little book
that comes with it: the most popular gun in American crime. Like
they're actually proud of that shit.
## I'm serious as a heart attack
The path of the righteous man is beset on all sides by the iniquities
of the selfish and the tyranny of evil men. Blessed is he who, in the
name of charity and good will, shepherds the weak through the valley
of darkness, for he is truly his brother's keeper and the finder of
lost children. And I will strike down upon thee with great vengeance
and furious anger those who would attempt to poison and destroy My
brothers.
]]
This will return string containing:
<h1>Are you ready for the truth?</h1>
<p>Now that there is the Tec-9, a crappy spray gun from South Miami.
This gun is advertised as the most popular gun in American crime.
Do you believe that shit? It actually says that in the little book
that comes with it: the most popular gun in American crime. Like
they're actually proud of that shit.</p>
<h2>I'm serious as a heart attack</h2>
<p>The path of the righteous man is beset on all sides by the iniquities
of the selfish and the tyranny of evil men. Blessed is he who, in the
name of charity and good will, shepherds the weak through the valley
of darkness, for he is truly his brother's keeper and the finder of
lost children. And I will strike down upon thee with great vengeance
and furious anger those who would attempt to poison and destroy My
brothers.</p>
Just place resty directory
somewhere in your package.path
. If you are using OpenResty, the default location would be /usr/local/openresty/lualib
.
Please check though that you do not overwrite the existing resty-directory if one exists already.
These are just rudimentary notes. Better installation instructions will follow:
- First download Hoedown from here: https://github.com/hoedown/hoedown
- Run
make
- Place
libhoedown.so
somewhere in the default search path for dynamic libraries of your operating system (or modifyresty/hoedown/library.lua
and pointffi_load("libhoedown")
with full path tolibhoedown.so
.
If you are using LuaRocks >= 2.2:
$ luarocks install lua-resty-hoedown
If you are using LuaRocks < 2.2:
$ luarocks install --server=http://rocks.moonscript.org moonrocks
$ moonrocks install lua-resty-hoedown
MoonRocks repository for lua-resty-hoedown
is located here: https://rocks.moonscript.org/modules/bungle/lua-resty-hoedown.
There are some functions called free
on the API (to be complete implementation of Hoedown). You don't really need to
call :free()
as the library automatically handles freeing the external resources using normal LuaJIT garbage collector
(the library registers the garbage collector handlers with ffi.gc
).
With extensions, you may extend how to document processing works. Here are the available extensions:
tables = HOEDOWN_EXT_TABLES,
fenced_code = HOEDOWN_EXT_FENCED_CODE,
footnotes = HOEDOWN_EXT_FOOTNOTES,
autolink = HOEDOWN_EXT_AUTOLINK,
strikethrough = HOEDOWN_EXT_STRIKETHROUGH,
underline = HOEDOWN_EXT_UNDERLINE,
highlight = HOEDOWN_EXT_HIGHLIGHT,
quote = HOEDOWN_EXT_QUOTE,
superscript = HOEDOWN_EXT_SUPERSCRIPT,
math = HOEDOWN_EXT_MATH,
no_intra_emphasis = HOEDOWN_EXT_NO_INTRA_EMPHASIS,
space_headers = HOEDOWN_EXT_SPACE_HEADERS,
math_explicit = HOEDOWN_EXT_MATH_EXPLICIT,
disable_indented_code = HOEDOWN_EXT_DISABLE_INDENTED_CODE
local hoedown = require "resty.hoedown"
print(hoedown.document.extensions.tables)
local doc = require "resty.hoedown.document"
local extensions = doc.extensions
print(extensions.tables)
With HTML rendering flags you can control the HTML rendering process. Hare are the available flags:
skip_html = HOEDOWN_HTML_SKIP_HTML,
escape = HOEDOWN_HTML_ESCAPE,
hard_wrap = HOEDOWN_HTML_HARD_WRAP,
use_xhtml = HOEDOWN_HTML_USE_XHTML
local hoedown = require "resty.hoedown"
print(hoedown.html.flags.skip_html)
local html = require "resty.hoedown.html"
local flags = html.flags
print(flags.use_xhtml)
These present values returned from resty.hoedown.html.is_tag
function.
The possible values are:
none = HOEDOWN_HTML_TAG_NONE,
open = HOEDOWN_HTML_TAG_OPEN,
close = HOEDOWN_HTML_TAG_CLOSE
local hoedown = require "resty.hoedown"
print(hoedown.html.tag.open)
local html = require "resty.hoedown.html"
local tag = html.tag
print(tag.open)
A helper library that you may require
with a single statement.
Helper function to rendering. source
is a string
containing a source document.
You can also pass in options with opts
argument. Here are the different options
that you may use (you can also skip passing options):
opts = {
renderer = ("html" or "html.toc" or function or nil),
extensions = (table or number or nil),
max_nesting = (number or nil),
flags = (table or number or nil),
nesting = (number or nil),
smartypants = (true or false or nil)
}
local hoedown = require "resty.hoedown"
print(hoedown[[
# Hello World
Hi this is Markdown.
]])
local flags = hoedown.html.flags
print(hoedown([[
# Hello World
Hi this is Markdown.
]], {
rendered = "html.toc",
nesting = 1,
flags = { flags.use_xhtml, "escape", 1 },
extensions = { "underline", "quote" },
smartypants = true
}))
This returns a buffer
module.
This returns a document
module.
This returns an html
module.
This returns an escape
module.
This returns a version
module.
lua-resty-hoedown
uses two clause BSD license.
Copyright (c) 2014, Aapo Talvensaari
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.