Skip to contents

Walks a .qmd and picks out the elements that have stable identity across formats: headings and code chunks. Prose is deliberately ignored — it is the part that must be rewritten rather than carried over. YAML front matter is skipped, and # inside a code chunk is not mistaken for a heading.

Usage

parse_qmd(path)

Arguments

path

Path to a .qmd file.

Value

A list of blocks, each a list with a type of either "heading" (with level and text) or "chunk" (with lines).

Examples

chapter <- withr::local_tempfile(fileext = ".qmd")
writeLines(c("# Title", "", "Some prose.", "", "## A section"), chapter)
parse_qmd(chapter)
#> [[1]]
#> [[1]]$type
#> [1] "heading"
#> 
#> [[1]]$level
#> [1] 1
#> 
#> [[1]]$text
#> [1] "Title"
#> 
#> 
#> [[2]]
#> [[2]]$type
#> [1] "heading"
#> 
#> [[2]]$level
#> [1] 2
#> 
#> [[2]]$text
#> [1] "A section"
#> 
#>