From 2ab2c207451f46f8a36dd6b34eaed2d473a11777 Mon Sep 17 00:00:00 2001 From: Andrew Heiss Date: Wed, 16 Oct 2024 00:17:24 -0400 Subject: [PATCH] Add status banner --- README.md | 42 ++++++++++++++++++++++++++++ README.qmd | 34 ++++++++++++++++++++++ _extensions/wordcount/_extension.yml | 2 +- _extensions/wordcount/banner.html | 32 +++++++++++++++++++++ 4 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 _extensions/wordcount/banner.html diff --git a/README.md b/README.md index 4842ed8..d3cfb62 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ # Quarto word count +- [Experimental new feature!](#experimental-new-feature) - [Why counting words is hard](#why-counting-words-is-hard) - [Using the word count script](#using-the-word-count-script) - [Installing](#installing) @@ -18,6 +19,47 @@ +## Experimental new feature! + +> [!TIP] +> +> I’ve added an experimental new feature that lets you add a sticky +> status bar at the top of HTML documents to show the word count. I’ve +> found that this is *super helpful* when writing, since I don’t need to +> constantly check the terminal output. +> +> I haven’t figured out the best way to work with Lua filters and Quarto +> shortcodes (and getting filters/shortcodes to run in the right order), +> so for now the process is a little convoluted. +> +> 1. Enable `wordcount-banner: true` in the YAML front matter +> +> 2. Specify the content of the banner using the different shortcodes +> in `params: wordcount:` +> +> 3. Include an HTML file that uses Javascript to inject the status +> banner into the document. +> +> Here’s a minimal example: +> +> ``` qmd +> --- +> title: Something +> format: +> wordcount-html: +> wordcount-banner: true +> params: +> wordcount: | +> -1 total words: in the body • in the references • in the notes +> --- +> +> ::: {.content-visible when-meta="wordcount-banner"} +> {{< include _extensions/andrewheiss/wordcount/banner.html >}} +> ::: +> +> Actual text stuff goes here. +> ``` + ## Why counting words is hard In academic writing and publishing, word counts are important, since diff --git a/README.qmd b/README.qmd index 0ed7f5e..bae18f1 100644 --- a/README.qmd +++ b/README.qmd @@ -17,6 +17,40 @@ knitr::opts_chunk$set( ) ``` +## Experimental new feature! + +::: {.callout-tip} +I've added an experimental new feature that lets you add a sticky status bar at the top of HTML documents to show the word count. I've found that this is *super helpful* when writing, since I don't need to constantly check the terminal output. + +I haven't figured out the best way to work with Lua filters and Quarto shortcodes (and getting filters/shortcodes to run in the right order), so for now the process is a little convoluted. + +1. Enable `wordcount-banner: true` in the YAML front matter + +2. Specify the content of the banner using the different shortcodes in `params: wordcount: ` + +3. Include an HTML file that uses Javascript to inject the status banner into the document. + +Here's a minimal example: + +````qmd +--- +title: Something +format: + wordcount-html: + wordcount-banner: true +params: + wordcount: | + {{< words-sum body-note-ref >}} total words: {{< words-body >}} in the body • {{< words-ref >}} in the references • {{< words-note >}} in the notes +--- + +::: {.content-visible when-meta="wordcount-banner"} +{{{< include _extensions/andrewheiss/wordcount/banner.html >}}} +::: + +Actual text stuff goes here. +```` +::: + ## Why counting words is hard In academic writing and publishing, word counts are important, since many journals specify word limits for submitted articles. Counting how many words you have in a Quarto Markdown file is tricky, though, for a bunch of reasons: diff --git a/_extensions/wordcount/_extension.yml b/_extensions/wordcount/_extension.yml index 4f5f039..0b9f353 100644 --- a/_extensions/wordcount/_extension.yml +++ b/_extensions/wordcount/_extension.yml @@ -4,7 +4,7 @@ authors: orcid: 0000-0003-1866-860X - name: Justin Landis orcid: 0000-0001-5501-4934 -version: 1.5.0 +version: 1.6.0 quarto-required: ">=1.4.551" contributes: shortcodes: diff --git a/_extensions/wordcount/banner.html b/_extensions/wordcount/banner.html new file mode 100644 index 0000000..9af99b8 --- /dev/null +++ b/_extensions/wordcount/banner.html @@ -0,0 +1,32 @@ +