Skip to contents

The commonmark package is used to translate markdown to XML, but it does not assign a namespace prefix, which means that xml2 will auto-assign a default prefix of d1.

Usage

md_ns()

Value

an xml_namespace object (see xml2::xml_ns())

Details

This function renames the default prefix to md, so that you can use XPath queries that are slightly more descriptive.

Examples


tink <- tinkr::to_xml(system.file("extdata", "example1.md", package = "tinkr"))
# with default namespace
xml2::xml_find_all(tink$body, 
  ".//d1:link[starts-with(@destination, 'https://ropensci')]"
)
#> {xml_nodeset (9)}
#> [1] <link destination="https://ropensci.org/blog/2018/08/21/birds-radolfzell/ ...
#> [2] <link destination="https://ropensci.org/blog/2018/09/04/birds-taxo-traits ...
#> [3] <link destination="https://ropensci.org/blog/2018/08/21/birds-radolfzell/ ...
#> [4] <link destination="https://ropensci.org/packages/" title="">\n  <text xml ...
#> [5] <link destination="https://ropensci.org/packages/" title="">\n  <text xml ...
#> [6] <link destination="https://ropensci.org/blog/2018/08/14/where-to-bird/" t ...
#> [7] <link destination="https://ropensci.org/blog/2018/08/21/birds-radolfzell/ ...
#> [8] <link destination="https://ropensci.org/blog/2018/08/28/birds-ocr/" title ...
#> [9] <link destination="https://ropensci.org/blog/2018/09/04/birds-taxo-traits ...
# with tinkr namespace
xml2::xml_find_all(tink$body, 
  ".//md:link[starts-with(@destination, 'https://ropensci')]",
  tinkr::md_ns()
)
#> {xml_nodeset (9)}
#> [1] <link destination="https://ropensci.org/blog/2018/08/21/birds-radolfzell/ ...
#> [2] <link destination="https://ropensci.org/blog/2018/09/04/birds-taxo-traits ...
#> [3] <link destination="https://ropensci.org/blog/2018/08/21/birds-radolfzell/ ...
#> [4] <link destination="https://ropensci.org/packages/" title="">\n  <text xml ...
#> [5] <link destination="https://ropensci.org/packages/" title="">\n  <text xml ...
#> [6] <link destination="https://ropensci.org/blog/2018/08/14/where-to-bird/" t ...
#> [7] <link destination="https://ropensci.org/blog/2018/08/21/birds-radolfzell/ ...
#> [8] <link destination="https://ropensci.org/blog/2018/08/28/birds-ocr/" title ...
#> [9] <link destination="https://ropensci.org/blog/2018/09/04/birds-taxo-traits ...