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

Fix markdown table rendering issue with inline styles/links #3130

Merged
merged 2 commits into from Sep 17, 2023

Conversation

rodrigogiraoserrao
Copy link
Contributor

@rodrigogiraoserrao rodrigogiraoserrao commented Sep 13, 2023

Type of changes

  • Bug fix
  • New feature
  • Documentation / docstrings
  • Tests
  • Other

Checklist

  • I've run the latest black with default args on new code.
  • I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate.
  • I've added tests for new code.
  • I accept that @willmcgugan may be pedantic in the code review.

Description

The table data elements were not interacting well with inline styles (in the rich sense) and the table data element would have its content overridden every time we found another excerpt of text with a different style.
The fix was to do something similar to what TextElement does in its method on_text, which is to append the new content instead of replacing it.

This fixes #3115.

The table data elements were not interacting well with inline styles (in the rich sense) and the table data element would have its content overridden every time we found another excerpt of text with a different style.
Comment on lines -337 to +339
plain = text.plain if isinstance(text, Text) else text
style = text.style if isinstance(text, Text) else ""
self.content = Text(
plain, justify=self.justify, style=context.style_stack.current
)
text = Text(text) if isinstance(text, str) else text
text.stylize(context.current_style)
self.content.append_text(text)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was a bit confused here because style was being created but not used.
My change will preserve whatever styling is already in the Text instance but will then add the current context style on top of it.
This felt like the correct thing to do.

@rodrigogiraoserrao rodrigogiraoserrao marked this pull request as ready for review September 13, 2023 12:41
@cwerner
Copy link

cwerner commented Sep 13, 2023

FWIW: I pip installed your pull request branch into my original project where I spotted the issue that only a single/ the last link remained in a markdown table cell and I'm happy to report that this change fixes the problem for me 👍 🥳

@rodrigogiraoserrao
Copy link
Contributor Author

FWIW: I pip installed your pull request branch into my original project where I spotted the issue that only a single/ the last link remained in a markdown table cell and I'm happy to report that this change fixes the problem for me 👍 🥳

That's good to know!
Thanks for the confirmation.

@willmcgugan willmcgugan merged commit bef0e50 into master Sep 17, 2023
19 checks passed
@willmcgugan willmcgugan deleted the fix-table-inline-styles branch September 17, 2023 14:56
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.

[BUG] Rich markdown printed to console only shows a single link in a column/ table cell
3 participants