From e7eb21ecca46daaf240e33584c55b9d5101eebc7 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Sun, 2 Apr 2017 17:21:22 +0200 Subject: Lua module: add readers submodule Plain text readers are exposed to lua scripts via the `pandoc.reader` submodule, which is further subdivided by format. Converting e.g. a markdown string into a pandoc document is possible from within lua: doc = pandoc.reader.markdown.read_doc("Hello, World!") A `read_block` convenience function is provided for all formats, although it will still parse the whole string but return only the first block as the result. Custom reader options are not supported yet, default options are used for all parsing operations. --- test/Tests/Lua.hs | 6 ++++++ test/lua/markdown-reader.lua | 12 ++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 test/lua/markdown-reader.lua (limited to 'test') diff --git a/test/Tests/Lua.hs b/test/Tests/Lua.hs index 4f8bd46d8..27a4d8d6f 100644 --- a/test/Tests/Lua.hs +++ b/test/Tests/Lua.hs @@ -26,6 +26,12 @@ tests = "hello-world-doc.lua" (doc . para $ str "Hey!" <> linebreak <> str "What's up?") (doc . para $ str "Hello," <> space <> str "World!") + + , testCase "parse raw markdown blocks" $ + assertFilterConversion "raw markdown block is converted" + "markdown-reader.lua" + (doc $ rawBlock "markdown" "*charly* **delta**") + (doc . para $ emph "charly" <> space <> strong "delta") ] assertFilterConversion :: String -> FilePath -> Pandoc -> Pandoc -> Assertion diff --git a/test/lua/markdown-reader.lua b/test/lua/markdown-reader.lua new file mode 100644 index 000000000..6356113ec --- /dev/null +++ b/test/lua/markdown-reader.lua @@ -0,0 +1,12 @@ +return { + { + RawBlock = function (blk) + local format, content = unpack(blk.c) + if format == "markdown" then + return pandoc.reader.markdown.read_block(content) + else + return blk + end + end, + } +} -- cgit v1.2.3