Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [14.3.0] - 2025-01-24

### Fixed

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

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

## [14.2.0] - 2025-10-09

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

- First official release, API still to be stabilized

[14.2.0]: https://github.com/textualize/rich/compare/v14.2.0...v14.3.0
[14.1.0]: https://github.com/textualize/rich/compare/v14.1.0...v14.2.0
[14.0.0]: https://github.com/textualize/rich/compare/v14.0.0...v14.1.0
[14.3.0]: https://github.com/textualize/rich/compare/v14.2.0...v14.3.0
[14.2.0]: https://github.com/textualize/rich/compare/v14.1.0...v14.2.0
[14.1.0]: https://github.com/textualize/rich/compare/v14.0.0...v14.1.0
[14.0.0]: https://github.com/textualize/rich/compare/v13.9.4...v14.0.0
[13.9.4]: https://github.com/textualize/rich/compare/v13.9.3...v13.9.4
[13.9.3]: https://github.com/textualize/rich/compare/v13.9.2...v13.9.3
Expand Down
2 changes: 1 addition & 1 deletion FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<a name="extra-space-not-enough-space-in-jupyter-output"></a>
## Extra space, not enough space, in Jupyter output

There are many different implementations of Jupyter, from different venders.
There are many different implementations of Jupyter, from different vendors.

Different notebook software may render Rich's output differently, due to how the CSS is constructed.
Adding or removing space, may make the output look good on your software, but break somewhere else.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "rich"
homepage = "https://github.com/Textualize/rich"
documentation = "https://rich.readthedocs.io/en/latest/"
version = "14.2.0"
version = "14.3.0"
description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal"
authors = ["Will McGugan <willmcgugan@gmail.com>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion questions/jupyter.question.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ alt_titles:
- "Not enough space in Jupyter"
---

There are many different implementations of Jupyter, from different venders.
There are many different implementations of Jupyter, from different vendors.

Different notebook software may render Rich's output differently, due to how the CSS is constructed.
Adding or removing space, may make the output look good on your software, but break somewhere else.
Expand Down
20 changes: 11 additions & 9 deletions rich/default_styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,22 @@
"markdown.block_quote": Style(color="magenta"),
"markdown.list": Style(color="cyan"),
"markdown.item": Style(),
"markdown.item.bullet": Style(color="yellow", bold=True),
"markdown.item.number": Style(color="yellow", bold=True),
"markdown.hr": Style(color="yellow"),
"markdown.item.bullet": Style(bold=True),
"markdown.item.number": Style(color="cyan"),
"markdown.hr": Style(dim=True),
"markdown.h1.border": Style(),
"markdown.h1": Style(bold=True),
"markdown.h2": Style(bold=True, underline=True),
"markdown.h3": Style(bold=True),
"markdown.h4": Style(bold=True, dim=True),
"markdown.h5": Style(underline=True),
"markdown.h6": Style(italic=True),
"markdown.h1": Style(bold=True, underline=True),
"markdown.h2": Style(color="magenta", underline=True),
"markdown.h3": Style(color="magenta", bold=True),
"markdown.h4": Style(color="magenta", italic=True),
"markdown.h5": Style(italic=True),
"markdown.h6": Style(dim=True),
"markdown.h7": Style(italic=True, dim=True),
"markdown.link": Style(color="bright_blue"),
"markdown.link_url": Style(color="blue", underline=True),
"markdown.s": Style(strike=True),
"markdown.table.border": Style(color="cyan"),
"markdown.table.header": Style(color="cyan", bold=False),
"iso8601.date": Style(color="blue"),
"iso8601.time": Style(color="magenta"),
"iso8601.timezone": Style(color="yellow"),
Expand Down
50 changes: 32 additions & 18 deletions rich/markdown.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import sys
from dataclasses import dataclass
from typing import ClassVar, Iterable, get_args

from markdown_it import MarkdownIt
Expand All @@ -14,7 +15,6 @@
from .console import Console, ConsoleOptions, JustifyMethod, RenderResult
from .containers import Renderables
from .jupyter import JupyterMixin
from .panel import Panel
from .rule import Rule
from .segment import Segment
from .style import Style, StyleStack
Expand Down Expand Up @@ -124,9 +124,24 @@ def __rich_console__(
yield self.text


@dataclass
class HeadingFormat:
justify: JustifyMethod = "left"
style: str = ""


class Heading(TextElement):
"""A heading."""

LEVEL_ALIGN: ClassVar[dict[str, JustifyMethod]] = {
"h1": "center",
"h2": "left",
"h3": "left",
"h4": "left",
"h5": "left",
"h6": "left",
}

@classmethod
def create(cls, markdown: Markdown, token: Token) -> Heading:
return cls(token.tag)
Expand All @@ -143,20 +158,10 @@ def __init__(self, tag: str) -> None:
def __rich_console__(
self, console: Console, options: ConsoleOptions
) -> RenderResult:
text = self.text
text.justify = "center"
if self.tag == "h1":
# Draw a border around h1s
yield Panel(
text,
box=box.HEAVY,
style="markdown.h1.border",
)
else:
# Styled text for h2 and beyond
if self.tag == "h2":
yield Text("")
yield text
text = self.text.copy()
heading_justify = self.LEVEL_ALIGN.get(self.tag, "left")
text.justify = heading_justify
yield text


class CodeBlock(TextElement):
Expand Down Expand Up @@ -219,7 +224,8 @@ def __rich_console__(
self, console: Console, options: ConsoleOptions
) -> RenderResult:
style = console.get_style("markdown.hr", default="none")
yield Rule(style=style)
yield Rule(style=style, characters="-")
yield Text()


class TableElement(MarkdownElement):
Expand All @@ -241,11 +247,19 @@ def on_child_close(self, context: MarkdownContext, child: MarkdownElement) -> bo
def __rich_console__(
self, console: Console, options: ConsoleOptions
) -> RenderResult:
table = Table(box=box.SIMPLE_HEAVY)
table = Table(
box=box.SIMPLE,
pad_edge=False,
style="markdown.table.border",
show_edge=True,
collapse_padding=True,
)

if self.header is not None and self.header.row is not None:
for column in self.header.row.cells:
table.add_column(column.content)
heading = column.content.copy()
heading.stylize("markdown.table.header")
table.add_column(heading)

if self.body is not None:
for row in self.body.rows:
Expand Down
2 changes: 1 addition & 1 deletion tests/_card_render.py

Large diffs are not rendered by default.

Loading
Loading