Skip to content

Commit 2f56d4d

Browse files
authored
Merge pull request #3942 from Textualize/markdown-style
Update to markdown styles
2 parents c595fa9 + 97b5bea commit 2f56d4d

File tree

9 files changed

+62
-43
lines changed

9 files changed

+62
-43
lines changed

CHANGELOG.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [Unreleased]
8+
## [14.3.0] - 2025-01-24
99

1010
### Fixed
1111

@@ -27,6 +27,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2727

2828
- `cells.cell_len` now has a `unicode_version` parameter (that you probably should never change) https://github.com/Textualize/rich/pull/3930
2929
- Live will not write a new line if there was nothing rendered https://github.com/Textualize/rich/pull/3934
30+
- Changed style of Markdown headers https://github.com/Textualize/rich/pull/3942
31+
- Changed style of Markdown tables, added `markdown.table.header` and `markdown.table.border` styles https://github.com/Textualize/rich/pull/3942
32+
- Changed style of Markdown rules https://github.com/Textualize/rich/pull/3942
3033

3134
## [14.2.0] - 2025-10-09
3235

@@ -2174,9 +2177,9 @@ Major version bump for a breaking change to `Text.stylize signature`, which corr
21742177

21752178
- First official release, API still to be stabilized
21762179

2177-
[14.2.0]: https://github.com/textualize/rich/compare/v14.2.0...v14.3.0
2178-
[14.1.0]: https://github.com/textualize/rich/compare/v14.1.0...v14.2.0
2179-
[14.0.0]: https://github.com/textualize/rich/compare/v14.0.0...v14.1.0
2180+
[14.3.0]: https://github.com/textualize/rich/compare/v14.2.0...v14.3.0
2181+
[14.2.0]: https://github.com/textualize/rich/compare/v14.1.0...v14.2.0
2182+
[14.1.0]: https://github.com/textualize/rich/compare/v14.0.0...v14.1.0
21802183
[14.0.0]: https://github.com/textualize/rich/compare/v13.9.4...v14.0.0
21812184
[13.9.4]: https://github.com/textualize/rich/compare/v13.9.3...v13.9.4
21822185
[13.9.3]: https://github.com/textualize/rich/compare/v13.9.2...v13.9.3

FAQ.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<a name="extra-space-not-enough-space-in-jupyter-output"></a>
1515
## Extra space, not enough space, in Jupyter output
1616

17-
There are many different implementations of Jupyter, from different venders.
17+
There are many different implementations of Jupyter, from different vendors.
1818

1919
Different notebook software may render Rich's output differently, due to how the CSS is constructed.
2020
Adding or removing space, may make the output look good on your software, but break somewhere else.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "rich"
33
homepage = "https://github.com/Textualize/rich"
44
documentation = "https://rich.readthedocs.io/en/latest/"
5-
version = "14.2.0"
5+
version = "14.3.0"
66
description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal"
77
authors = ["Will McGugan <willmcgugan@gmail.com>"]
88
license = "MIT"

questions/jupyter.question.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ alt_titles:
55
- "Not enough space in Jupyter"
66
---
77

8-
There are many different implementations of Jupyter, from different venders.
8+
There are many different implementations of Jupyter, from different vendors.
99

1010
Different notebook software may render Rich's output differently, due to how the CSS is constructed.
1111
Adding or removing space, may make the output look good on your software, but break somewhere else.

