rundel / parsermd

https://rundel.github.io/parsermd/
Other
76 stars 4 forks source link

Teach `parse_rmd()` about callouts #32

Open jennybc opened 1 year ago

jennybc commented 1 year ago

Every now and then I'm reminded that this package is so handy! Currently I'm facing the problem that the section labels in the R Packages book should really follow a convention and they currently don't. And this package is very useful for gathering reasonably tidy data about how things currently are.

One thing I've noticed is that parsermd doesn't know about quarto callouts, which we are using frequently in R Packages (which is now a quarto book):

::: callout-tip
## Title of the callout
Here's a super handy nifty thing!
:::

Notice the use of a ## heading as the syntax for a callout's title.

Right now parsermd thinks this is a real heading.

Example with the vignettes chapter of R Packages. All of the "Submitting to CRAN" heading are actually callouts.

library(tidyverse)
library(parsermd)

file <- "vignettes.Rmd"
(rmd <- parse_rmd(file) |> 
    rmd_select(has_type("rmd_heading")))
#> └── Heading [h1] - Vignettes {#sec-vignettes}
#>     ├── Heading [h2] - Introduction
#>     ├── Heading [h2] - Workflow for writing a vignette {#sec-vignettes-workflow-writing}
#>     ├── Heading [h2] - Metadata
#>     ├── Heading [h2] - Advice on writing vignettes
#>     │   └── Heading [h3] - Diagrams
#>     ├── Heading [h2] - Submitting to CRAN
#>     │   ├── Heading [h3] - Links
#>     │   ├── Heading [h3] - Filepaths
#>     │   ├── Heading [h3] - How many vignettes?
#>     │   └── Heading [h3] - Scientific publication
#>     ├── Heading [h2] - Special considerations for vignette code
#>     │   └── Heading [h3] - Article instead of vignette {#sec-vignettes-article}
#>     ├── Heading [h2] - How vignettes are built and checked {#sec-vignettes-how-built-checked}
#>     │   └── Heading [h3] - `R CMD build` and vignettes {#sec-vignettes-how-built}
#>     ├── Heading [h2] - Pre-built vignettes (or other documentation)
#>     │   └── Heading [h3] - `R CMD check` and vignettes {#sec-vignettes-how-checked}
#>     └── Heading [h2] - Submitting to CRAN