make_div_pairs: Create a data frame describing the divs associated with...

View source: R/div.R

make_div_pairsR Documentation

Create a data frame describing the divs associated with nodes.

Description

Native and fenced divs may have several tags grouped in a single element. In order to mark the pairs, we need to account for what tags exist in the nodes. This function creates that

Usage

make_div_pairs(nodes, path = NULL, yaml = NULL)

Arguments

nodes

a nodelist containing native div and fenced div tags in html_block or paragraphs.

Value

a list of data frames for each node with the following columns:

  • node: numeric index of the node

  • div: the text of the individual div element, stripped of context

  • label: label of the div pair (div-label-class)

  • pos: position the label will be relative to its associated node

See Also

Other div: clean_div_tags(), find_between_tags(), find_div_pairs(), get_divs(), label_div_tags(), label_pairs(), make_div(), replace_with_div()

Examples

txt <- "# Example with a mix of div tags

> PLEASE NEVER DO THE LESSONS THIS WAY
>
> I AM LITERALLY JUST TESTING A TERRIBLE EXAMPLE.

--------------------------------------------------------------------------------

<div class='challenge'>
## Challenge

do that challenging thing.

```{r}
cat('it might be challenging to do this')
```
:::: solution
```{r}
It's not that challenging
```
:::
<div class='solution'>
We just have to try harder and use `<div>` tags

:::::: callout
```{r}
cat('better faster stronger with <div>')
```
::::
:::::: discussion
<img src='https://carpentries.org/logo.svg'/>
:::::
</div>
</div>

<div class='good'>

## Good divs

</div>
" 
tmp <- tempfile()
writeLines(txt, tmp)
ex <- tinkr::to_xml(tmp)
pegboard:::clean_div_tags(ex$body)
nodes <- pegboard:::find_div_tags(ex$body)
divs  <- pegboard:::make_div_pairs(nodes)
do.call("rbind", divs)

carpentries/pegboard documentation built on Nov. 13, 2024, 8:53 a.m.