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

commonmark renderer renders incompatible table with width limit #353

Open
matthewhughes934 opened this issue Oct 26, 2023 · 1 comment
Open

Comments

@matthewhughes934
Copy link

Given the content:

# Table test

| column 1 | column 2 |
| --- | --- |
| this is a very long row | longer than width limit |

Rendering with a width less than that of one of the rows of the table gives:

$ cmark-gfm --extension table --width 40 --to commonmark table.md 
# Table test

| column 1 | column 2 |
| --- | --- |
| this is a very long row | longer than
width limit |

Which is not compatible with the original content since it will render an extra row:

$ cmark-gfm --extension table --width 40 --to commonmark table.md | cmark-gfm --to html --extension table
<h1>Table test</h1>
<table>
<thead>
<tr>
<th>column 1</th>
<th>column 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>this is a very long row</td>
<td>longer than</td>
</tr>
<tr>
<td>width limit</td>
<td></td>
</tr>
</tbody>
</table>

From what I can tell reading the spec https://github.github.com/gfm/#tables-extension- there's no support for breaking table rows over several lines, so I suppose the commonmark render should never try to break these lines, regardless of width?

@matthewhughes934
Copy link
Author

Here's a quick hack copying some behaviour from how titles behave (which also can't be broken)

diff --git a/extensions/table.c b/extensions/table.c
index e8359f2..61ee353 100644
--- a/extensions/table.c
+++ b/extensions/table.c
@@ -567,6 +567,7 @@ static void commonmark_render(cmark_syntax_extension *extension,
   if (node->type == CMARK_NODE_TABLE) {
     renderer->blankline(renderer);
   } else if (node->type == CMARK_NODE_TABLE_ROW) {
+    renderer->no_linebreaks = entering;
     if (entering) {
       renderer->cr(renderer);
       renderer->out(renderer, node, "|", false, LITERAL);

At a glance I didn't see any tests covering conversion to commonmark though, so not sure how valid this is

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

No branches or pull requests

1 participant