summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml22
-rw-r--r--data/pandoc.lua25
-rw-r--r--src/Text/Pandoc/Lua/PandocModule.hs24
-rw-r--r--stack.pkg.yaml2
4 files changed, 45 insertions, 28 deletions
diff --git a/.travis.yml b/.travis.yml
index ef5641dc0..f8264f67b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -31,29 +31,31 @@ matrix:
include:
# We grab the appropriate GHC and cabal-install versions from hvr's PPA. See:
# https://github.com/hvr/multi-ghc-travis
- - env: BUILD=cabal GHCVER=7.8.4 CABALVER=1.18 OPTS="-O0 -Wall -fno-warn-unused-do-bind -Werror" FLAGS="fast embed_data_files"
+ - env: BUILD=cabal GHCVER=7.8.4 CABALVER=1.18 OPTS="-O0 -Wall -fno-warn-unused-do-bind -Werror" FLAGS="fast embed_data_files" CABALARGS="--enable-benchmarks"
compiler: ": #GHC 7.8.4"
addons: {apt: {packages: [cabal-install-1.18,ghc-7.8.4,happy-1.19.5], sources: [hvr-ghc]}}
- - env: BUILD=cabal GHCVER=7.10.3 CABALVER=1.22 OPTS="-O0 -Wall -fno-warn-unused-do-bind -Werror" FLAGS="fast embed_data_files"
+ # don't build benchmarks for ghc 7.10.3, because build takes too long...
+ - env: BUILD=cabal GHCVER=7.10.3 CABALVER=1.22 OPTS="-O0 -Wall -fno-warn-unused-do-bind -Werror" FLAGS="fast embed_data_files" CABALARGS=""
compiler: ": #GHC 7.10.3"
addons: {apt: {packages: [cabal-install-1.22,ghc-7.10.3,happy-1.19.5], sources: [hvr-ghc]}}
- - env: BUILD=cabal GHCVER=8.0.2 CABALVER=1.24 OPTS="-O0 -Wall -Wincomplete-record-updates -Wnoncanonical-monad-instances -Wnoncanonical-monadfail-instances -fno-warn-unused-do-bind -Werror" FLAGS="fast"
+ # don't build benchmarks for ghc 8.0.2, because build takes too long...
+ - env: BUILD=cabal GHCVER=8.0.2 CABALVER=1.24 OPTS="-O0 -Wall -Wincomplete-record-updates -Wnoncanonical-monad-instances -Wnoncanonical-monadfail-instances -fno-warn-unused-do-bind -Werror" FLAGS="fast" CABALARGS=""
compiler: ": #GHC 8.0.2"
addons: {apt: {packages: [cabal-install-1.24,ghc-8.0.2,happy-1.19.5], sources: [hvr-ghc]}}
- - env: BUILD=cabal GHCVER=8.2.1 CABALVER=1.24 OPTS="-O0 -Wall -Wincomplete-record-updates -Wnoncanonical-monad-instances -Wnoncanonical-monadfail-instances -fno-warn-unused-do-bind -Werror" FLAGS="fast embed_data_files"
+ - env: BUILD=cabal GHCVER=8.2.1 CABALVER=1.24 OPTS="-O0 -Wall -Wincomplete-record-updates -Wnoncanonical-monad-instances -Wnoncanonical-monadfail-instances -fno-warn-unused-do-bind -Werror" FLAGS="fast embed_data_files" CABALARGS="--enable-benchmarks"
compiler: ": #GHC 8.2.1"
addons: {apt: {packages: [cabal-install-1.24,ghc-8.2.1,happy-1.19.5], sources: [hvr-ghc]}}
- - env: BUILD=cabal GHCVER=8.2.1 CABALVER=2.0 OPTS="-O0 -Wall -Wincomplete-record-updates -Wnoncanonical-monad-instances -Wnoncanonical-monadfail-instances -fno-warn-unused-do-bind -Werror" FLAGS="fast embed_data_files"
+ - env: BUILD=cabal GHCVER=8.2.1 CABALVER=2.0 OPTS="-O0 -Wall -Wincomplete-record-updates -Wnoncanonical-monad-instances -Wnoncanonical-monadfail-instances -fno-warn-unused-do-bind -Werror" FLAGS="fast embed_data_files" CABALARGS="--enable-benchmarks"
compiler: ": #GHC 8.2.1"
addons: {apt: {packages: [cabal-install-2.0,ghc-8.2.1,happy-1.19.5], sources: [hvr-ghc]}}
# Build with the newest GHC and cabal-install. This is an accepted failure,
# see below.
- # - env: BUILD=cabal GHCVER=head CABALVER=head
+ # - env: BUILD=cabal GHCVER=head CABALVER=head CABALAGS="--allow-newer"
# compiler: ": #GHC HEAD"
# addons: {apt: {packages: [cabal-install-head,ghc-head], sources: [hvr-ghc]}}
@@ -85,10 +87,6 @@ matrix:
before_install:
# Using compiler above sets CC to an invalid value, so unset it
- unset CC
-
-# We want to always allow newer versions of packages when building on GHC HEAD
-- CABALARGS=""
-- if [ "x$GHCVER" = "xhead" ]; then CABALARGS=--allow-newer; fi
- export PATH=$PATH:/opt/happy/1.19.5/bin/:/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$HOME/.local/bin:$HOME/.cabal/bin
# Download and unpack the stack executable
- |
@@ -114,7 +112,7 @@ install:
cabal)
cabal --version
travis_retry cabal update
- cabal install -j --only-dependencies --flags="$FLAGS" --enable-tests --enable-benchmarks --force-reinstalls --ghc-options=-O0 --reorder-goals --max-backjumps=-1 $CABALARGS
+ cabal install -j --only-dependencies --flags="$FLAGS" --enable-tests --force-reinstalls --ghc-options="-O0" --reorder-goals --max-backjumps=-1 $CABALARGS
;;
esac
@@ -129,7 +127,7 @@ script:
cabal)
cabal sdist --output-directory=sourcedist && \
cd sourcedist && \
- cabal configure --enable-tests --enable-benchmarks -v2 --flags="$FLAGS" --ghc-options="$OPTS" && \
+ cabal configure --enable-tests -v2 --flags="$FLAGS" --ghc-options="$OPTS" $CABALARGS && \
cabal build && \
cabal test
;;
diff --git a/data/pandoc.lua b/data/pandoc.lua
index bce4e9326..fc83103e0 100644
--- a/data/pandoc.lua
+++ b/data/pandoc.lua
@@ -782,7 +782,7 @@ M.UpperAlpha = "UpperAlpha"
-- assert(block.content[1].t == "Emph")
function M.read(markup, format)
format = format or "markdown"
- local pd = pandoc.__read(format, markup)
+ local pd = pandoc._read(format, markup)
if type(pd) == "string" then
error(pd)
else
@@ -790,6 +790,29 @@ function M.read(markup, format)
end
end
+--- Runs command with arguments, passing it some input, and returns the output.
+-- @treturn string Output of command.
+-- @usage
+-- local ec, output = pandoc.pipe("sed", {"-e","s/a/b/"}, "abc")
+function M.pipe (command, args, input)
+ local ec, output = pandoc._pipe(command, args, input)
+ if ec ~= 0 then
+ err = setmetatable(
+ { command = command, error_code = ec, output = output},
+ { __tostring = function(e)
+ return "Error running " .. e.command
+ .. " (error code " .. e.error_code .. "): "
+ .. e.output
+ end
+ }
+ )
+ -- TODO: drop the wrapping call to `tostring` as soon as hslua supports
+ -- non-string error objects.
+ error(tostring(err))
+ end
+ return output
+end
+
--- Use functions defined in the global namespace to create a pandoc filter.
-- All globally defined functions which have names of pandoc elements are
-- collected into a new table.
diff --git a/src/Text/Pandoc/Lua/PandocModule.hs b/src/Text/Pandoc/Lua/PandocModule.hs
index 6a84a4350..f9b072dff 100644
--- a/src/Text/Pandoc/Lua/PandocModule.hs
+++ b/src/Text/Pandoc/Lua/PandocModule.hs
@@ -41,6 +41,7 @@ import Data.IORef
import Data.Maybe (fromMaybe)
import Data.Text (pack)
import Foreign.Lua (Lua, FromLuaStack, ToLuaStack, NumResults, liftIO)
+import Foreign.Lua.FunctionCalling (ToHaskellFunction)
import Text.Pandoc.Class (readDataFile, runIO,
runIOorExplode, setUserDataDir, CommonState(..),
putCommonState, fetchItem, setMediaBag)
@@ -62,15 +63,9 @@ pushPandocModule datadir = do
script <- liftIO (pandocModuleScript datadir)
status <- Lua.loadstring script
unless (status /= Lua.OK) $ Lua.call 0 1
- Lua.push "__read"
- Lua.pushHaskellFunction readDoc
- Lua.rawset (-3)
- Lua.push "sha1"
- Lua.pushHaskellFunction sha1HashFn
- Lua.rawset (-3)
- Lua.push "pipe"
- Lua.pushHaskellFunction pipeFn
- Lua.rawset (-3)
+ addFunction "_pipe" pipeFn
+ addFunction "_read" readDoc
+ addFunction "sha1" sha1HashFn
-- | Get the string representation of the pandoc module
pandocModuleScript :: Maybe FilePath -> IO String
@@ -102,11 +97,12 @@ pushMediaBagModule commonState mediaBagRef = do
addFunction "list" (mediaDirectoryFn mediaBagRef)
addFunction "fetch" (fetch commonState mediaBagRef)
return ()
- where
- addFunction name fn = do
- Lua.push name
- Lua.pushHaskellFunction fn
- Lua.rawset (-3)
+
+addFunction :: ToHaskellFunction a => String -> a -> Lua ()
+addFunction name fn = do
+ Lua.push name
+ Lua.pushHaskellFunction fn
+ Lua.rawset (-3)
sha1HashFn :: BL.ByteString
-> Lua NumResults
diff --git a/stack.pkg.yaml b/stack.pkg.yaml
index 73179eb5b..5f2985cb4 100644
--- a/stack.pkg.yaml
+++ b/stack.pkg.yaml
@@ -14,7 +14,7 @@ packages:
- '.'
- location:
git: https://github.com/jgm/pandoc-citeproc.git
- commit: d13bd7ca04fc9549b64e43b3d466b70da8398ef1
+ commit: d41aa82e8c0aac3c7e71ad7b300bbe0a380e65f0
extra-dep: false
extra-deps:
- pandoc-types-1.17.2