From 24ef67213213b621a6c0f340e7bfdf68d2d40ac1 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Mon, 17 Apr 2017 11:54:42 +0200 Subject: Lua module: provide simple `read` format parser A single `read` function parsing pandoc-supported formats is added to the module. This is simpler and more convenient than the previous method of exposing all reader functions individually. --- data/pandoc.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'data') diff --git a/data/pandoc.lua b/data/pandoc.lua index dfa67cdcc..46155a575 100644 --- a/data/pandoc.lua +++ b/data/pandoc.lua @@ -796,6 +796,20 @@ M.UpperAlpha = "UpperAlpha" -- Helper Functions -- @section helpers +--- Parse the given string into a Pandoc document. +-- @tparam string markup the markup to be parsed +-- @tparam[opt] string format format specification, defaults to "markdown". +-- @return Doc pandoc document +function M.read(markup, format) + format = format or "markdown" + local pd = pandoc.__read(format, markup) + if type(pd) == "string" then + error(pd) + else + return pd + end +end + --- Use functions defined in the global namespace to create a pandoc filter. -- All globally defined functions which have names of pandoc elements are -- collected into a new table. -- cgit v1.2.3