项目作者: tarleb

项目描述 :
DEPRECATED (use pandoc 2 Lua filters instead): Custom json writer for portable pandoc filtering without external programs
高级语言: Lua
项目地址: git://github.com/tarleb/panlunatic.git
创建时间: 2016-12-17T20:32:16Z
项目社区:https://github.com/tarleb/panlunatic

开源协议:ISC License

下载


Panlunatic

:warning: DEPRECATED :warning: This package is no longer maintained. Use
pandoc’s Lua filters instead.

github release
license
travis build status

Panlunatic writers are Lua scripts intended to be used instead of filters.
Pandoc includes its very own lua interpreter, so no other software than pandoc
is required to process a document AST via a panlunatic writer.

Installation

An archive containing all required lua files can be downloaded from this
project’s GitHub release page.
It will usually be most convenient to simply unpack it directly into the
directory from which you run pandoc.

The lua interpreter must be able to find the files panlunatic.lua and
dkjson.lua. Set the LUA_PATH environment variable if these files are not in
the current working directory.

  1. export LUA_PATH="/path/to/panlunatic/?.lua;;"

The library can then be included from custom pandoc writers via require "panlunatic".

Alternatively, panlunatic can also be installed
via luarocks by running

  1. luarocks install --local panlunatic

Usage

The examples/undiv.lua and examples/emph2strong.lua scripts serve as
examples and are intended to be copied or modified. Define a new function in
your script to alter elements of the element type with the same name. The
output of the script should be valid JSON describing a pandoc document. This
allows to read the result back into pandoc.

  1. pandoc -t examples/undiv.lua input.md | pandoc -f json -t OUTFORMAT

Examples

The following will turn emphasised text into strong text:

  1. panluna = require("panlunatic")
  2. Emph = panluna.Strong
  3. setmetatable(_G, {__index = panluna})

Unwrap all contents from Div elements:

  1. panluna = require("panlunatic")
  2. function Div(s, attr)
  3. return s
  4. end
  5. setmetatable(_G, {__index = panlunatic})

Remove list items starting with “NOPE”; note the decoding of the JSON string
containing the list items:

  1. panluna = require("panlunatic")
  2. function BulletList(items)
  3. new_items = {}
  4. for _, item_str in pairs(items) do
  5. item = panlunatic.decode('[' .. item_str .. ']')
  6. if item[1].c[1].c ~= "NOPE" then
  7. table.insert(new_items, item_str)
  8. end
  9. end
  10. if #new_items == 0 then
  11. return ""
  12. end
  13. return panlunatic.BulletList(new_items)
  14. end
  15. setmetatable(_G, {__index = panlunatic})