gt icon indicating copy to clipboard operation
gt copied to clipboard

Duplicated Div-Tags in Typst Output

Open AlbertRapp opened this issue 5 months ago • 1 comments

Prework

Description

Disclaimer: Not sure if this is a Quarto or {gt} issue. Please tell me if this is not the appropriate place to raise this issue.

Inside of Markdown columns (formatted with fmt_markdown()), content inside of <div>-tags is duplicated inside Typst outputs. <span>-tags however are not affected by this. Also, the output width of the table changes when <div>-tags present.

Reproducible example

---
title: "Paris Metro Lines"
keep-typ: true
keep-md: true
format: typst
---


## Regular Formatting 

```{r}
library(gt)
gt::metro[1:2, c('name', 'lines')] |>
  transform(
    lines = paste0('<span>', lines, '</span>')
  ) |>
  gt()
```


## Expected Output (with Markdown formatting)

```{r}
library(gt)
gt::metro[1:2, c('name', 'lines')] |>
  transform(
    lines = paste0('<span>', lines, '</span>')
  ) |>
  gt() |>
  fmt_markdown(columns = lines)
```


## Actual Output

```{r}
library(gt)
gt::metro[1:2, c('name', 'lines')] |>
  transform(
    # Changed to div-tags here
    lines = paste0('<div>', lines, '</div>')
  ) |>
  gt() |>
  fmt_markdown(columns = lines)
```

Images

Image Image Image

Generated Typst Code

For expected output:

table(
    columns: 2,
    align: (left, left),
    table.header(
      table.cell(align: bottom + left, fill: rgb("#ffffff"))[#set text(size: 1.0em, fill: rgb("#333333")); name],
      table.cell(align: bottom + left, fill: rgb("#ffffff"))[#set text(size: 1.0em, fill: rgb("#333333")); lines],
    ),
    table.hline(),
    table.cell(align: horizon + left, stroke: (top: (paint: rgb("#d3d3d3"), thickness: 0.75pt)))[Argentine],
    table.cell(align: horizon + left, stroke: (top: (paint: rgb("#d3d3d3"), thickness: 0.75pt)))[1],
    table.cell(align: horizon + left, stroke: (top: (paint: rgb("#d3d3d3"), thickness: 0.75pt)))[Bastille],
    table.cell(align: horizon + left, stroke: (top: (paint: rgb("#d3d3d3"), thickness: 0.75pt)))[1, 5, 8],
  )

For actual output


#{set text(font: ("system-ui", "Segoe UI", "Roboto", "Helvetica", "Arial", "sans-serif", "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji") , size: 12pt); table(
  columns: (50%, 50%),
  align: (left,left,),
  table.header(table.cell(align: bottom + left, fill: rgb("#ffffff"))[#set text(size: 1.0em , fill: rgb("#333333")); name], table.cell(align: bottom + left, fill: rgb("#ffffff"))[#set text(size: 1.0em , fill: rgb("#333333")); lines],),
  table.hline(),
  table.cell(align: horizon + left, stroke: (top: (paint: rgb("#d3d3d3"), thickness: 0.75pt)))[Argentine], table.cell(align: horizon + left, stroke: (top: (paint: rgb("#d3d3d3"), thickness: 0.75pt)))[1
  #block[
  1
  ]],
  table.cell(align: horizon + left, stroke: (top: (paint: rgb("#d3d3d3"), thickness: 0.75pt)))[Bastille], table.cell(align: horizon + left, stroke: (top: (paint: rgb("#d3d3d3"), thickness: 0.75pt)))[1, 5, 8
  #block[
  1, 5, 8
  ]],
)}

In the last four lines you can clearly see that it has 1, 5, 8 and a #block[] of the same content.

Session info

sessioninfo::session_info()
─ Session info ───────────────────────────────────────────────
 setting  value
 version  R version 4.4.3 (2025-02-28)
 os       Ubuntu 22.04.5 LTS
 system   x86_64, linux-gnu
 ui       X11
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       Europe/Berlin
 date     2025-08-09
 pandoc   NA

─ Packages ───────────────────────────────────────────────────
 package     * version date (UTC) lib source
 cli           3.6.5   2025-04-23 [1] CRAN (R 4.4.3)
 commonmark    1.9.5   2025-03-17 [1] CRAN (R 4.4.3)
 digest        0.6.37  2024-08-19 [1] CRAN (R 4.4.1)
 dplyr         1.1.4   2023-11-17 [1] CRAN (R 4.4.0)
 fastmap       1.2.0   2024-05-15 [1] CRAN (R 4.4.1)
 generics      0.1.4   2025-05-09 [1] CRAN (R 4.4.3)
 glue          1.8.0   2024-09-30 [1] CRAN (R 4.4.1)
 gt          * 1.0.0   2025-04-05 [1] CRAN (R 4.4.3)
 htmltools     0.5.8.1 2024-04-04 [1] CRAN (R 4.4.0)
 lifecycle     1.0.4   2023-11-07 [1] CRAN (R 4.4.0)
 litedown      0.7     2025-04-08 [1] CRAN (R 4.4.3)
 magrittr      2.0.3   2022-03-30 [1] CRAN (R 4.4.0)
 markdown      2.0     2025-03-23 [1] CRAN (R 4.4.3)
 pillar        1.10.2  2025-04-05 [1] CRAN (R 4.4.3)
 pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.4.0)
 R6            2.6.1   2025-02-15 [1] CRAN (R 4.4.3)
 rlang         1.1.6   2025-04-11 [1] CRAN (R 4.4.3)
 sass          0.4.10  2025-04-11 [1] CRAN (R 4.4.3)
 sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.4.0)
 tibble        3.3.0   2025-06-08 [1] CRAN (R 4.4.3)
 tidyselect    1.2.1   2024-03-11 [1] CRAN (R 4.4.0)
 vctrs         0.6.5   2023-12-01 [1] CRAN (R 4.4.0)
 withr         3.0.2   2024-10-28 [1] CRAN (R 4.4.1)
 xfun          0.52    2025-04-02 [1] CRAN (R 4.4.3)
 xml2          1.3.8   2025-03-14 [1] CRAN (R 4.4.3)

 [1] /home/albert/R/x86_64-pc-linux-gnu-library/4.4
 [2] /usr/local/lib/R/site-library
 [3] /usr/lib/R/site-library
 [4] /usr/lib/R/library

──────────────────────────────────────────────────────────────

AlbertRapp avatar Aug 09 '25 11:08 AlbertRapp

A workaround is to use span-tags and set its display style-attribute to something like block. But in principle, I believe the content of div-tags should not be duplicated.

AlbertRapp avatar Aug 09 '25 11:08 AlbertRapp