-
Notifications
You must be signed in to change notification settings - Fork 94
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
Format markdown code for tables #3516
Comments
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
In order to make sure this
good first issue
If some aspects of it are still unclear please ask so i can clarify further. If you think this should be done differently please open a new issue describing your solution. Let's keep this issue focused on the proposed solution to provide clarity for whoever wants to tackle it. |
@max-nextcloud The markdown result of table already has the alignment. |
I think there was a misunderstanding with the issue. It is about nicely formatting the actual markdown source code in. Some example: Currently tables are written to the file like this:
The goal of this issue would be to make sure the table is formatted in the markdown file like this
(I've also put this example in the first post) |
This is a challenging good first issueGood for newcomers
if you...
If you would like some guidance ping @max-nextcloud or join the public text channel.
Problem
When creating a table the resulting markdown source is not aligned.
Solution
Create pretty tables like https://www.tablesgenerator.com/markdown_tables
Currently tables are written to the markdown files like this:
The goal of this issue would be to make sure the table is formatted in the markdown file like this:
Alternatives we considered
For now we settled on creating nicely formatted tables. This could be changed in the future based on user feedback.
Starting points
Testing
The existing test for serializing tables loads a markdown input file, serializes it and checks the output is the same as the input.
The table in the markdown file is currently not aligned. If you change it to be nicely formatted the test will fail because text currently does not serialize the table content that way. So now you have a failing test you can start from.
Markdown rendering of tables
The
toMarkdown
functions in the table nodes define how to serialize the table to markdown.Each file in that folder describes a node, which corresponds to an html element in the table. Rendering of the result starts with rendering the
Table
node, descends into to theTableHeader
node, then further into theTableHeadRow
and thenTableCell
and so on. Right now theTableCell
s just start with a leading whitespace and end with a trailing one. In order to format the table nicely the number of whitespaces will have to depend on the largest cell in a given column.Computing the cell width
In order to compute the width of the columns the content of the entire table needs to be considered. The to markdown function gets arguments of the following form:
The
node
argument is a ProsemirrorNode and you can usedescendants
to iterate through all of the child nodes.Starting from the
Table
itself, iterate through all of the children. We're only interested in theTableCell
s here. The function handed todescendants
will get the child node as a first argument. If it's not aTableCell
just return true (sodescandents
continues to look forTableCell
s inside the node in question. If it's a table cell you can use the index to identify the column thisTableCell
is in.Providing the cell width to the
TableCell
toMarkdown
functionMarkdown serialization happens based on
prosemirror-markdown
.MarkdownSerializerState
can be used to track the required width for each column.Additional context
Strictly speaking this is not part of perserving md source - still came up when discussing #593 .
The text was updated successfully, but these errors were encountered: