mirror of
https://github.com/Textualize/rich.git
synced 2026-02-06 10:58:48 +00:00
Update to markdown styles
This commit is contained in:
parent
c595fa9506
commit
e9b0e19158
@ -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
|
||||
- Changed style of Markdown tables, added `markdown.table.header` and `markdown.table.border` styles
|
||||
- Changed style of Markdown rules
|
||||
|
||||
## [14.2.0] - 2025-10-09
|
||||
|
||||
|
||||
@ -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"),
|
||||
|
||||
@ -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
Loading…
Reference in New Issue
Block a user