diff --git a/README.md b/README.md index f700360..2e9cde7 100644 --- a/README.md +++ b/README.md @@ -88,9 +88,19 @@ Some *Djot* content ### Pandoc AST alternative package -_Prerequisites:_ The [LuaJSON](https://github.com/harningt/luajson) module must be installed and available to your SILE environment. -This topic is not covered here. +_Prerequisites:_ Either [lunajson](https://github.com/grafi-tt/lunajson) or [LuaJSON](https://github.com/harningt/luajson) must be installed and available to your SILE environment. The former is recommended has no additional dependencies, and is straightforward to install: +```shell +luarocks install lunajson +``` + +The latter depends on the LPeg library, and this may require some additional tooling to be installed on your system (such as a C compiler, etc.). Moreover, as of 2024, the stable version has some issues, and you will need to install the development version instead: + +```shell +luarocks install --dev luajson +``` + +Ready to go? First, using the appropriate version of Pandoc, convert your file to a JSON AST: ```shell diff --git a/examples/sile-and-pandoc.dj b/examples/sile-and-pandoc.dj index ca3ba20..23ffc38 100644 --- a/examples/sile-and-pandoc.dj +++ b/examples/sile-and-pandoc.dj @@ -13,8 +13,13 @@ The following solution is still an experimental proof-of-concept, but you may gi ## Prerequisites Obviously, you need to have the Pandoc software installed on your system. -You also need to have the LuaJSON module installed and available to your SILE environment. -As of 2024, we recommend using the development version of the module, due to some issues with the current release version. +You also need a JSON parser, and this collection comes by default with the *lunajson* module as pre-installed dependency. +It is a Lua-only module, with no external dependencies, so it works out of the box. + +Another option is to use the *luajson* module, which is an LPeg-based parser, and might (or not) be more efficient in some cases. +On some systems, it may however require the LPeg library to be compiled and installed. +Luarocks{.nobreak} should take care of that for you, but it then assumes you have the necessary development tools on your system. +Moreover, as of 2024, the current release version of the module has some issues, so we recommend using the development version instead: {custom-style=CodeBlock} ::: @@ -23,6 +28,8 @@ luarocks install --dev luajson ``` ::: +If you have *luajson* installed, it is used instead of the default *lunajson* dependency. + ## Using Pandoc's AST with the pandocast package The experimental *pandocast* package allows you to use Pandoc’s JSON AST as an input format for documents. diff --git a/inputters/pandocast.lua b/inputters/pandocast.lua index 2efe739..7a95ca4 100644 --- a/inputters/pandocast.lua +++ b/inputters/pandocast.lua @@ -6,7 +6,7 @@ -- AST conversion relies on the Pandoc types specification: -- https://hackage.haskell.org/package/pandoc-types -- --- Using the LuaJSON library for parsing. +-- Using the luajson (LPEG-based) or lunajson (pure Lua) library for parsing. -- Reusing the common commands initially made for the "markdown" inputter/package. -- -- @copyright License: MIT (c) 2022-2024 Omikhleia, Didier Willis @@ -582,9 +582,16 @@ function inputter.appropriate (round, filename, doc) end function inputter:parse (doc) + -- Load JSON parser: + -- Luajson is LPEG-based, and lunajson is pure Lua without other + -- dependencies. Prioritize the former for if available, otherwise + -- fallback to lunajson, which we'll have in our dependencies. local has_json, json = pcall(require, "json.decode") if not has_json then - SU.error("The pandocast inputter requires LuaJSON's json.decode() to be available.") + has_json, json = pcall(require, "lunajson") + if not has_json then + SU.error("The pandocast inputter requires either luajson or lunajson to be available.") + end end local jsast = json.decode(doc) diff --git a/rockspecs/markdown.sile-2.2.0-1.rockspec b/rockspecs/markdown.sile-2.2.0-1.rockspec new file mode 100644 index 0000000..7fcdd9d --- /dev/null +++ b/rockspecs/markdown.sile-2.2.0-1.rockspec @@ -0,0 +1,62 @@ +rockspec_format = "3.0" +package = "markdown.sile" +version = "2.2.0-1" +source = { + url = "git+https://github.com/Omikhleia/markdown.sile.git", + tag = "v2.2.0", +} +description = { + summary = "Native Markdown support for the SILE typesetting system.", + detailed = [[ + This package set for the SILE typesetting system provides a complete redesign + of the native Markdown support for SILE, with a great set of Pandoc-like + extensions and plenty of extra goodies. + ]], + homepage = "https://github.com/Omikhleia/markdown.sile", + license = "MIT", +} +dependencies = { + "lua >= 5.1", + "embedders.sile >= 0.2.0", + "labelrefs.sile >= 0.1.0", + "ptable.sile >= 3.1.0", + "smartquotes.sile >= 1.0.0", + "textsubsuper.sile >= 1.1.1", + "silex.sile >= 0.6.0, < 1.0", + "lunajson", +} + +build = { + type = "builtin", + modules = { + ["sile.classes.markdown"] = "classes/markdown.lua", + ["sile.inputters.markdown"] = "inputters/markdown.lua", + ["sile.inputters.pandocast"] = "inputters/pandocast.lua", + ["sile.inputters.djot"] = "inputters/djot.lua", + ["sile.packages.markdown"] = "packages/markdown/init.lua", + ["sile.packages.markdown.cmbase"] = "packages/markdown/cmbase.lua", + ["sile.packages.markdown.commands"] = "packages/markdown/commands.lua", + ["sile.packages.markdown.utils"] = "packages/markdown/utils.lua", + ["sile.packages.pandocast"] = "packages/pandocast/init.lua", + ["sile.packages.djot"] = "packages/djot/init.lua", + + ["sile.lunamark"] = "lua-libraries/lunamark.lua", + ["sile.lunamark.entities"] = "lua-libraries/lunamark/entities.lua", + ["sile.lunamark.reader"] = "lua-libraries/lunamark/reader.lua", + ["sile.lunamark.reader.markdown"] = "lua-libraries/lunamark/reader/markdown.lua", + ["sile.lunamark.util"] = "lua-libraries/lunamark/util.lua", + ["sile.lunamark.writer"] = "lua-libraries/lunamark/writer.lua", + ["sile.lunamark.writer.generic"] = "lua-libraries/lunamark/writer/generic.lua", + ["sile.lunamark.writer.html"] = "lua-libraries/lunamark/writer/html.lua", + ["sile.lunamark.writer.html5"] = "lua-libraries/lunamark/writer/html5.lua", + + ["sile.djot"] = "lua-libraries/djot.lua", + ["sile.djot.attributes"] = "lua-libraries/djot/attributes.lua", + ["sile.djot.json"] = "lua-libraries/djot/json.lua", + ["sile.djot.block"] = "lua-libraries/djot/block.lua", + ["sile.djot.inline"] = "lua-libraries/djot/inline.lua", + ["sile.djot.html"] = "lua-libraries/djot/html.lua", + ["sile.djot.ast"] = "lua-libraries/djot/ast.lua", + ["sile.djot.filter"] = "lua-libraries/djot/filter.lua", + } +} diff --git a/rockspecs/markdown.sile-dev-1.rockspec b/rockspecs/markdown.sile-dev-1.rockspec index e13bf07..4c3bcdd 100644 --- a/rockspecs/markdown.sile-dev-1.rockspec +++ b/rockspecs/markdown.sile-dev-1.rockspec @@ -22,6 +22,7 @@ dependencies = { "smartquotes.sile", "textsubsuper.sile", "silex.sile", + "lunajson", } build = {