Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thisisnic/qmdparse
https://github.com/thisisnic/qmdparse
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/thisisnic/qmdparse
- Owner: thisisnic
- License: other
- Created: 2023-12-25T12:12:46.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-28T02:04:14.000Z (11 months ago)
- Last Synced: 2024-02-28T17:55:34.014Z (11 months ago)
- Language: R
- Size: 3.81 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![R-CMD-check](https://github.com/thisisnic/qmdparse/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/thisisnic/qmdparse/actions/workflows/R-CMD-check.yaml)
# qmdparse
A top-down recursive descent parser for qmd files.
Given this input `.qmd` file:
```
---
title: "my document"
format: html
editor: visual
---# Overview
In this document, I will talk about very little of meaning or merit.
# My First Real Section
This is where I tell you my grand idea!
## A Mere Subsection
While I merely am a subsection, I am mighty!
I contain code and everything!`` ```{r}
#| label: my_code
#| eval: TRUE
mean(mtcars$mpg)
`` ```
```We can parse it like so:
``` r
library(qmdparse)
out <- parse_qmd("/home/nic/qmdparse/tests/testthat/qmds/simple_doc.qmd")# Refer to sections of the document as nested lists
out[["My First Real Section"]][["A Mere Subsection"]]
#> ## A Mere Subsection
#> While I merely am a subsection, I am mighty!
#> I contain code and everything!
#>
#> ```{r}
#> #| label: my_code
#> #| eval: TRUE
#> mean(mtcars$mpg)
#> ```# Extract all code chunks
extract_code(out)
#> [[1]]
#> ```{r}
#> #| label: my_code
#> #| eval: TRUE
#> mean(mtcars$mpg)
#> ```# Extract a section based on its name
extract_named(out, "A Mere Subsection")
#> $`A Mere Subsection`
#> ## A Mere Subsection
#> While I merely am a subsection, I am mighty!
#> I contain code and everything!
#>
#> ```{r}
#> #| label: my_code
#> #| eval: TRUE
#> mean(mtcars$mpg)
#> ```# Extract all headings
extract_headings(out)
#> [[1]]
#> # Overview
#>
#> [[2]]
#> # My First Real Section
#>
#> [[3]]
#> ## A Mere Subsection# Print the AST of the document
print_tree(out)
#> simple_doc.qmd
#> ├──yaml
#> ├──markdown
#> ├──h1: Overview
#> └──markdown
#> └──h1: My First Real Section
#> ├──markdown
#> └──h2: A Mere Subsection
#> ├──markdown
#> └──code
```## Installation
You can install the latest version of qmdparse from [github](https://github.com/thisisnic/qmdparse) with:
```r
library(devtools)
devtools::install_github("thisisnic/qmdparse")
```## Similar work
Check out [parsermd](https://github.com/rundel/parsermd) for a `.rmd` parser based on C++ libraries or [lightparser](https://github.com/ThinkR-open/lightparser/) for a `.rmd` and `.qmd` parser based on knitr.