add_class.Rd
Add a class to the root node of an HTML string
add_class(html, class_name)
html | Character. An HTML string. |
---|---|
class_name | Character. Class name to be added to the root node. |
Character. An HTML string with the class name added to the root node.
library(magrittr) html <- "<!-- function handles comments--><div><p>R is fun</div></p>" html %>% add_class("second-class")#> [1] "<!-- function handles comments--><div class=\"second-class\"><p>R is fun</div></p>"html %>% add_class(".ok-to-start-with-period")#> [1] "<!-- function handles comments--><div class=\"ok-to-start-with-period\"><p>R is fun</div></p>"html %>% add_class("you-can") %>% add_class("chain-function-calls-too")#> [1] "<!-- function handles comments--><div class=\"you-can chain-function-calls-too\"><p>R is fun</div></p>"html %>% add_class("or add five at once")#> [1] "<!-- function handles comments--><div class=\"or add five at once\"><p>R is fun</div></p>"html <- "<div class='using-single-quotes'><p>R is fun</div></p>" html %>% add_class("is-ok-too")#> [1] "<div class='using-single-quotes is-ok-too'><p>R is fun</div></p>"html <- "<div class = 'lots-of-spaces'><p>R is fun</div></p>" html %>% add_class("is-also-ok")#> [1] "<div class = 'lots-of-spaces is-also-ok'><p>R is fun</div></p>"