find_between_tags: Find nodes between two nodes with a given dtag

View source: R/div.R

find_between_tagsR Documentation

Find nodes between two nodes with a given dtag

Description

Find nodes between two nodes with a given dtag

Usage

find_between_tags(
  tag,
  body,
  ns = "pb",
  find = "dtag[@label='{tag}']",
  include = FALSE
)

Arguments

tag

an integer representing a unique dtag attribute

body

an xml document

ns

the namespace from the body

find

an xpath element to search for (without namespace tag)

include

if TRUE, the tags themselves will be included in the output

Value

a nodeset between tags that have the dtag attribute matching tag

See Also

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

Examples

loop <- Episode$new(file.path(lesson_fragment(), "_episodes", "14-looping-data-sets.md"))
loop$body # a full document with block quotes and code blocks, etc
loop$unblock() # removing blockquotes and replacing with div tags
# find all the div tags
ns <- pegboard:::get_ns(loop$body)
tags <- xml2::xml_find_all(loop$body, ".//pb:dtag", ns)
tags <- xml2::xml_attr(tags, "label")
tags
# grab the contents of the first div tag
pegboard:::find_between_tags(tags[[1]], loop$body)

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