diff options
author | Christoph Helma <helma@in-silico.ch> | 2019-06-05 17:28:10 +0200 |
---|---|---|
committer | Christoph Helma <helma@in-silico.ch> | 2019-06-05 17:28:10 +0200 |
commit | 9a217185e791d6abbe46549cd4e87c1d1a643c05 (patch) | |
tree | 1968aebd8a38acd7784e58d478e0f6c3fb08ab76 /paper/lua-filters/wordcount/wordcount.lua | |
parent | feb1f82356da50a1ebf63b1eda434c388ab009e1 (diff) |
first manuscript version
Diffstat (limited to 'paper/lua-filters/wordcount/wordcount.lua')
-rw-r--r-- | paper/lua-filters/wordcount/wordcount.lua | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/paper/lua-filters/wordcount/wordcount.lua b/paper/lua-filters/wordcount/wordcount.lua new file mode 100644 index 0000000..19aec11 --- /dev/null +++ b/paper/lua-filters/wordcount/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: + pandoc.walk_block(pandoc.Div(el.blocks), wordcount) + print(words .. " words in body") + os.exit(0) +end |