clean_div_tags | R Documentation |
Clean the div tags from an xml document
clean_div_tags(body)
body |
an xml document |
Commonmark knows what raw HTML looks like and will read it in as an HTML
block, escaping the tag. it does this for every HTML tag that is preceded by
a blank line, so this: <div class='hello'>\n\n</div>
becomes two html_block
elements
<html_block> <div class='hello'>\n </html_block> <html_block> </div>\n </html_block>
However, if an element is not preceded by a non-html element, it becomes
part of that html element. So this <div class='hello'>\n</div>
becomes a
single html_block element:
<html_block> <div class='hello'>\n</div>\n </html_block>
Sometimes, this process can gobble up text that is markdown instead of HTML,
This function will find multiple tags in HTML blocks and separates them into different blocks.
TRUE
if divs were detected and cleaned, FALSE
if there were no
divs.
Other div:
find_between_tags()
,
find_div_pairs()
,
get_divs()
,
label_div_tags()
,
label_pairs()
,
make_div()
,
make_div_pairs()
,
replace_with_div()
txt <- "
<div class='challenge'>
## Challenge
do that challenging thing.
```{r}
cat('it might be challenging to do this')
```
<div class='solution'>
```{r}
It's not that challenging
```
</div>
<div class='solution'>
We just have to try harder and use `<div>` tags
```{r}
cat('better faster stronger with <div>')
```
<img src='https://carpentries.org/logo.svg'/>
</div>
</div>
<div class='good'>
## Good divs
</div>
"
library(purrr)
library(xml2)
f <- tempfile()
writeLines(txt, f)
ex <- tinkr::to_xml(f)
xml2::xml_find_all(ex$body, ".//d1:html_block[contains(text(), 'div')]")
pegboard:::clean_div_tags(ex$body)
xml2::xml_find_all(ex$body, ".//d1:html_block[contains(text(), 'div')]")
pegboard:::label_div_tags(ex$body)
xml2::xml_find_all(ex$body, ".//d1:html_block[contains(text(), 'div')]")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.