-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
marco-lancini
committed
Sep 21, 2023
1 parent
143069a
commit ed5353d
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |