Skip to content

Adding an id to a processed HTML table breaks span data-qmd #11460

Open

Description

@allefeld

Originally posted by @allefeld in #6602 (reply in thread)

To assign an id to a table, so that it can be referred to from elsewhere, if that table is defined in HTML code in a fenced code block ```{=html}, one can put the id on the table element using HTML syntax, <table id="tbl-xyz">.

Unfortunately, there seems to be a bug such that in that case all Markdown given via span data-qmd is ignored.

Reproducible example

span data-qmd works but without id

```{=html}
<table>
  <caption>
    <span data-qmd="Quarto is __*great*__!"></span>
  </caption>
  <thead>
    <tr>
      <th>Header 1</th>
      <th><span data-qmd="*Header* 2"></span></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Body 1</td>
      <td><span data-qmd="Body __2__"></span></td>
    </tr>
  </tbody>
</table>
```

Image

with id but span data-qmd doesn't work

```{=html}
<table id="tbl-xyz">
  <caption>
    <span data-qmd="Quarto is __*great*__!"></span>
  </caption>
  <thead>
    <tr>
      <th>Header 1</th>
      <th><span data-qmd="*Header* 2"></span></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Body 1</td>
      <td><span data-qmd="Body __2__"></span></td>
    </tr>
  </tbody>
</table>
```

Image

Activity

  1. changed the title [-]I believe @friosavila refers to giving the table a label, so that it can be referred to from elsewhere. In a regular markdown table, that would be done by appending an id attribute to the caption, `: Quarto is great! {#tbl-xyz}`.[/-] [+]Adding an id to a processed HTML table breaks span data-qmd[/+] on Nov 15, 2024
  2. cderv commented on Nov 18, 2024

    @cderv
    Member

    We don't handle attributes on the start pattern for detecting HTML tables

    local start = patterns.html_start_tag("table")

    local function start_tag(t)
    local pattern = "<" .. t .. "[^>]->"
    return pattern
    end

    while cursor < len do
    -- find the first table start tag
    local i, j = string.find(eltext, start, cursor)
    if i == nil then
    -- no more tables
    break
    end

    So we don't parse the table, meaning no quarto table processing happens, and specific span attributes are not handled (and other quarto table feature require processing are not applied either)

    so that it can be referred to from elsewhere, if that table is defined in HTML code in a fenced code block {=html}

    Current way of referencing a raw HTML table elsewhere is to used cross ref div syntax

    ---
    title: Test
    format: typst
    ---
    
    ::: {#tbl-xyz}
    
    ```{=html}
    <table>
      <caption>
        <span data-qmd="Quarto is __*great*__!"></span>
      </caption>
      <thead>
        <tr>
          <th>Header 1</th>
          <th><span data-qmd="*Header* 2"></span></th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>Body 1</td>
          <td><span data-qmd="Body __2__"></span></td>
        </tr>
      </tbody>
    </table>
    ```
    
    :::
    
    See @tbl-xyz
  3. added
    bug
    tables
    on Nov 18, 2024
  4. added
    triaged-to
    on Nov 18, 2024
  5. added this to the Future milestone on Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugtablestriaged-to

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions