| Title: | 'HTML' Element Construction |
| Version: | 1.0.0 |
| Description: | Provides a deterministic, framework-agnostic Domain-Specific Language for building 'HTML' nodes and rendering them to a string. |
| License: | MIT + file LICENSE |
| URL: | https://github.com/sigflux/hypertext |
| BugReports: | https://github.com/sigflux/hypertext/issues |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.3 |
| Suggests: | testthat (≥ 3.0.0) |
| Config/testthat/edition: | 3 |
| NeedsCompilation: | no |
| Packaged: | 2026-02-23 02:52:02 UTC; mwavu |
| Author: | Kennedy Mwavu |
| Maintainer: | Kennedy Mwavu <mwavukennedy@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-02-27 20:00:02 UTC |
Escape special HTML characters
Description
Replaces &, <, >, ", and ' with their HTML entity equivalents.
Usage
.escape_html(x)
Arguments
x |
A character string. |
Value
A character string with HTML special characters escaped.
Flatten children
Description
Recursively unpack plain lists (but not hypertext.tag nodes) so users
can pass list(tags$li("a"), tags$li("b")) as a single child
argument.
Usage
.flatten_children(x)
Arguments
x |
A list of children. |
Value
A flat list of children.
Create a tag function for a normal (non-void) element
Description
Create a tag function for a normal (non-void) element
Usage
.make_tag(tag_name)
Create a tag function for a void (self-closing) element
Description
Create a tag function for a void (self-closing) element
Usage
.make_void_tag(tag_name)
Render a named list of attributes to a single HTML attribute string
Description
-
NAvalues produce boolean / valueless attributes (e.g.disabled). -
NULLvalues are silently dropped. -
TRUEproduces a boolean attribute;FALSEdrops it. Character vectors of length > 1 are collapsed with a space (handy for
class = c("a", "b")).
Usage
.render_attrs(attrs)
Arguments
attrs |
A named list of attribute values. |
Value
A single character string (leading space included when non-empty).
Create an HTML element node
Description
Low-level constructor. Named arguments become attributes; unnamed arguments become children (text or nested nodes). This function is used internally by every entry in the tags list.
Usage
.tag(tag_name, ..., .void = FALSE)
Arguments
tag_name |
Character scalar – the HTML element name. |
... |
Attributes (named) and children (unnamed). |
.void |
Logical; if |
Value
A list of class "hypertext.tag" with components tag, attrs,
and children.
Render an HTML node tree to a character string
Description
Converts an hypertext.tag object (and all its descendants) into an HTML
string. Text children are escaped; nested hypertext.tag children are
rendered recursively.
Usage
render(x)
## S3 method for class 'hypertext.tag'
render(x)
## Default S3 method:
render(x)
## S3 method for class 'list'
render(x)
Arguments
x |
An |
Value
A single character string of HTML.
HTML tag functions
Description
A named list of functions, one per HTML5 element. Access individual
tags with tags$div(...), tags$p(...), etc.
Usage
tags
Format
An object of class list of length 115.
Details
Named arguments become HTML attributes; unnamed arguments become child nodes or text content.
Boolean / valueless attributes
Pass NA or TRUE as the attribute value to produce a valueless
attribute (e.g. disabled). FALSE or NULL suppresses the
attribute entirely.
Multi-value attributes
Character vectors of length > 1 are collapsed with a space, so
class = c("a", "b") renders as class="a b".
Examples
tags$p(class = "lead", "Hello, world!")
render(tags$div(id = "app", tags$h1("Title")))