rich/default_styles.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,22 @@
149149
"markdown.block_quote": Style(color="magenta"),
150150
"markdown.list": Style(color="cyan"),
151151
"markdown.item": Style(),
152-
"markdown.item.bullet": Style(color="yellow", bold=True),
153-
"markdown.item.number": Style(color="yellow", bold=True),
154-
"markdown.hr": Style(color="yellow"),
152+
"markdown.item.bullet": Style(bold=True),
153+
"markdown.item.number": Style(color="cyan"),
154+
"markdown.hr": Style(dim=True),
155155
"markdown.h1.border": Style(),
156-
"markdown.h1": Style(bold=True),
157-
"markdown.h2": Style(bold=True, underline=True),
158-
"markdown.h3": Style(bold=True),
159-
"markdown.h4": Style(bold=True, dim=True),
160-
"markdown.h5": Style(underline=True),
161-
"markdown.h6": Style(italic=True),
156+
"markdown.h1": Style(bold=True, underline=True),
157+
"markdown.h2": Style(color="magenta", underline=True),
158+
"markdown.h3": Style(color="magenta", bold=True),
159+
"markdown.h4": Style(color="magenta", italic=True),
160+
"markdown.h5": Style(italic=True),
161+
"markdown.h6": Style(dim=True),
162162
"markdown.h7": Style(italic=True, dim=True),
163163
"markdown.link": Style(color="bright_blue"),
164164
"markdown.link_url": Style(color="blue", underline=True),
165165
"markdown.s": Style(strike=True),
166+
"markdown.table.border": Style(color="cyan"),
167+
"markdown.table.header": Style(color="cyan", bold=False),
166168
"iso8601.date": Style(color="blue"),
167169
"iso8601.time": Style(color="magenta"),
168170
"iso8601.timezone": Style(color="yellow"),

rich/markdown.py

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import sys
4+
from dataclasses import dataclass
45
from typing import ClassVar, Iterable, get_args
56

67
from markdown_it import MarkdownIt
@@ -14,7 +15,6 @@
1415
from .console import Console, ConsoleOptions, JustifyMethod, RenderResult
1516
from .containers import Renderables
1617
from .jupyter import JupyterMixin
17-
from .panel import Panel
1818
from .rule import Rule
1919
from .segment import Segment
2020
from .style import Style, StyleStack
@@ -124,9 +124,24 @@ def __rich_console__(
124124
yield self.text
125125

126126

127+
@dataclass
128+
class HeadingFormat:
129+
justify: JustifyMethod = "left"
130+
style: str = ""
131+
132+
127133
class Heading(TextElement):
128134
"""A heading."""
129135

136+
LEVEL_ALIGN: ClassVar[dict[str, JustifyMethod]] = {
137+
"h1": "center",
138+
"h2": "left",
139+
"h3": "left",
140+
"h4": "left",
141+
"h5": "left",
142+
"h6": "left",
143+
}
144+
130145
@classmethod
131146
def create(cls, markdown: Markdown, token: Token) -> Heading:
132147
return cls(token.tag)
@@ -143,20 +158,10 @@ def __init__(self, tag: str) -> None:
143158
def __rich_console__(
144159
self, console: Console, options: ConsoleOptions
145160
) -> RenderResult:
146-
text = self.text
147-
text.justify = "center"
148-
if self.tag == "h1":
149-
# Draw a border around h1s
150-
yield Panel(
151-
text,
152-
box=box.HEAVY,
153-
style="markdown.h1.border",
154-
)
155-
else:
156-
# Styled text for h2 and beyond
157-
if self.tag == "h2":
158-
yield Text("")
159-
yield text
161+
text = self.text.copy()
162+
heading_justify = self.LEVEL_ALIGN.get(self.tag, "left")
163+
text.justify = heading_justify
164+
yield text
160165

161166

162167
class CodeBlock(TextElement):
@@ -219,7 +224,8 @@ def __rich_console__(
219224
self, console: Console, options: ConsoleOptions
220225
) -> RenderResult:
221226
style = console.get_style("markdown.hr", default="none")
222-
yield Rule(style=style)
227+
yield Rule(style=style, characters="-")
228+
yield Text()
223229

224230

225231
class TableElement(MarkdownElement):
@@ -241,11 +247,19 @@ def on_child_close(self, context: MarkdownContext, child: MarkdownElement) -> bo
241247
def __rich_console__(
242248
self, console: Console, options: ConsoleOptions
243249
) -> RenderResult:
244-
table = Table(box=box.SIMPLE_HEAVY)
250+
table = Table(
251+
box=box.SIMPLE,
252+
pad_edge=False,
253+
style="markdown.table.border",
254+
show_edge=True,
255+
collapse_padding=True,
256+
)
245257

246258
if self.header is not None and self.header.row is not None:
247259
for column in self.header.row.cells:
248-
table.add_column(column.content)
260+
heading = column.content.copy()
261+
heading.stylize("markdown.table.header")
262+
table.add_column(heading)
249263

250264
if self.body is not None:
251265
for row in self.body.rows:

tests/_card_render.py

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)