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

Add preliminary support for tables #290

Merged
merged 2 commits into from
Sep 20, 2024
Merged

Add preliminary support for tables #290

merged 2 commits into from
Sep 20, 2024

Conversation

pengjiz
Copy link
Contributor

@pengjiz pengjiz commented Sep 1, 2024

(Re: #2, #289)

Hello!

I added a very basic implementation for table rendering.

The implementation does not depend on any existing TTY table rendering libraries because I realized that we need to support, e.g., markups inside table cells and attributes, but I did not find a library that supports such a use case well.

Right now it is only a quick and dirty implementation. Many functionalities are missing, e.g., cell alignment, head row formatting, table rules, and markups inside cells. However, I noticed that you had created a blockwise-rendering branch, which might be very helpful for table rendering as well. So I am opening this PR to get some comments and hopefully provide some insights on implementing the new blockwise rendering.

Thanks!

PS here is the table in README rendered with this implementation:

mdcat-table

Nothing fancy indeed.

@swsnr
Copy link
Owner

swsnr commented Sep 1, 2024

Haven't taken a deeper look yet, but could you please not abbreviate table to tbl? It's easier to read written out.

@pengjiz
Copy link
Contributor Author

pengjiz commented Sep 2, 2024 via email

Copy link
Owner

@swsnr swsnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this patch 🙏❤️

I'd not like to hold this off with a lengthy review, since any support is better than no support 😅

I've just had a few minor remarks on the doff, and some overall points:

  • I'd appreciate a small test, which renders a small file with two tables to assert the formatting and to check that we properly reset the current table state at the end of a table.
  • Please do add a changelog entry.
  • Please check the manpage file and the README and the top level api docs whether we need to update them now that we support tables (I believe this restriction is mentioned in a couple of places).

Tests (edit)

Tests work mostly with golden files, i.e. the tests generate files which I check manually and then add to the repo; future test runs then compare against the existing golden file.

For this PR you'd add a e.g. tables.md to pulldown-cmark-mdcat/tests/render/md/samples/, then run the tests with $MDCAT_UPDATE_GOLDEN_FILES set to generate the initial golden file for tables.md.

Note that no other file should probably change, as tables aren't yet tested anywhere. If any other golden file changes you'd need to investigate.

pulldown-cmark-mdcat/src/render/data.rs Show resolved Hide resolved
pulldown-cmark-mdcat/src/render/write.rs Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
@pengjiz
Copy link
Contributor Author

pengjiz commented Sep 3, 2024

Thanks a lot for the review!

Honestly I did not expect that this PR would be merged – I was planning to rewrite it after your blockwise-rendering would get merged. If you'd like to install this implementation, I will address your comments and cleanup it a bit, perhaps over this weekend.

@swsnr
Copy link
Owner

swsnr commented Sep 3, 2024

If you wait for blockwise rendering you'll wait a long time. I don't have much time for this kind of stuff these days, so if I get this done this year, it's already fast 😅🙈

Let's merge what we have ✌️

@pengjiz pengjiz force-pushed the feat/table branch 2 times, most recently from 89da46c to 57c0030 Compare September 16, 2024 08:31
@pengjiz pengjiz changed the title WIP: Support tables Add preliminary support for tables Sep 16, 2024
@pengjiz pengjiz marked this pull request as ready for review September 16, 2024 08:33
With this commit, mdcat can render basic tables. However, the support is
incomplete. E.g., inline markups are stripped, overlong texts are not
wrapped, and block attributes are mostly ignored.

We intend to support those in the future. So we chose to not use a TTY
table rendering library because it would be hard to plug the library
into our existing renderer.
@pengjiz
Copy link
Contributor Author

pengjiz commented Sep 16, 2024

Sorry for the delay. I got a bit busy in the past few weeks.

I just updated the implementation and then squashed and force pushed to my branch. It is ready from my side, and I would appreciate a review.

Thank you!

PS here is an updated screenshot rendering the README.md file:

mdcat-tables

@swsnr
Copy link
Owner

swsnr commented Sep 16, 2024

Thanks for finishing this. Now I'm a bit busy, but I hope to have a look by the end of this week.

If you haven't heard from me beginning of next week, please ping me 😊

@swsnr
Copy link
Owner

swsnr commented Sep 20, 2024

@pengjiz clippy complained 😬 Could take a look? Once the pipeline is green, I'll merge and publish a new release

@pengjiz
Copy link
Contributor Author

pengjiz commented Sep 20, 2024 via email

@swsnr swsnr merged commit 9177b24 into swsnr:main Sep 20, 2024
6 checks passed
@pengjiz pengjiz deleted the feat/table branch October 14, 2024 00:16
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.

2 participants