Skip to contents

This will search an XML document for a challenge marker and extract all of the block quotes that are ancestral to that marker so that we can extract the challenge blockquotes from the carpentries lessons.

Usage

get_challenges(body, type = c("block", "div", "chunk"))

Arguments

body

the XML body of a carpentries lesson (an xml2 object)

type

the type of element containing the challenges "block" is the default and will search for all of the blockquotes with liquid/kramdown markup, "div" will search for all div tags with class of challenge, and "chunk" will search for all of code chunks with the engine of challenge.

Value

an xml object.

Examples

loop <- Episode$new(file.path(lesson_fragment(), "_episodes", "14-looping-data-sets.md"))
get_challenges(loop$body, "block")
#> {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  ...
get_challenges(loop$unblock()$body, "div")
#> $`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-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-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 ...
#> 
loop$reset()
get_challenges(loop$use_dovetail()$unblock()$body, "chunk")
#> {xml_nodeset (3)}
#> [1] <code_block sourcepos="95:1-108:14" language="challenge" name="&quot;95:1 ...
#> [2] <code_block sourcepos="110:1-140:14" language="challenge" name="&quot;110 ...
#> [3] <code_block sourcepos="142:1-170:14" language="challenge" name="&quot;142 ...