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

Table extension: Add (optional?) container element to handle horizontal overflow #780

Closed
Paul-Hebert opened this issue Jan 10, 2022 · 5 comments · Fixed by #787
Closed
Assignees
Labels
enhancement New functionality or behavior implemented Change has been implemented
Milestone

Comments

@Paul-Hebert
Copy link

Description

I'm using the Tables extension to add tables to markdown. On small screens the tables often extend outside of the viewport, breaking the page layout.

This is because elements with display: table do not respond to width and max-width the same way block elements do. There's no easy CSS way to constrain the table to its container. In the past I've handled it like so:

<div style="overflow-x: auto; max-width: 100%">
  <table><!-- table innards... --> </table>
</div>

It would be nice if there was a way to configure the tables extension to wrap all tables in an element (div?) with a configurable class (e.g. table-container). This would make it easy to use the table extension without breaking responsive layouts.

In the meantime it seems like the only workaround is to extend the Table Renderer with a custom render function. (Which is not the end of the world, by any means, but it would be nice if this was a built-in option.)

I'm currently pretty busy at work, but if this is a feature you're open to I could try to find time to make a PR in the future.

Example

Take the following markdown:

|Heading|Heading|
|--------|--------|
|Content|Content|

It currently outputs something like this:

<table><!-- table innards... --></table>

It would be nice if it output this instead:

<div class="table-container">
  <table><!-- table innards... --></table>
</div>

To prevent making this a breaking change, it would probably be best to make this an optional configuration setting for the tables extension.

Did this project help you today? Did it make you happy in any way?

This project is sooooooo good. I'm working on a project that requires some pretty complex custom markdown parsing, and the extension structure makes this really easy to set up. (I was originally planning to use a lot of regex, but I'm glad I found this project instead 😅 )

Thank you so much for your work on this project! It works great, is a breeze to build off of, and has saved me a ton of time!

@Paul-Hebert Paul-Hebert added the enhancement New functionality or behavior label Jan 10, 2022
@colinodell colinodell added this to the v2.2 milestone Jan 10, 2022
@colinodell
Copy link
Member

Thanks for the feedback! This is a great idea. I'll try to work on this over the coming weekend unless somebody beats me to it :)

@Paul-Hebert
Copy link
Author

Awesome, thanks @colinodell !

@colinodell
Copy link
Member

@Paul-Hebert How does the implementation in #787 look to you?

@Paul-Hebert
Copy link
Author

@colinodell this looks fantastic, great work!

The only other thing I could think of would be to make the wrapping tag configurable (e.g. adding an option to use a figure over a div) but I don't think this is necessary. (I'd probably default to using a div so this works for me!)

@colinodell colinodell linked a pull request Jan 22, 2022 that will close this issue
@close-label close-label bot added the implemented Change has been implemented label Jan 22, 2022
@colinodell
Copy link
Member

I've added that additional option and released the feature in https://github.com/thephpleague/commonmark/releases/tag/2.2.0! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New functionality or behavior implemented Change has been implemented
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants