rstudio / htmltools

Tools for HTML generation and output
https://rstudio.github.io/htmltools/
214 stars 67 forks source link

tagQuery does not allow ":" to exist in tag type when searching #356

Open thebioengineer opened 1 year ago

thebioengineer commented 1 year ago

I am working on some ooxml to support processing of {gt} into word outputs and I was hoping to use tagQuery to allow me to sort through the tags and make edits. tag types are prepended for docx outputs with w:. The current logic blocks me from using : anywhere in a tag because it does a simple search for : existing. Could there be a caveat in this if statement to check whether that call matches directly any tag types or something?

https://github.com/rstudio/htmltools/blob/39b3f1f6a4abef8acebc407d506d239d871d6a03/R/selector.R#L44

ie given the ooxml: </w:pPr></w:rPr>Test this</w:t></w:r></w:p>

if I want to access the text tag (w:t), the find (or any other cssSelector arg) complains about ::

library(htmltools)

## contructed html tag of ooxml containing a paragraph saying "test string"
x <- structure(list(name = "w:p", attribs = list(), children = list(
    structure("<w:pPr></w:pPr><w:r><w:rPr></w:rPr><w:t xml:space=\"default\">test string</w:t></w:r>", html = TRUE, class = c("html", 
    "character")))), class = "shiny.tag")
x_q <- tagQuery(x)
x_q$find("w:t")
schloerke commented 1 year ago

tagQuery does not work with XML name spaces. I would rather not make an exception for w: specifically as {gt} could change the namespace value.


In addition to the feature request, the code above would not work even if HTML namespaces were supported. The plain text HTML structure would not be searched. The text would need to be converted to tags before being able to be processed.

Related: https://github.com/rstudio/htmltools/issues/287