-
Notifications
You must be signed in to change notification settings - Fork 39
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 for newlines inside tables #10
Comments
Oh, interesting! I haven’t really spent much work on tables at all as part of this. This one might be slightly complicated. Here’s a quick breakdown of how things work:
The vast majority of everything here happens in step 2. I took a quick look at this, though, and the problem in this case is really in step 4 — that is, this is an issue with remark-stringify. For example, this doc: Results in a Markdown AST with two paragraphs in the table cells after step 3: The markdown AST syntax has a | Heading 1 | Heading 2 | Heading 3 |
| --------- | --------- | ----------- |
| Abc def | One line | Two lines |
| Yes | No | Maybe | SO! I think there are two options here…
Doing (1) would fix things pretty quickly here, but (2) would be a little more stable and long-term. (You could also do both!) |
@Mr0grog In markdown, you can’t have a newline in a table cell, so The question then is whether you’d want |
@wooorm right! I definitely get that, sorry if I wasn’t clear. I guess my thinking was that it seems wrong for stringifying the AST to be a [silently] lossy operation — if there’s a |
I added a note that the
The goal of mdast is to be a lossy (it’s an ast, not a cst) and easy to handle format for markdown that handles user-provided data. “Silently” lossy is what it is: that’s the tradeoff made against complexity and crashing.
How important is the newline? People probably add enters accidentally to google docs. I’d say that if you’re transforming GDocs -> Markdown, you can only do so while losing info 🤷♂️ |
Oh! I thought that was the Markdown equivalent of a
Hmmm, I definitely feel like I’ve seen people do formatting intentionally in tables like this, though. It seems hard to make a judgement on it in the abstract. @sa3dany do you have some use cases that you needed this for?
Fair point! I naïvely assumed where I was losing info and where I should be worried about it would be in the But I hear what you’re saying about this being an abstract tree, and that because the mdast universe is meant to be loose rather than strict, it should be on this program to handle the situation, rather than on mdast to figure out how to represent something that Markdown doesn’t handle well to begin with. 👍 @sa3dany are you still interested in working on this? If this is an important feature to you, I think the right answer here is one of:
|
They are somewhat equivalent, but the reason of mdast’s existence is exactly because markdown does not always map directly to HTML. It’s a nuanced (perhaps pedantic) difference, but I think of it as: mdast represents only markdown, hast represent only HTML, and in different scenarios, you’d want to transform between them differently as well!
I think your assumption is correct: |
What if there were a boolean setting for Or, more broad: a boolean |
FWIW, I’m not sure a special hook for |
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.
Thanks for creating this tool. I found that the only way to have newlines in markdown tables is to use the
<br>
html tag. I haven't looked at the code yet but if you think this can be done easily just point me in the right direction and I can try to implement this and open a pull request.The text was updated successfully, but these errors were encountered: