Skip to contents

This modifies a document to replace a blockquote element with a div element

Usage

replace_with_div(block)

Arguments

block

a blockquote element

Value

the children of the element, invisibly

Examples

frg <- Lesson$new(lesson_fragment())
lop <- frg$episodes$`14-looping-data-sets.md`
xml2::xml_find_all(lop$body, ".//d1:html_block")
#> {xml_nodeset (2)}
#> [1] <html_block sourcepos="174:1-174:86" xml:space="preserve">&lt;img src="ht ...
#> [2] <html_block sourcepos="176:1-176:49" xml:space="preserve">&lt;img src=".. ...
lop$get_blocks(level = 1)
#> {xml_nodeset (3)}
#> [1] <block_quote sourcepos="95:1-108:14" ktag="{: .challenge}">\n  <heading s ...
#> [2] <block_quote sourcepos="110:1-140:14" ktag="{: .challenge}">\n  <heading  ...
#> [3] <block_quote sourcepos="142:1-170:14" ktag="{: .challenge}">\n  <heading  ...
lop$get_blocks(level = 2)
#> {xml_nodeset (3)}
#> [1] <block_quote sourcepos="104:3-108:14" ktag="{: .solution}">\n  <heading s ...
#> [2] <block_quote sourcepos="128:3-140:14" ktag="{: .solution}">\n  <heading s ...
#> [3] <block_quote sourcepos="147:3-170:14" ktag="{: .solution}">\n  <heading s ...
purrr::walk(lop$get_blocks(level = 2), pegboard:::replace_with_div)
purrr::walk(lop$get_blocks(level = 1), pegboard:::replace_with_div)
lop$get_blocks()
#> {xml_nodeset (0)}
# add tags
pegboard:::label_div_tags(lop$body)
lop$get_divs()
#> $`div-1-challenge`
#> {xml_nodeset (9)}
#> [1] <paragraph xmlns="http://commonmark.org/xml/1.0">\n  <text xml:space="pre ...
#> [2] <heading sourcepos="95:3-95:24" level="2">\n  <text sourcepos="95:6-95:24 ...
#> [3] <paragraph sourcepos="97:3-97:87">\n  <text sourcepos="97:3-97:26" xml:sp ...
#> [4] <list sourcepos="99:3-103:1" type="ordered" start="1" delim="period" tigh ...
#> [5] <paragraph xmlns="http://commonmark.org/xml/1.0">\n  <text xml:space="pre ...
#> [6] <heading sourcepos="104:5-104:15" level="2">\n  <text sourcepos="104:8-10 ...
#> [7] <paragraph sourcepos="106:5-108:14">\n  <text sourcepos="106:5-106:33" xm ...
#> [8] <paragraph xmlns="http://commonmark.org/xml/1.0">\n  <text xml:space="pre ...
#> [9] <paragraph xmlns="http://commonmark.org/xml/1.0">\n  <text xml:space="pre ...
#> 
#> $`div-2-solution`
#> {xml_nodeset (4)}
#> [1] <paragraph xmlns="http://commonmark.org/xml/1.0">\n  <text xml:space="pre ...
#> [2] <heading sourcepos="104:5-104:15" level="2">\n  <text sourcepos="104:8-10 ...
#> [3] <paragraph sourcepos="106:5-108:14">\n  <text sourcepos="106:5-106:33" xm ...
#> [4] <paragraph xmlns="http://commonmark.org/xml/1.0">\n  <text xml:space="pre ...
#> 
#> $`div-3-challenge`
#> {xml_nodeset (10)}
#>  [1] <paragraph xmlns="http://commonmark.org/xml/1.0">\n  <text xml:space="pr ...
#>  [2] <heading sourcepos="110:3-110:22" level="2">\n  <text sourcepos="110:6-1 ...
#>  [3] <paragraph sourcepos="112:3-113:39">\n  <text sourcepos="112:3-112:64" x ...
#>  [4] <code_block sourcepos="115:3-123:5" xml:space="preserve" name="" ktag="{ ...
#>  [5] <paragraph sourcepos="124:3-126:72">\n  <text sourcepos="125:3-125:16" x ...
#>  [6] <paragraph xmlns="http://commonmark.org/xml/1.0">\n  <text xml:space="pr ...
#>  [7] <heading sourcepos="128:5-128:15" level="2">\n  <text sourcepos="128:8-1 ...
#>  [8] <code_block sourcepos="129:5-137:7" xml:space="preserve" name="" ktag="{ ...
#>  [9] <paragraph xmlns="http://commonmark.org/xml/1.0">\n  <text xml:space="pr ...
#> [10] <paragraph xmlns="http://commonmark.org/xml/1.0">\n  <text xml:space="pr ...
#> 
#> $`div-4-solution`
#> {xml_nodeset (4)}
#> [1] <paragraph xmlns="http://commonmark.org/xml/1.0">\n  <text xml:space="pre ...
#> [2] <heading sourcepos="128:5-128:15" level="2">\n  <text sourcepos="128:8-12 ...
#> [3] <code_block sourcepos="129:5-137:7" xml:space="preserve" name="" ktag="{: ...
#> [4] <paragraph xmlns="http://commonmark.org/xml/1.0">\n  <text xml:space="pre ...
#> 
#> $`div-5-challenge`
#> {xml_nodeset (9)}
#> [1] <paragraph xmlns="http://commonmark.org/xml/1.0">\n  <text xml:space="pre ...
#> [2] <heading sourcepos="142:3-142:19" level="2">\n  <text sourcepos="142:6-14 ...
#> [3] <paragraph sourcepos="144:3-146:20">\n  <text sourcepos="144:3-144:54" xm ...
#> [4] <paragraph xmlns="http://commonmark.org/xml/1.0">\n  <text xml:space="pre ...
#> [5] <heading sourcepos="147:5-147:15" level="2">\n  <text sourcepos="147:8-14 ...
#> [6] <paragraph sourcepos="148:5-151:31">\n  <text sourcepos="148:5-148:61" xm ...
#> [7] <code_block sourcepos="152:5-167:7" xml:space="preserve" name="" ktag="{: ...
#> [8] <paragraph xmlns="http://commonmark.org/xml/1.0">\n  <text xml:space="pre ...
#> [9] <paragraph xmlns="http://commonmark.org/xml/1.0">\n  <text xml:space="pre ...
#> 
#> $`div-6-solution`
#> {xml_nodeset (5)}
#> [1] <paragraph xmlns="http://commonmark.org/xml/1.0">\n  <text xml:space="pre ...
#> [2] <heading sourcepos="147:5-147:15" level="2">\n  <text sourcepos="147:8-14 ...
#> [3] <paragraph sourcepos="148:5-151:31">\n  <text sourcepos="148:5-148:61" xm ...
#> [4] <code_block sourcepos="152:5-167:7" xml:space="preserve" name="" ktag="{: ...
#> [5] <paragraph xmlns="http://commonmark.org/xml/1.0">\n  <text xml:space="pre ...
#> 
xml2::xml_text(lop$get_divs()[[1]])
#> [1] ":::::::::::::::::::::::::::::::::::::::  challenge"                                                             
#> [2] "Determining Matches"                                                                                            
#> [3] "Which of these files is not matched by the expression glob.glob('data/*as*.csv')?"                              
#> [4] "data/gapminder_gdp_africa.csvdata/gapminder_gdp_americas.csvdata/gapminder_gdp_asia.csv1 and 2 are not matched."
#> [5] ":::::::::::::::  solution"                                                                                      
#> [6] "Solution"                                                                                                       
#> [7] "1 is not matched by the glob."                                                                                  
#> [8] ":::::::::::::::::::::::::"                                                                                      
#> [9] "::::::::::::::::::::::::::::::::::::::::::::::::::"