Skip to contents

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="...">).

Usage

html(text)

Arguments

text

The HTML fragment. <character(1)>: required. Length-1 character vector. NA is rejected.

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.

See also

Sibling helper: md() — Markdown wrapper for the common case.

String slots that consume the wrapper: tabular() (titles, footnotes), col_spec() (label), style() (pretext, posttext).

Entry / terminal verbs: tabular(), emit(), as_grid().

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)

 

variablestat_labelplacebodrug_50drug_100Total
Age (years)n869672254
Age (years)Mean (SD)75.2 (8.59)76.0 (8.11)73.8 (7.94)75.1 (8.25)
Age (years)Median76.078.075.577.0
Age (years)Q1, Q369.2, 81.871.0, 82.070.5, 79.070.0, 81.0
Age (years)Min, Max52, 8951, 8856, 8851, 89
Sex, n (%)F53 (61.6)55 (57.3)35 (48.6)143 (56.3)
Sex, n (%)M33 (38.4)41 (42.7)37 (51.4)111 (43.7)
Race, n (%)WHITE78 (90.7)90 (93.8)62 (86.1)230 (90.6)
Race, n (%)BLACK OR AFRICAN AMERICAN8 (9.3)6 (6.2)9 (12.5)23 (9.1)
Race, n (%)ASIAN0 (0.0)0 (0.0)0 (0.0)0 (0.0)
Race, n (%)AMERICAN INDIAN OR ALASKA NATIVE0 (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

 

Categoryplacebodrug_50drug_100Total
Any TEAE65 (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 Drug43 (50.0)77 (80.2)64 (88.9)184 (72.4)
Any AE Leading to Death2 (2.3)1 (1.0)0 (0.0)3 (1.2)
Any AE Recovered / Resolved47 (54.7)61 (63.5)49 (68.1)157 (61.8)
  Maximum severity: Mild36 (41.9)21 (21.9)20 (27.8)77 (30.3)
  Maximum severity: Moderate24 (27.9)47 (49.0)40 (55.6)111 (43.7)
  Maximum severity: Severe5 (5.8)16 (16.7)8 (11.1)29 (11.4)

See MedDRA coding1.