Skip to content

retrieve markdown table class from attributes #10884

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
priiduonu opened this issue May 30, 2025 · 6 comments
Open

retrieve markdown table class from attributes #10884

priiduonu opened this issue May 30, 2025 · 6 comments

Comments

@priiduonu
Copy link
Contributor

I would like to be able to write

| header1 | header2 |
|---------|---------|
| r1c1    | r1c2    |
| r2c1    | r2c2    |

: mycaption {.myclass}

and get the table class assigned to the table element, while removing it from the caption.

I know I can achieve it with fenced div blocks, but the shorthand version would be nice.

In the real world I am using pandoc-crossref, so my table usually looks like:

| header1 | header2 |
|---------|---------|
| r1c1    | r1c2    |
| r2c1    | r2c2    |

: mycaption {#tbl:id}

therefore I prefer the short version instead of wrapping the whole thing in extra div.

@jgm
Copy link
Owner

jgm commented May 30, 2025

Pandoc's Markdown doesn't allow attributes that aren't attached to a heading, code, link, image, bracketed span, or fenced div.

I'm not sure how pandoc-crossref lets you do that.

But with commonmark_x (which includes the attributes extension to commonmark), you can do

{.myclass}
| header1 | header2 |
|---------|---------|
| r1c1    | r1c2    |
| r2c1    | r2c2    |

and it will attach the class to the table.

@rnwst
Copy link
Contributor

rnwst commented May 31, 2025

@priiduonu -- I wrote a filter for cross-references in Lua which supports the same syntax that pandoc-crossref is using to specify Table Attrs (the syntax you are using above). You can find it here. If you are only interested in the code that enables use of this syntax to specify Table Attrs, you could copy the function parse_table_attr into a separate Lua filter. The way this function works is quite simple -- it parses the table caption as a Heading, since Headings use the same syntax to specify Attrs.

@jgm -- would you be open to having pandoc's Markdown extended to support this syntax for specifying Table Attrs? The syntax seems natural to me, since it is already used in Headings to specify Attrs.

@jgm
Copy link
Owner

jgm commented Jun 1, 2025

@jgm -- would you be open to having pandoc's Markdown extended to support this syntax for specifying Table Attrs? The syntax seems natural to me, since it is already used in Headings to specify Attrs.

Worth considering. Comments welcome.

@tarleb
Copy link
Collaborator

tarleb commented Jun 1, 2025

It's a fairly common and natural extension to pandoc's syntax, Quarto has it, too.

I'd be in support of building this into pandoc. The only mildly awkward thing, IMHO, arises when using captions with multiple paragraphs. Attaching the attribute to the last paragraph is slightly weird. But, as noted above, people are already doing that, so it seems fine.

@rnwst
Copy link
Contributor

rnwst commented Jun 1, 2025

@tarleb -- I did not realise it was possible to create table captions with multiple paragraphs in pandoc's Markdown. Could you give an example of how this can be done? I tried a few things and couldn't get it to work (I also don't think this is documented in the manual?).

@tarleb
Copy link
Collaborator

tarleb commented Jun 1, 2025

Whoops, you're right. I must have imagined that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants