Merge pull request #3942 from Textualize/markdown-style

Update to markdown styles
This commit is contained in:
Will McGugan 2026-01-24 12:16:29 +00:00 committed by GitHub
commit 2f56d4d1d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 62 additions and 43 deletions

View File

@ -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
@ -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
@ -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

2
FAQ.md
View File

@ -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.

View File

@ -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"

View File

@ -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.

View File

@ -149,20 +149,22 @@ DEFAULT_STYLES: Dict[str, Style] = {
"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"),

View File

@ -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
@ -14,7 +15,6 @@ from ._stack import Stack
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
@ -124,9 +124,24 @@ class Paragraph(TextElement):
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)
@ -143,20 +158,10 @@ class Heading(TextElement):
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):
@ -219,7 +224,8 @@ class HorizontalRule(MarkdownElement):
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):
@ -241,11 +247,19 @@ class TableElement(MarkdownElement):
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:

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long