Skip to content

Commit f3d8e9b

Browse files
committed
Update styling to be minimal in markdown tables, add inline style support
1 parent c40fdbb commit f3d8e9b

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

rich/markdown.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def on_child_close(
247247
def __rich_console__(
248248
self, console: Console, options: ConsoleOptions
249249
) -> RenderResult:
250-
table = Table()
250+
table = Table(box=box.SIMPLE_HEAVY)
251251

252252
assert self.header is not None
253253
assert self.header.row is not None
@@ -331,7 +331,10 @@ def __init__(self, justify: JustifyMethod) -> None:
331331

332332
def on_text(self, context: "MarkdownContext", text: TextType) -> None:
333333
plain = text.plain if isinstance(text, Text) else text
334-
self.content = Text(plain, justify=self.justify)
334+
style = text.style if isinstance(text, Text) else ""
335+
self.content = Text(
336+
plain, justify=self.justify, style=context.style_stack.current
337+
)
335338

336339

337340
class ListElement(MarkdownElement):

tests/test_markdown.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@ def test_markdown_table():
121121
"""\
122122
| Year | Title | Director | Box Office (USD) |
123123
|------|:------------------------------------------------:|:------------------|------------------:|
124-
| 1982 | E.T. the Extra-Terrestrial | Steven Spielberg | $792.9 million |
124+
| 1982 | *E.T. the Extra-Terrestrial* | Steven Spielberg | $792.9 million |
125125
| 1980 | Star Wars: Episode V – The Empire Strikes Back | Irvin Kershner | $538.4 million |
126126
| 1983 | Star Wars: Episode VI – Return of the Jedi | Richard Marquand | $475.1 million |
127127
| 1981 | Raiders of the Lost Ark | Steven Spielberg | $389.9 million |
128128
| 1984 | Indiana Jones and the Temple of Doom | Steven Spielberg | $333.1 million |
129129
"""
130130
)
131131
result = render(markdown)
132-
expected = "\n┏━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┓\n\x1b[1m \x1b[0m\x1b[1mYear\x1b[0m\x1b[1m \x1b[0m┃\x1b[1m \x1b[0m\x1b[1m Title \x1b[0m\x1b[1m \x1b[0m┃\x1b[1m \x1b[0m\x1b[1mDirector \x1b[0m\x1b[1m \x1b[0m┃\x1b[1m \x1b[0m\x1b[1mBox Office (USD)\x1b[0m\x1b[1m \x1b[0m┃\n┡━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━┩\n│ 1982 │ E.T. the Extra-Terrestrial │ Steven Spielberg │ $792.9 million │\n│ 1980 │ Star Wars: Episode V – The Empire Strikes Back │ Irvin Kershner │ $538.4 million │\n│ 1983 │ Star Wars: Episode VI – Return of the Jedi │ Richard Marquand │ $475.1 million │\n│ 1981 │ Raiders of the Lost Ark │ Steven Spielberg │ $389.9 million │\n│ 1984 │ Indiana Jones and the Temple of Doom │ Steven Spielberg │ $333.1 million │\n└──────┴────────────────────────────────────────────────┴──────────────────┴──────────────────┘\n"
132+
expected = "\n \n \x1b[1m \x1b[0m\x1b[1mYear\x1b[0m\x1b[1m \x1b[0m \x1b[1m \x1b[0m\x1b[1m Title \x1b[0m\x1b[1m \x1b[0m \x1b[1m \x1b[0m\x1b[1mDirector \x1b[0m\x1b[1m \x1b[0m \x1b[1m \x1b[0m\x1b[1mBox Office (USD)\x1b[0m\x1b[1m \x1b[0m \n ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ \n 1982 \x1b[3m E.T. the Extra-Terrestrial \x1b[0m Steven Spielberg $792.9 million \n 1980 Star Wars: Episode V – The Empire Strikes Back Irvin Kershner $538.4 million \n 1983 Star Wars: Episode VI – Return of the Jedi Richard Marquand $475.1 million \n 1981 Raiders of the Lost Ark Steven Spielberg $389.9 million \n 1984 Indiana Jones and the Temple of Doom Steven Spielberg $333.1 million \n \n"
133133
assert result == expected
134134

135135

tools/movies.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ The 1980's was an era that produced some of the most iconic movies of all time.
66

77
Here are the top 5 highest-grossing films of the 1980s:
88

9-
| Year | Title | Director | Box Office (USD) |
10-
|------|:------------------------------------------------:|:------------------|------------------:|
11-
| 1982 | E.T. the Extra-Terrestrial | Steven Spielberg | $792.9 million |
12-
| 1980 | Star Wars: Episode V – The Empire Strikes Back | Irvin Kershner | $538.4 million |
13-
| 1983 | Star Wars: Episode VI – Return of the Jedi | Richard Marquand | $475.1 million |
14-
| 1981 | Raiders of the Lost Ark | Steven Spielberg | $389.9 million |
15-
| 1984 | Indiana Jones and the Temple of Doom | Steven Spielberg | $333.1 million |
9+
| Year | Title | Director | Box Office (USD) |
10+
|------|:----------------------------------------------:|:------------------|------------------:|
11+
| 1982 | *E.T. the Extra-Terrestrial* | Steven Spielberg | $792.9 million |
12+
| 1980 | Star Wars: Episode V – The Empire Strikes Back | Irvin Kershner | $538.4 million |
13+
| 1983 | Star Wars: Episode VI – Return of the Jedi | Richard Marquand | $475.1 million |
14+
| 1981 | Raiders of the Lost Ark | Steven Spielberg | $389.9 million |
15+
| 1984 | Indiana Jones and the Temple of Doom | Steven Spielberg | $333.1 million |
1616

1717
## Oscar Winners
1818

0 commit comments

Comments
 (0)