rstudio/htmltools

Document how to add an empty attribute

Closed this issue · 1 comments

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.

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!