[1] "<span class='fansi-color-012'>hello</span><span class='fansi-color-001 fansi-bgcol-002' style='font-weight: bold;'>world</span>"

class.8 <- do.call(paste, c(expand.grid(c("fg", "bg"), 0:7), 
    sep = "-"))

class.16 <- do.call(paste, c(expand.grid(c("fg", "bg"), 0:15), 
    sep = "-"))

class.256 <- do.call(paste, c(expand.grid(c("fg", "bg"), 0:255), 
    sep = "-"))

term.cap <- c("bright", "256", "truecolor")

sgr_to_html(x, classes = class.8, term.cap = term.cap)

<span style='color: #5555FF;'>he</span><span style='color: #5555FF; background-color: #FFFFFF;'>llo</span><span class='fg-1 bg-2' style='font-weight: bold;'>world</span>
<span style='color: #5FAF00; background-color: #FFFF00;'>good</span><span style='color: #FFFF00; background-color: #5FAF00;'>bye</span> super <span style='color: #EB0014;'>moon</span>

[1] "<span style='color: #5555FF;'>he</span><span style='color: #5555FF; background-color: #FFFFFF;'>llo</span><span class='fg-1 bg-2' style='font-weight: bold;'>world</span>"              
[2] "<span style='color: #5FAF00; background-color: #FFFF00;'>good</span><span style='color: #FFFF00; background-color: #5FAF00;'>bye</span> super <span style='color: #EB0014;'>moon</span>"

sgr_to_html(x, classes = class.16, term.cap = term.cap)

<span class='fg-12'>he</span><span class='fg-12 bg-15'>llo</span><span class='fg-1 bg-2' style='font-weight: bold;'>world</span>
<span class='bg-11' style='color: #5FAF00;'>good</span><span class='fg-11' style='background-color: #5FAF00;'>bye</span> super <span style='color: #EB0014;'>moon</span>

[1] "<span class='fg-12'>he</span><span class='fg-12 bg-15'>llo</span><span class='fg-1 bg-2' style='font-weight: bold;'>world</span>"                                        
[2] "<span class='bg-11' style='color: #5FAF00;'>good</span><span class='fg-11' style='background-color: #5FAF00;'>bye</span> super <span style='color: #EB0014;'>moon</span>"

sgr_to_html(x, classes = class.256, term.cap = term.cap)

<span class='fg-12'>he</span><span class='fg-12 bg-15'>llo</span><span class='fg-1 bg-2' style='font-weight: bold;'>world</span>
<span class='fg-70 bg-11'>good</span><span class='fg-11 bg-70'>bye</span> super <span style='color: #EB0014;'>moon</span>