-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow code blocks to be optionally counted
- Loading branch information
1 parent
4998a78
commit f8cf097
Showing
7 changed files
with
311 additions
and
11 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
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,16 @@ | ||
--- | ||
title: "as-is results work" | ||
format: | ||
wordcount-markdown: | ||
count-code-blocks: true | ||
--- | ||
|
||
This sentence has seven words in it. | ||
|
||
```{r} | ||
#| echo: false | ||
#| results: asis | ||
output <- "Two words" | ||
cat(output) | ||
``` |
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,31 @@ | ||
--- | ||
title: "Code blocks disabled" | ||
format: | ||
wordcount-markdown: | ||
count-code-blocks: false | ||
--- | ||
|
||
This sentence has seven words in it.[^note] | ||
|
||
```{r} | ||
asdf <- 1:10 | ||
mean(asdf) | ||
``` | ||
|
||
[^note]: Here's some code: | ||
|
||
```{r indent=" "} | ||
zxcv <- 21:30 | ||
mean(zxcv) | ||
``` | ||
|
||
::: {#appendix-count} | ||
|
||
There are five words here. | ||
|
||
```{r} | ||
qwer <- 11:20 | ||
mean(qwer) | ||
``` | ||
|
||
::: |
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,31 @@ | ||
--- | ||
title: "Code blocks enabled" | ||
format: | ||
wordcount-markdown: | ||
count-code-blocks: true | ||
--- | ||
|
||
This sentence has seven words in it.[^note] | ||
|
||
```{r} | ||
asdf <- 1:10 | ||
mean(asdf) | ||
``` | ||
|
||
[^note]: Here's some code: | ||
|
||
```{r indent=" "} | ||
zxcv <- 21:30 | ||
mean(zxcv) | ||
``` | ||
|
||
::: {#appendix-count} | ||
|
||
There are five words here. | ||
|
||
```{r} | ||
qwer <- 11:20 | ||
mean(qwer) | ||
``` | ||
|
||
::: |
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,47 @@ | ||
test_that("disabling code block counting works", { | ||
test_file <- test_file_parts(here::here("tests/testthat/test-code-blocks-disabled.qmd")) | ||
|
||
create_local_quarto_project(test_file = test_file) | ||
|
||
quarto::quarto_render(input = test_file$qmd, quiet = TRUE) | ||
|
||
counts <- get_wordcounts(test_file$md) | ||
|
||
expect_equal(counts$wordcount_appendix_words, 5) | ||
expect_equal(counts$wordcount_body_words, 7) | ||
expect_equal(counts$wordcount_note_words, 3) | ||
expect_equal(counts$wordcount_ref_words, 0) | ||
expect_equal(counts$wordcount_total_words, 15) | ||
}) | ||
|
||
test_that("enabling code block counting works", { | ||
test_file <- test_file_parts(here::here("tests/testthat/test-code-blocks-enabled.qmd")) | ||
|
||
create_local_quarto_project(test_file = test_file) | ||
|
||
quarto::quarto_render(input = test_file$qmd, quiet = TRUE) | ||
|
||
counts <- get_wordcounts(test_file$md) | ||
|
||
expect_equal(counts$wordcount_appendix_words, 11) | ||
expect_equal(counts$wordcount_body_words, 13) | ||
expect_equal(counts$wordcount_note_words, 9) | ||
expect_equal(counts$wordcount_ref_words, 0) | ||
expect_equal(counts$wordcount_total_words, 33) | ||
}) | ||
|
||
test_that("as-is output from echo=false chunks gets counted", { | ||
test_file <- test_file_parts(here::here("tests/testthat/test-code-blocks-asis.qmd")) | ||
|
||
create_local_quarto_project(test_file = test_file) | ||
|
||
quarto::quarto_render(input = test_file$qmd, quiet = TRUE) | ||
|
||
counts <- get_wordcounts(test_file$md) | ||
|
||
expect_equal(counts$wordcount_appendix_words, 0) | ||
expect_equal(counts$wordcount_body_words, 9) | ||
expect_equal(counts$wordcount_note_words, 0) | ||
expect_equal(counts$wordcount_ref_words, 0) | ||
expect_equal(counts$wordcount_total_words, 9) | ||
}) |