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

Support multiple lines in table cells #11

Conversation

Mr0grog
Copy link
Owner

@Mr0grog Mr0grog commented Mar 6, 2020

Plain Markdown syntax doesn't support more than one line in a table cell, but Google Docs lets you have many paragraphs or lines in each cell. This update supports multiple lines by adding a custom handler for table cell nodes which outputs MDast html nodes representing <br> tags to use in the table.

It converts paragraphs to inline text separated by <br> tags rather than actual <p> tags so as to keep the amount of inserted HTML fairly light. I think this is probably the right thing, but we’ll see if anyone has issues with it!

This is probably not the nicest implementation, but it works reasonably well with a few test cases. @wooorm’s latest comment (#10 (comment)) suggests the right spot for this kind of logic is in the rehype → mdast conversion rather than in stringification, so that’s what I’ve done here. If hast-util-to-mdast gets more complicated and handles content in table cells differently in the future, this part may have to change, but I think that’s probably OK.

Fixes #10.

Plain Markdown syntax doesn't support more than one line in a table cell, but Google Docs lets you have many paragraphs or lines in each cell. This update supports multiple lines by adding a custom handler for table cell nodes which outputs MDast `html` nodes representing `<br>` tags to use in the table.

Fixes #10.
@wooorm
Copy link

wooorm commented Mar 7, 2020

I’ve worked on solving this properly in hast-util-to-mdast: syntax-tree/hast-util-to-mdast@fdafac8.

Next step is to document .wrapText (and other values that track state), so that others can benefit from it. In your case, I think that you’d want to overwrite the br handler and either use a break if wrapping is possible, or an html <br> if wrapping isn’t possible.

@Mr0grog Mr0grog deleted the branch master December 13, 2023 05:32
@Mr0grog Mr0grog closed this Dec 13, 2023
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

Successfully merging this pull request may close these issues.

Support for newlines inside tables
2 participants