Skip to content

[quarto] data-qmd content should be escaped at least on double quotes #1487

Closed

Description

@cderv
---
title: "Test"
format: html
keep-md: true
---

```{r}
library(gt)
data.frame(A = "Text", B = '<em class="special">Text</em>') |> 
  gt() |> 
  fmt_markdown(B)
```

This will lead to

image

because gt does not handle the double quotes in the column and produce this

<div data-qmd="<em class="special">Text</em>">

This was found in the context of

And maybe there should be a fmt_raw_html() function to mark the column content as HTML. I don't think data-qmd attributes is needed in that case.

Though it would be a wrapper or alias for fmt_passthrough() with escaping opt-out

This works fine.

---
title: "Test"
format: html
keep-md: true
---

```{r}
library(gt)
data.frame(A = "Text", B = '<em class="special">Text</em>') |> 
  gt() |> 
  fmt_passthrough(B, escape = FALSE)
```

So this is really about fmt_markdown usage maybe

Requires latest 1.4 pre-release

Activity

  1. self-assigned this
    on Nov 15, 2023
  2. moved this from Backlog to Next / Ready for Dev in R Markdown Team Projectson Nov 15, 2023
  3. added this to the v0.11.0 milestone on Nov 15, 2023
  4. modified the milestones: v0.11.0, v0.10.1 on Dec 3, 2023
  5. modified the milestones: v0.10.1, v0.10.2 on Jan 17, 2024
  6. cderv commented on Apr 11, 2024

    @cderv
    CollaboratorAuthor

    @rich-iannone I do think there is a related issue mentioned in quarto-dev/quarto-cli#3340 with \QuartoMarkdownBase64{ as raw LaTeX in a cell, and gt not escaping it.

    Currently fmt_passthrough with escape = FALSE seems to be the solution. Though I am wondering if this should be by cell and not column.

    This makes me think about some tricks we using in knitr where using I() is a way to mark some content as not to be touched.

    Like

    tibble::tribble(
      ~Thing, ~Citation,
      1234, I("\\QuartoMarkdownBase64{QGVxLW1hdGg=}"),
      5678, "\\QuartoMarkdownBase64{QExvdmVsYWNlMTg0Mg==}"
    ) |>
      gt()
    

    The first one would go through the processing of text but not be escape_latex(), while the second would be escaped.

    Anyhow, maybe not really gt-like and a latex() should work with md() or html().

    To be discussed. Do you want another issue specific for LaTeX ? Or should would make this one generic about how to pass some raw content in cells ?

  7. rich-iannone commented on May 29, 2024

    @rich-iannone
    Member

    Note to self: this should be fixed by using base-64 encoding of the text.

  8. moved this from Next / Ready for Dev to Done in R Markdown Team Projectson May 29, 2024
  9. modified the milestones: v0.10.2, v0.11.0 on Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions