Split out wordcount and variable filters
This commit is contained in:
parent
3482586880
commit
aa320a927d
4 changed files with 15 additions and 22 deletions
4
build.sh
4
build.sh
|
@ -17,10 +17,10 @@ then
|
|||
INPUT_FILES="$INPUT_FILES $METADATA_FILE"
|
||||
fi
|
||||
|
||||
PANDOC_ARGS="$INPUT_FILES --template $SCRIPTPATH/main.tex -o $OUTPUT_FILE $ADDITIONAL_ARGS"
|
||||
PANDOC_ARGS="$INPUT_FILES --lua-filter=variables.lua --template $SCRIPTPATH/main.tex -o $OUTPUT_FILE $ADDITIONAL_ARGS"
|
||||
|
||||
echo "> Building document..."
|
||||
pandoc $PANDOC_ARGS
|
||||
|
||||
echo "> Running second pass..."
|
||||
pandoc --lua-filter=second-pass.lua $PANDOC_ARGS
|
||||
pandoc --lua-filter=word-count.lua $PANDOC_ARGS
|
||||
|
|
4
main.tex
4
main.tex
|
@ -16,13 +16,13 @@
|
|||
\author{Some Author}
|
||||
\date{2018-01-01}
|
||||
|
||||
$if(secondpass)$
|
||||
$if(wordcount)$
|
||||
\include{header-footer}
|
||||
$endif$
|
||||
|
||||
\begin{document}
|
||||
|
||||
$if(secondpass)$
|
||||
$if(wordcount)$
|
||||
\input{title}
|
||||
\tableofcontents
|
||||
$endif$
|
||||
|
|
|
@ -2,16 +2,6 @@ local vars = {}
|
|||
|
||||
local additionalChars = {".", ",", "!", ":", ";"}
|
||||
|
||||
function fileExists(name)
|
||||
local f=io.open(name,"r")
|
||||
if f~=nil then io.close(f) return true else return false end
|
||||
end
|
||||
|
||||
local function countWords()
|
||||
local rawText = pandoc.pipe("pdftotext", {"output.pdf", "-"}, "")
|
||||
return pandoc.pipe("wc", {"-w"}, rawText)
|
||||
end
|
||||
|
||||
local function getVars(meta)
|
||||
for k, v in pairs(meta) do
|
||||
if v.t == 'MetaInlines' then
|
||||
|
@ -24,18 +14,12 @@ local function getVars(meta)
|
|||
end
|
||||
end
|
||||
end
|
||||
return meta
|
||||
end
|
||||
|
||||
return {
|
||||
{
|
||||
Meta = function(meta)
|
||||
getVars(meta)
|
||||
if fileExists("output.pdf") then
|
||||
meta["wordcount"] = countWords()
|
||||
meta["secondpass"] = true
|
||||
end
|
||||
return meta
|
||||
end,
|
||||
Meta = getVars
|
||||
},
|
||||
{
|
||||
Str = function (el)
|
9
word-count.lua
Normal file
9
word-count.lua
Normal file
|
@ -0,0 +1,9 @@
|
|||
return {
|
||||
{
|
||||
Meta = function(meta)
|
||||
local rawText = pandoc.pipe("pdftotext", {"output.pdf", "-"}, "")
|
||||
meta["wordcount"] = pandoc.pipe("wc", {"-w"}, rawText)
|
||||
return meta
|
||||
end,
|
||||
},
|
||||
}
|
Reference in a new issue