Skip to contents

This uses xml2::xml_root() and xml2::xml_path() to make a copy of the root document and then tag the corresponding nodes in the nodelist so that we can filter on nodes that are not connected to those present in the nodelist. This function is required for isolate_nodes() to work.

Usage

provision_isolation(nodelist)

Arguments

nodelist

an object of class xml_nodeset OR xml_node OR a list of either.

Value

a list of three elements:

  • doc: a copy of the document with the nodes isolated depending on the context

  • key: a string used to tag nodes that are isolated via the tnk-key attribute.

  • unrelated: an xml_nodeset containing nodes that have no ancestor, descendant, or self relationship to the nodes in nodelist.

See also

Other nodeset isolation functions: isolate_nodes()

Examples

path <- system.file("extdata", "show-example.md", package = "tinkr")
y <- tinkr::yarn$new(path, sourcepos = TRUE)
y$protect_math()$protect_curly()
items <- xml2::xml_find_all(y$body, ".//md:item", tinkr::md_ns())
tnk <- asNamespace("tinkr")
tnk$provision_isolation(items)
#> $doc
#> {xml_document}
#> <document sourcepos="1:1-47:42" xmlns="http://commonmark.org/xml/1.0">
#>  [1] <heading sourcepos="2:1-2:8" level="2">\n  <text sourcepos="2:4-2:8" xml ...
#>  [2] <heading sourcepos="4:1-4:12" level="3">\n  <text sourcepos="4:5-4:12" x ...
#>  [3] <paragraph sourcepos="6:1-6:59">\n  <text sourcepos="6:1-6:14" xml:space ...
#>  [4] <heading sourcepos="8:1-8:10" level="3">\n  <text sourcepos="8:5-8:10" x ...
#>  [5] <paragraph sourcepos="10:1-10:88">\n  <image sourcepos="10:1-10:52" dest ...
#>  [6] <heading sourcepos="12:1-12:8" level="2">\n  <text sourcepos="12:4-12:8" ...
#>  [7] <list sourcepos="14:1-24:0" type="bullet" tight="true">\n  <item sourcep ...
#>  [8] <heading sourcepos="25:1-25:7" level="2">\n  <text sourcepos="25:4-25:7" ...
#>  [9] <paragraph sourcepos="27:1-27:56">\n  <text sourcepos="27:1-27:26" xml:s ...
#> [10] <code_block sourcepos="29:1-37:3" info="r" xml:space="preserve" name=""> ...
#> [11] <heading sourcepos="39:1-39:7" level="2">\n  <text sourcepos="39:4-39:7" ...
#> [12] <paragraph sourcepos="41:1-41:70">\n  <text sourcepos="41:1-41:70" xml:s ...
#> [13] <paragraph sourcepos="43:1-45:2">\n  <text sourcepos="43:1-43:2" xml:spa ...
#> [14] <paragraph>\n  <link destination="https://example.com/anchor" title="" a ...
#> 
#> $key
#> [1] "1738682596"
#> 
#> $unrelated
#> {xml_nodeset (68)}
#>  [1] <heading sourcepos="2:1-2:8" level="2">\n  <text sourcepos="2:4-2:8" xml ...
#>  [2] <text sourcepos="2:4-2:8" xml:space="preserve">Links</text>
#>  [3] Links
#>  [4] <heading sourcepos="4:1-4:12" level="3">\n  <text sourcepos="4:5-4:12" x ...
#>  [5] <text sourcepos="4:5-4:12" xml:space="preserve">Relative</text>
#>  [6] Relative
#>  [7] <paragraph sourcepos="6:1-6:59">\n  <text sourcepos="6:1-6:14" xml:space ...
#>  [8] <text sourcepos="6:1-6:14" xml:space="preserve">Here are some </text>
#>  [9] Here are some 
#> [10] <link sourcepos="6:15-6:38" destination="#links" title="">\n  <text sour ...
#> [11] <text sourcepos="6:16-6:29" xml:space="preserve">relative links</text>
#> [12] relative links
#> [13] <text sourcepos="6:39-6:43" xml:space="preserve"> and </text>
#> [14]  and 
#> [15] <link sourcepos="6:44-6:57" destination="https://example.com/anchor" tit ...
#> [16] <text sourcepos="6:45-6:56" xml:space="preserve">anchor links</text>
#> [17] anchor links
#> [18] <text sourcepos="6:58-6:58" xml:space="preserve">.</text>
#> [19] .
#> [20] <heading sourcepos="8:1-8:10" level="3">\n  <text sourcepos="8:5-8:10" x ...
#> ...
#>