-
Notifications
You must be signed in to change notification settings - Fork 2k
feat: Add default styling for code blocks (pre/code tags) across components #2736
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
base: develop
Are you sure you want to change the base?
feat: Add default styling for code blocks (pre/code tags) across components #2736
Conversation
✅ Acceptance Criteria UpdateI've added the following to complete the acceptance criteria: 🧪 Tests Added
📚 Documentation Added
🎯 Acceptance Criteria Status✅ Working demo/example - 📝 Notes
The PR is now complete and ready for review! 🚀 |
|
Hi @SasikaA073, thank you for your PR. I see you've added a release note and test in the repo root which must have been mistake. Could you check this and give me a ping when this is ready for review |
- Added default CSS styling for inline code and code blocks - Styles include monospaced font, background color, padding, and border - Supports both light and dark modes using existing color variables - Code blocks are visually distinctive with proper readability - Added E2E tests for light/dark modes, chat, text components, and CSS override Fixes Avaiga#2662
0733092 to
9d918cc
Compare
|
@arcanaxion yes, that was my mistake. Now I have checked this one, and edited the PR with only the required changes. I've removed the files that were in the wrong location. Now the PR only contains
|
|
Hi @arcanaxion Is there any other modification needed? |
|
This PR has been labelled as "🥶Waiting for contributor" because it has been inactive for more than 14 days. If you would like to continue working on this PR, then please add new commit or another comment, otherwise this PR will be closed in 14 days. For more information please refer to the contributing guidelines. |
|
This PR has been labelled as "🥶Waiting for contributor" because it has been inactive for more than 14 days. If you would like to continue working on this PR, then please add new commit or another comment, otherwise this PR will be closed in 14 days. For more information please refer to the contributing guidelines. |
FredLL-Avaiga
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @SasikaA073
Thanks for your contribution
Can you update your branch and fix the linter issues ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds default CSS styling for code blocks (<code> and <pre> tags) across Taipy GUI components, improving readability for code snippets in markdown, chat messages, and pre-formatted text. The implementation includes light and dark mode support with monospaced fonts and distinctive background colors.
Key Changes:
- Added comprehensive CSS styling for inline code and code blocks in
typography.csswith theme-aware dark mode variants - Created E2E test suite covering markdown text, chat components, pre-mode text, and custom style overrides
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
frontend/taipy-gui/public/stylekit/base/typography.css |
Implements default styling for code and pre elements with light/dark mode support, monospace fonts, and proper spacing/borders |
tests/gui/e2e/test_code_block_styling.py |
Adds comprehensive E2E tests validating code block styling across different components and modes, including custom override capabilities |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| pre_content = """def example(): | ||
| x = 42 | ||
| return x""" | ||
|
|
||
| page_content = '<|{pre_content}|id=pre1|mode=pre|>' | ||
|
|
||
| gui._set_frame(inspect.currentframe()) |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable pre_content must be defined before calling gui._set_frame(inspect.currentframe()). The current order will cause the variable to not be captured in the frame's local scope, which is required for the Taipy GUI to access it.
Move the pre_content definition to before line 146.
| font-size: 0.9em; | ||
| background-color: rgba(0, 0, 0, 0.06); | ||
| color: var(--color-contrast); | ||
| padding: 0.2em 0.4em; |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Mixing em units (which are relative to the parent font size) with rem units (which are relative to the root font size) can lead to inconsistent sizing. The font-size uses em (line 88) while padding uses em as well, which means the padding will be calculated relative to the already-scaled font size, potentially leading to unexpected results.
Consider using rem for the font size for consistency with the pre block styling (line 103), or use fixed pixel values for padding to avoid compounding relative units.
| font-size: 0.9em; | |
| background-color: rgba(0, 0, 0, 0.06); | |
| color: var(--color-contrast); | |
| padding: 0.2em 0.4em; | |
| font-size: 0.9rem; | |
| background-color: rgba(0, 0, 0, 0.06); | |
| color: var(--color-contrast); | |
| padding: 0.2rem 0.4rem; |
| assert inline_code_bg != "rgba(0, 0, 0, 0)", "Inline code should have a background color in dark mode" | ||
|
|
||
|
|
||
| @pytest.mark.teste2e |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent spacing: there's an extra space before the decorator. Other test functions in this file don't have this extra space.
| @pytest.mark.teste2e | |
| @pytest.mark.teste2e |
| ) | ||
| assert code_bg == "rgb(255, 0, 0)", "Custom style should override default code styling" | ||
|
|
||
|
|
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra blank line at the end of the file. The file should end with a single newline character to match the project's style conventions.
| chat_messages = [ | ||
| ["1", "Show me a Python example", "user"], | ||
| ["2", "Here's an example:\n\n```python\ndef greet():\n print('Hello')\n```", "assistant"], | ||
| ] | ||
|
|
||
| page_content = '<|{chat_messages}|chat|id=chat1|>' | ||
|
|
||
| gui._set_frame(inspect.currentframe()) |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable chat_messages must be defined before calling gui._set_frame(inspect.currentframe()). The current order will cause the variable to not be captured in the frame's local scope, which is required for the Taipy GUI to access it.
Move the chat_messages definition to before line 119.
| @pytest.mark.teste2e | ||
| def test_code_block_in_chat(page: "Page", gui: Gui, helpers): | ||
| """Test that code blocks in chat messages have proper styling""" | ||
| chat_messages = [ |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable chat_messages is not used.
| @pytest.mark.teste2e | ||
| def test_pre_mode_styling(page: "Page", gui: Gui, helpers): | ||
| """Test that pre mode text component has proper styling""" | ||
| pre_content = """def example(): |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable pre_content is not used.
Description
This PR implements the feature requested in issue #2662 to provide default styling for code blocks across Taipy GUI components.
Changes Made
<code>(inline code) and<pre>(code blocks) tags infrontend/taipy-gui/public/stylekit/base/typography.csstest_code_block_styling.py) demonstrating the feature across:Features
Light Mode
Dark Mode
Testing
Run the test application:
This will demonstrate code block styling in:
Components Affected
Benefits
Closes #2662