Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Markdown does not render "markdown" code blocks correctly! #3128

Closed
2 tasks done
gagb opened this issue Sep 10, 2023 · 5 comments
Closed
2 tasks done

[BUG] Markdown does not render "markdown" code blocks correctly! #3128

gagb opened this issue Sep 10, 2023 · 5 comments

Comments

@gagb
Copy link

gagb commented Sep 10, 2023

Rich's markdown rendering fails on the following example.

Example:

from rich.panel import Panel
from rich.markdown import Markdown
from rich.console import Console, group, Group
from rich.text import Text

content = "Sure, here is the information in a markdown table:\n\n```markdown\n| Rank | River Name | Length (km) |\n| --- | --- | --- |\n| 1 | Nile | 6,650 |\n| 2 | Congo | 4,700 |\n| 3 | Niger | 4,180 |\n| 4 | Zambezi | 2,574 |\n| 5 | Ubangi | 2,270 |\n```"

print(content)

panel_content = Markdown(content)

console = Console()
console.print(panel_content)

Running this code results in:
image

Platform
MacOS 13.5.1 (22G90)
Python 3.11.4
rich==13.5.2
iTerm2 (Build 3.4.16)

@Textualize Textualize deleted a comment from github-actions bot Sep 11, 2023
@davep
Copy link
Contributor

davep commented Sep 11, 2023

What output would you expect? For example, if I take your input document and include it in this comment, which will render it with GitHub's own Markdown rendering engine, it looks pretty much the same:


Sure, here is the information in a markdown table:

| Rank | River Name | Length (km) |
| --- | --- | --- |
| 1 | Nile | 6,650 |
| 2 | Congo | 4,700 |
| 3 | Niger | 4,180 |
| 4 | Zambezi | 2,574 |
| 5 | Ubangi | 2,270 |

Or, if I preview it with the online markdown-it demo, it also appears the same:

Screenshot 2023-09-11 at 08 27 00

What incorrect rendering are you seeing?

@rodrigogiraoserrao
Copy link
Contributor

rodrigogiraoserrao commented Sep 13, 2023

I'm pretty sure there's a bit of confusion here between the table that was pasted inside the triple backticks, which is supposed to represent “markdown source ”””code””””, and the pretty table representation one gets from markdown tables.

@gagb Markdown will render markdown. If you want a table to be rendered, you shouldn't put it inside a code block.
I.e., use this code:

from rich.panel import Panel
from rich.markdown import Markdown
from rich.console import Console, group, Group
from rich.text import Text

content = "Sure, here is the information in a markdown table:\n\n| Rank | River Name | Length (km) |\n| --- | --- | --- |\n| 1 | Nile | 6,650 |\n| 2 | Congo | 4,700 |\n| 3 | Niger | 4,180 |\n| 4 | Zambezi | 2,574 |\n| 5 | Ubangi | 2,270 |\n"

print(content)

panel_content = Markdown(content)

console = Console()
console.print(panel_content)

Notice how I dropped the ```markdown from the beginning of the table and the triple-backtick from the end.

@github-actions
Copy link

I hope we solved your problem.

If you like using Rich, you might also enjoy Textual

@gagb
Copy link
Author

gagb commented Sep 18, 2023

You are correct @rodrigogiraoserrao -- your response helped clarify my confusion about the semantics of the renderer. Thank you!

@rodrigogiraoserrao
Copy link
Contributor

Thank you!

I'm glad I could help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants