1{-# LANGUAGE NoImplicitPrelude #-}
3Copyright © 2017–2018 Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation; either version 2 of the License, or
8(at your option) any later version.
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 Module : Text.Pandoc.Lua
21 Copyright : Copyright © 2017–2018 Albert Krewinkel
22 License : GNU GPL, version 2 or above
24 Maintainer : Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
27Running pandoc Lua filters.
36import Control.Monad ((>=>))
37import Foreign.Lua (FromLuaStack (peek), Lua, LuaException (..),
38 Status (OK), ToLuaStack (push))
39import Text.Pandoc.Class (PandocIO)
40import Text.Pandoc.Definition (Pandoc)
41import Text.Pandoc.Lua.Filter (LuaFilter, walkMWithLuaFilter)
42import Text.Pandoc.Lua.Init (runPandocLua, registerScriptPath)
43import Text.Pandoc.Lua.Util (popValue)
44import Text.Pandoc.Options (ReaderOptions)
45import qualified Foreign.Lua as Lua
47-- | Run the Lua filter in @filterPath@ for a transformation to target
48-- format @format@. Pandoc uses Lua init files to setup the Lua
50runLuaFilter :: ReaderOptions -> FilePath -> String
51 -> Pandoc -> PandocIO (Either LuaException Pandoc)
52runLuaFilter ropts filterPath format doc =
53 runPandocLua (runLuaFilter' ropts filterPath format doc)
55runLuaFilter' :: ReaderOptions -> FilePath -> String
56 -> Pandoc -> Lua Pandoc
57runLuaFilter' ropts filterPath format pd = do
60 registerScriptPath filterPath
62 stat <- Lua.dofile filterPath
66 Lua.throwLuaError luaErrMsg
69 -- Use the returned filters, or the implicitly defined global filter if
70 -- nothing was returned.
71 luaFilters <- if newtop - top >= 1
73 else Lua.getglobal "_G" *> fmap (:[]) popValue
78 Lua.setglobal "FORMAT"
80 registerReaderOptions = do
82 Lua.setglobal "PANDOC_READER_OPTIONS"
84runAll :: [LuaFilter] -> Pandoc -> Lua Pandoc
85runAll = foldr ((>=>) . walkMWithLuaFilter) return
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list