aboutsummaryrefslogtreecommitdiffhomepage
path: root/wordcount.lua
diff options
context:
space:
mode:
authorMarvin Borner2023-07-06 22:03:08 +0200
committerMarvin Borner2023-07-06 22:31:46 +0200
commit6afe0a6961a959454d08f89fcfbb8a545902aa17 (patch)
treecdd4abe3b22addd31e2cd1b2fa727824267c1d30 /wordcount.lua
Initial commit
Diffstat (limited to 'wordcount.lua')
-rw-r--r--wordcount.lua27
1 files changed, 27 insertions, 0 deletions
diff --git a/wordcount.lua b/wordcount.lua
new file mode 100644
index 0000000..9cac82e
--- /dev/null
+++ b/wordcount.lua
@@ -0,0 +1,27 @@
+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)
+ os.exit(0)
+end