Skip to content

Commit

Permalink
Lua filters: preload text module
Browse files Browse the repository at this point in the history
The `text` module is preloaded in lua. The module contains some UTF-8
aware string functions, implemented in Haskell.  The module is loaded on
request only, e.g.:

    text = require 'text'
    function Str (s)
      s.text = text.upper(s.text)
      return s
    end
  • Loading branch information
Albert Krewinkel committed Nov 16, 2017
1 parent 4e02ed5 commit a999675
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions pandoc.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ library
scientific >= 0.2 && < 0.4,
vector >= 0.10 && < 0.13,
hslua >= 0.9 && < 0.10,
hslua-module-text >= 0.1 && < 0.2,
binary >= 0.5 && < 0.9,
SHA >= 1.6 && < 1.7,
haddock-library >= 1.1 && < 1.5,
Expand Down
2 changes: 2 additions & 0 deletions src/Text/Pandoc/Lua.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import Text.Pandoc.Lua.PandocModule (pushMediaBagModule, pushPandocModule)
import Text.Pandoc.Lua.Filter (LuaFilter, walkMWithLuaFilter)
import Text.Pandoc.MediaBag (MediaBag)
import qualified Foreign.Lua as Lua
import qualified Foreign.Lua.Module.Text as Lua

runLuaFilter :: Maybe FilePath -> FilePath -> String
-> Pandoc -> PandocIO (Either LuaException Pandoc)
Expand All @@ -64,6 +65,7 @@ runLuaFilter' :: CommonState
-> Pandoc -> Lua Pandoc
runLuaFilter' commonState datadir filterPath format mbRef pd = do
Lua.openlibs
Lua.preloadTextModule "text"
-- store module in global "pandoc"
pushPandocModule datadir
Lua.setglobal "pandoc"
Expand Down
4 changes: 4 additions & 0 deletions stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ flags:
network-uri: true
packages:
- '.'
- location:
git: https://github.com/hslua/hslua-module-text
commit: 890ec312a91764738c4579b3a7505c8e55ecf1a5
extra-dep: true
extra-deps:
- pandoc-types-1.17.3
- hslua-0.9.2
Expand Down

0 comments on commit a999675

Please sign in to comment.