Open thothal opened 3 years ago
What do you think, would it make sense to include such a funciton into htmltools?
Perhaps someday, but I don't think we'll have the incentive/bandwidth to add it for awhile. That said, preferably the logic would depend on {xml2}
, not {XML}
OK, thanks for the feedback. Would a PR with some code like this ({xml2}
based) stand a chance to be included?
Motivation
Suppose you use a function from a package which returns an HTML string. You can use this string with
htmltools
viaHTML
, but the result is not really satisfactory as the following example shows:Current workaround requires falling back to string replacement, which is cumbersome and error prone.
Thus, a converter / parser which transforms HTML strings into
tags
would be tremendously helpful.Proposal
I found a small shiny app, which used
library(XML)
to do this sort of parsing and based on this I came up with the following lines:Some simple tests
Granted, the function is not injective, thus, it does not (yet) guarnatee
x == html_to_tags(as.character(x))
, but from what I can judge (not being an expert inHTML
and all its specifities), the resultingHTML
should be rather equivalent.What do you think, would it make sense to include such a funciton into
htmltools
?Update Using
{xml2}