quarto-wordcount
quarto-wordcount copied to clipboard
Adding Short codes
Hello, Great extension for quarto! I noticed that it only prints to the console, so I looked into adding shortcodes to the project. Much of the explanation was included into the template.qmd.
The main contribution:
- short codes:
- body count: {{< words-body >}}
- reference count: {{< words-ref >}}
- appendix count: {{< words-append >}}
- note count: {{< words-note >}}
- sum count: {{< words-sum ARG >}} where arg can be a concatenation of the other 4: body/ref/append/note.
Some other things:
- I added a separate count for notes. Some academic writing do not include foot notes towards word counts. In the current implementation, a foot note added in the body would be counted towards the body word count, and a foot note added in the references/appendix would be added to those counts. This pull request would separate these counts.
- fancy quotation characters
“and”were being counted as individual words. The newis_wordfunction now accounts for those. - I have noticed that word count currently does not account for callout blocks. This is largely due to how quarto handles them, which is like a special RawInLine. I think, however, this will be fixed in quarto 1.4 as the bug has been closed
Phew, apologies for the huge delay in reviewing this! This looks incredible and I'm really excited to add this support!
With Quarto 1.4.551 (the stable version as of right now), template.qmd isn't renderable. It looks like Quarto's shortcode Lua filter has changed or something
Here's a minimal reprex:
---
title: Some title
author: Some author
date: last-modified
format:
wordcount-html:
toc: false
---
Here are some words: {{< words-body >}}
And here's the error:
Error running filter /Applications/quarto/share/filters/main.lua:
string expected, got nil
while retrieving function argument text
while retrieving arguments for function Str
stack traceback:
...ds/quarto-wordcount-main/_extensions/wordcount/words.lua:4: in function <...ds/quarto-wordcount-main/_extensions/wordcount/words.lua:3>
(...tail calls...)
[string "..."]:1888: in function <[string "..."]:1886>
(...tail calls...)
/Applications/quarto/share/filters/main.lua:18293: in upvalue 'handle_shortcode'
/Applications/quarto/share/filters/main.lua:18338: in local 'filter_fn'
/Applications/quarto/share/filters/main.lua:302: in function </Applications/quarto/share/filters/main.lua:292>
(...tail calls...)
[C]: in ?
[C]: in method 'walk'
/Applications/quarto/share/filters/main.lua:224: in function </Applications/quarto/share/filters/main.lua:214>
(...tail calls...)
/Applications/quarto/share/filters/main.lua:18374: in field 'Pandoc'
/Applications/quarto/share/filters/main.lua:235: in function 'run_emulated_filter'
/Applications/quarto/share/filters/main.lua:942: in local 'callback'
/Applications/quarto/share/filters/main.lua:960: in upvalue 'run_emulated_filter_chain'
/Applications/quarto/share/filters/main.lua:996: in function </Applications/quarto/share/filters/main.lua:993>
stack traceback:
/Applications/quarto/share/filters/main.lua:224: in function </Applications/quarto/share/filters/main.lua:214>
(...tail calls...)
/Applications/quarto/share/filters/main.lua:18374: in field 'Pandoc'
/Applications/quarto/share/filters/main.lua:235: in function 'run_emulated_filter'
/Applications/quarto/share/filters/main.lua:942: in local 'callback'
/Applications/quarto/share/filters/main.lua:960: in upvalue 'run_emulated_filter_chain'
/Applications/quarto/share/filters/main.lua:996: in function </Applications/quarto/share/filters/main.lua:993>
The same error happens with Quarto v1.5.27, so they must have done something to break compatibility with this
Hey! I'll have a look later today and see if I can make heads or tails of it 👍
I haven't verified with quarto 1.5.*, but I think I corrected the issue in ba1bf19 . Could you check to see if the template renders and prints the correct word count numbers?
This is fantastic! Everything's working with 1.5+. I'll clean up the README and other documentation a bit and give it a bigger version bump
Thanks!
Oh wait, as I was updating the documentation and examples, I ran into an issue with the word-sum ARG shortcode, which breaks in Quarto 1.5 (not tested with 1.4, though); and it might be because I'm using the shortcode wrong (I've tried {{< words-sum body-note >}} and {{< words-sum body note >}} and {{< words-sum "body-note" >}} and they all cause the same error)
See https://github.com/andrewheiss/quarto-wordcount/issues/6