diff --git a/docker/pandoc/Dockerfile b/docker/pandoc/Dockerfile index cebfeb3..45b2494 100644 --- a/docker/pandoc/Dockerfile +++ b/docker/pandoc/Dockerfile @@ -13,6 +13,10 @@ COPY docker/pandoc/requirements.txt /requirements.txt RUN pip3 install --no-cache-dir -r /requirements.txt \ && rm -f /requirements.txt +# Install custom filters +COPY docker/pandoc/filters/* /root/.pandoc/filters/ + +# Set working directory WORKDIR /data # Command diff --git a/docker/pandoc/filters/wordcount.lua b/docker/pandoc/filters/wordcount.lua new file mode 100644 index 0000000..bcaf9ac --- /dev/null +++ b/docker/pandoc/filters/wordcount.lua @@ -0,0 +1,29 @@ +-- counts words in a document + +words = 0 + +wordcount = { + Str = function(el) + -- we don't count a word if it's entirely punctuation: + if el.text:match("%P") then + words = words + 1 + end + end, + + Code = function(el) + _,n = el.text:gsub("%S+","") + words = words + n + end, + + CodeBlock = function(el) + _,n = el.text:gsub("%S+","") + words = words + n + end +} + +function Pandoc(el) + -- skip metadata, just count body: + el.blocks:walk(wordcount) + print(words .. " words in body") + os.exit(0) +end