Wrap a length-1 character vector so tabular(), col_spec(),
and similar string slots interpret it as a constrained HTML
subset at render time. Use when CommonMark cannot express the
formatting (custom CSS via <span style="...">, raw destination
codes via <span data-rtf="...">).
Value
A length-1 character vector classed
c("from_html", "character"). Pass it directly into any
string-bearing slot (tabular() titles / footnotes,
col_spec() label, style() pretext / posttext); the
resolve engine calls parse_inline() internally and backends
walk the resulting inline_ast.
Details
Recognised tag whitelist. <p>, <br> / <br/>,
<strong>, <b>, <em>, <i>, <sup>, <sub>, <code>,
<a href>, <span style>. Tags outside this set drop their
wrapper and keep their text content (no arbitrary HTML attack
surface).
Span styles. <span style="color: red; font-weight: bold">x</span>
parses the style attribute into a named character vector
(c(color = "red", "font-weight" = "bold")). Backends translate
CSS keys to destination-specific markup (RTF \cf, LaTeX
\textcolor, DOCX <w:color>, HTML inline style).
Backend-specific raw codes. A span with data-rtf,
data-latex, data-html, or data-docx attributes carries
per-backend raw markup. The matching backend emits its data
value verbatim and ignores the others; non-matching backends
render the span's text content as plain. Use for cases the AST
cannot express portably.
Examples
# ---- Example 1: Colour-styled span in a title ----
#
# Demographics table title with the population subset shaded
# red. The HTML wrapper carries an inline CSS style; backends
# translate (RTF: \cf, LaTeX: \textcolor, HTML: inline style).
n <- stats::setNames(cdisc_saf_n$n, cdisc_saf_n$arm_short)
tabular(
cdisc_saf_demo,
titles = c(
"Table 14.1.1",
"Demographics",
html(sprintf("Safety Pop <span style='color:red'>(N=%d)</span>", n["Total"]))
)
)
Table 14.1.1
Demographics
Safety Pop (N=254)
variable stat_label placebo drug_50 drug_100 Total Age (years) n 86 96 72 254 Age (years) Mean (SD) 75.2 (8.59) 76.0 (8.11) 73.8 (7.94) 75.1 (8.25) Age (years) Median 76.0 78.0 75.5 77.0 Age (years) Q1, Q3 69.2, 81.8 71.0, 82.0 70.5, 79.0 70.0, 81.0 Age (years) Min, Max 52, 89 51, 88 56, 88 51, 89 Sex, n (%) F 53 (61.6) 55 (57.3) 35 (48.6) 143 (56.3) Sex, n (%) M 33 (38.4) 41 (42.7) 37 (51.4) 111 (43.7) Race, n (%) WHITE 78 (90.7) 90 (93.8) 62 (86.1) 230 (90.6) Race, n (%) BLACK OR AFRICAN AMERICAN 8 (9.3) 6 (6.2) 9 (12.5) 23 (9.1) Race, n (%) ASIAN 0 (0.0) 0 (0.0) 0 (0.0) 0 (0.0) Race, n (%) AMERICAN INDIAN OR ALASKA NATIVE 0 (0.0) 0 (0.0) 1 (1.4) 1 (0.4)
# ---- Example 2: HTML link plus superscript footnote marker ----
#
# AE table footnote with an HTML link and a superscript marker.
# `html()` lets the user write tags directly when CommonMark
# would be awkward (e.g. attributes that Markdown does not
# surface).
tabular(
cdisc_saf_ae,
titles = c("Table 14.3.0", "Overall Adverse Event Summary"),
footnotes = c(
html('See <a href="https://www.meddra.org/">MedDRA</a> coding<sup>1</sup>.')
)
) |>
cols(stat_label = col_spec(label = "Category"))
Table 14.3.0
Overall Adverse Event Summary
Category placebo drug_50 drug_100 Total Any TEAE 65 (75.6) 84 (87.5) 68 (94.4) 217 (85.4) Any Serious AE (SAE) 0 (0.0) 2 (2.1) 1 (1.4) 3 (1.2) Any AE Related to Study Drug 43 (50.0) 77 (80.2) 64 (88.9) 184 (72.4) Any AE Leading to Death 2 (2.3) 1 (1.0) 0 (0.0) 3 (1.2) Any AE Recovered / Resolved 47 (54.7) 61 (63.5) 49 (68.1) 157 (61.8) Maximum severity: Mild 36 (41.9) 21 (21.9) 20 (27.8) 77 (30.3) Maximum severity: Moderate 24 (27.9) 47 (49.0) 40 (55.6) 111 (43.7) Maximum severity: Severe 5 (5.8) 16 (16.7) 8 (11.1) 29 (11.4)
See MedDRA coding1.