rstudio / htmltools

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

Document how to add an empty attribute #426

Closed russHyde closed 3 months ago

russHyde commented 3 months ago

In tagAppendAttributes(), could we add an example to show how to add an empty attribute please.

The current examples are:

html <- div(a())
tagAppendAttributes(html, class = "foo")
<div class="foo">
  <a></a>
</div>

tagAppendAttributes(html, .cssSelector = "a", class = "bar")
<div>
  <a class="bar"></a>
</div>

tagHasAttribute(div(foo = "bar"), "foo")
[1] TRUE

tagGetAttribute(div(foo = "bar"), "foo")
[1] "bar"

So, could we add an example like:

tagAppendAttributes(html, `value-attribute` = 123, `empty-attribute` = NA)
<div value-attribute="123" empty-attribute>
  <a></a>
</div>

How to construct empty/flag attributes doesn't appear to be documented anywhere.

gadenbuie commented 3 months ago

How to construct empty/flag attributes doesn't appear to be documented anywhere.

It's documented in ?tags, but I agree that it's a bit out of the way when you're working with tagAppendAttributes(). I've added an example and improved the docs in #427.

Thanks for the suggestion @russHyde!