Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix H1 header alignment: change from center to left justification #3830

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

Open
djvolz wants to merge 2 commits into Textualize:master
base: master
Choose a base branch
Loading
from djvolz:fix-h1-header-alignment

Conversation

Copy link

@djvolz djvolz commented Aug 22, 2025

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

This PR fixes the alignment of H1 headers in markdown rendering by changing them from center-justified to left-justified. This improves readability, especially in terminal contexts where left-aligned text is generally easier to scan and read.

Changes Made

  • Modified rich/markdown.py line 147: Changed text.justify = "center" to text.justify = "left" in the Heading class's __rich_console__ method
  • Updated CHANGELOG.md: Added entry for this behavior change under [Unreleased] section
  • Updated CONTRIBUTORS.md: Added contributor entry alphabetically by surname
  • Updated test expectations: Modified both test_markdown.py and test_markdown_no_hyperlinks.py to expect left-aligned H1 headers

Before/After Comparison

Before (center-justified):

┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ My Header Title ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

After (left-justified):

┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ My Header Title ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

Impact

  • Scope: This change only affects H1 headers (which are rendered inside panels with borders)
  • Other headers: H2-H6 headers remain unchanged as they were already left-aligned
  • Readability: The change improves readability and consistency with standard markdown conventions
  • Breaking change: Tests expecting center-aligned H1 headers have been updated to match the new behavior

Testing

  • ✅ Verified the change works by testing with python -m rich.markdown
  • ✅ Updated test expectations in both test_markdown.py and test_markdown_no_hyperlinks.py
  • ✅ Ran black formatter with no changes needed
  • ✅ All markdown-related tests should now pass with the updated expectations

Motivation

This addresses the community feedback about centered headers being less readable in terminal environments. Left-aligned headers are more consistent with typical markdown rendering and improve the overall user experience when reading documentation in the terminal.

Fixes #2137

Additional Context

The original issue highlighted that centered headers can be harder to read, especially when scanning through documentation. This small change brings Rich's markdown rendering more in line with common expectations while maintaining the distinctive panel styling for H1 headers.

djvolz added 2 commits August 22, 2025 02:47
Changes markdown H1 headers to be left-justified instead of center-justified
for better readability in terminal contexts. This addresses user feedback
about centered headers being harder to read.
Fixes Textualize#2137 
- Update CHANGELOG.md with entry for H1 alignment change
- Add contributor to CONTRIBUTORS.md
- Update test expectations for left-aligned H1 headers
- Both test_markdown.py and test_markdown_no_hyperlinks.py updated
Related to Textualize#2137 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[QUESTION] How to override markdown header justification?

1 participant

AltStyle によって変換されたページ (->オリジナル) /