Skip to content
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

rich-text-from-markdown does not support table headers #352

Open
giovanni-caiazzo opened this issue Jul 18, 2022 · 7 comments
Open

rich-text-from-markdown does not support table headers #352

giovanni-caiazzo opened this issue Jul 18, 2022 · 7 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@giovanni-caiazzo
Copy link

As per title, @contentful/rich-text-from-markdown does not support table headers in markdown. When I have this in markdown:

| Header 1 | Header 2 |
| --- | --- |
| Cell 1-1 | Cell 1-2 |

The tool responds with:

{
  nodeType: "table",
  content: [
    {
      nodeType: "table-row",
      content: [
        {
          nodeType: "table-cell",
          content: [
            {
              nodeType: "paragraph",
              data: {},
              content: [
                { nodeType: "text", value: "Header 1", marks: [], data: {} },
              ],
            },
          ],
          data: {},
        },
        {
          nodeType: "table-cell",
          content: [
            {
              nodeType: "paragraph",
              data: {},
              content: [
                { nodeType: "text", value: "Header 2", marks: [], data: {} },
              ],
            },
          ],
          data: {},
        },
      ],
      data: {},
    },
    {
      nodeType: "table-row",
      content: [
        {
          nodeType: "table-cell",
          content: [
            {
              nodeType: "paragraph",
              data: {},
              content: [
                { nodeType: "text", value: "Cell 1-1", marks: [], data: {} },
              ],
            },
          ],
          data: {},
        },
        {
          nodeType: "table-cell",
          content: [
            {
              nodeType: "paragraph",
              data: {},
              content: [
                { nodeType: "text", value: "Cell 1-2", marks: [], data: {} },
              ],
            },
          ],
          data: {},
        },
      ],
      data: {},
    },
  ],
}

So, it detects the header part of the markdown (which is |---|) and removes it from the rich text, but does not promote the table-cells to table-header-cells.
Is it possible to know when this feature will be available? Contentful itself supports table-header-cell node types, so I don't see why this tool should not use it.
Thank you for your time

@diegoaguilar
Copy link

@giovanni-caiazzo did you found a solution or work around for this?

@giovanni-caiazzo
Copy link
Author

I removed all the headers and then treated the first row of any table as the header in my react app 😓

@LuudJanssen
Copy link

I used this dirty trick to split the header and body row(s):

[BLOCKS.TABLE]: (_node: unknown, children: ReactNode): ReactNode => {
  const [header, ...body] = children as ReactNode[];
  
  return (
    <Table.Root>
      <Table.Header>{header}</Table.Header>
      <Table.Body>{body}</Table.Body>
    </Table.Root>
  );
},

@z0al z0al added the enhancement New feature or request label Aug 30, 2024
@z0al
Copy link
Member

z0al commented Aug 30, 2024

Looks like the underlying package doesn't recognise the notion of table header cells. Here is a quick demo

But since markdown tables syntax enforces headers I think it's safe to assume the first row of a table is a header row.

Would anyone be willing to submit a PR for this?

@z0al z0al added the good first issue Good for newcomers label Aug 30, 2024
@LuudJanssen
Copy link

@z0al, this is the same for the tables in rich text in Contentful, a syntax we don't control. Should I create a separate issue for that?

@z0al
Copy link
Member

z0al commented Sep 3, 2024

this is the same for the tables in rich text in Contentful

What do you mean @LuudJanssen ? can you give an example please?

@LuudJanssen
Copy link

Hi @z0al. I'm talking about header rows missing from the entire Contentful ecosystem.

Ideally, both the converter from markdown to rich text, as well as the native rich text format (for the rich text field) in Contentful would produce something like:

nodeType: table
  nodeType: table-header-row <-- doesn't exist
    nodeType: table-header-cell
    nodeType: table-header-cell
  nodeType: table-row
    nodeType: table-cell
    nodeType: table-cell

Again, don't know if I'm in the right place reporting this enhancement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants