add wordcount calculation
Signed-off-by: Christine Dodrill <me@christine.website>
This commit is contained in:
parent
f9403010cd
commit
d297449035
@ -9,3 +9,5 @@ echo $FILES
|
|||||||
|
|
||||||
pandoc -o ../out/Spellblade.epub --resource-path=. title.txt $FILES
|
pandoc -o ../out/Spellblade.epub --resource-path=. title.txt $FILES
|
||||||
ebook-convert ../out/Spellblade.epub ../out/Spellblade.mobi
|
ebook-convert ../out/Spellblade.epub ../out/Spellblade.mobi
|
||||||
|
|
||||||
|
pandoc --lua-filter wordcount.lua $FILES
|
||||||
|
30
src/wordcount.lua
Normal file
30
src/wordcount.lua
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
-- counts words in a document
|
||||||
|
-- from https://pandoc.org/lua-filters.html#examples
|
||||||
|
|
||||||
|
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
|
Loading…
x
Reference in New Issue
Block a user