Skip to content

Commit

Permalink
Update styling to be minimal in markdown tables, add inline style sup…
Browse files Browse the repository at this point in the history
…port
  • Loading branch information
darrenburns committed May 31, 2023
1 parent c40fdbb commit f3d8e9b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
7 changes: 5 additions & 2 deletions rich/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def on_child_close(
def __rich_console__(
self, console: Console, options: ConsoleOptions
) -> RenderResult:
table = Table()
table = Table(box=box.SIMPLE_HEAVY)

assert self.header is not None
assert self.header.row is not None
Expand Down Expand Up @@ -331,7 +331,10 @@ def __init__(self, justify: JustifyMethod) -> None:

def on_text(self, context: "MarkdownContext", text: TextType) -> None:
plain = text.plain if isinstance(text, Text) else text
self.content = Text(plain, justify=self.justify)
style = text.style if isinstance(text, Text) else ""
self.content = Text(
plain, justify=self.justify, style=context.style_stack.current
)


class ListElement(MarkdownElement):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ def test_markdown_table():
"""\
| Year | Title | Director | Box Office (USD) |
|------|:------------------------------------------------:|:------------------|------------------:|
| 1982 | E.T. the Extra-Terrestrial | Steven Spielberg | $792.9 million |
| 1982 | *E.T. the Extra-Terrestrial* | Steven Spielberg | $792.9 million |
| 1980 | Star Wars: Episode V – The Empire Strikes Back | Irvin Kershner | $538.4 million |
| 1983 | Star Wars: Episode VI – Return of the Jedi | Richard Marquand | $475.1 million |
| 1981 | Raiders of the Lost Ark | Steven Spielberg | $389.9 million |
| 1984 | Indiana Jones and the Temple of Doom | Steven Spielberg | $333.1 million |
"""
)
result = render(markdown)
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"
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"
assert result == expected


Expand Down
14 changes: 7 additions & 7 deletions tools/movies.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ The 1980's was an era that produced some of the most iconic movies of all time.

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

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

## Oscar Winners

Expand Down

0 comments on commit f3d8e9b

Please sign in to comment.