-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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] Spaces at the end lines when using Markdown
#3154
Comments
There isn't a parameter to control that, but you can customize how the code fence is rendered. Something like this: import rich
from rich.markdown import Markdown
markdown = """\
This is some code:
```sql
SELECT
toStartOfHour(event_time) AS Event_Hour,
COUNT() AS Event_Count
FROM events
WHERE event_time >= now() - INTERVAL 1 DAY
GROUP BY Event_Hour
ORDER BY Event_Hour DESC;
```
"""
from rich.markdown import CodeBlock
from rich.syntax import Syntax
class SimpleCodeBlock(CodeBlock):
def __rich_console__(self, console, options):
code = str(self.text).rstrip()
syntax = Syntax(
code,
self.lexer_name,
theme="ansi_light",
word_wrap=True,
background_color="default",
)
yield syntax
Markdown.elements["fence"] = SimpleCodeBlock
rich.print(Markdown(markdown)) But that doesn't guarantee it will be cut and pastable. It will still hard wrap if the code is wider than the terminal. |
Thanks so much, I'll try that. hard wrapping hasn't been a problem so far. I've found myself using aicli (which uses rich markdown to print the response) more and more during development, hence needing to copy the code from markdown frequently. |
I hope we solved your problem. If you like using Rich, you might also enjoy Textual |
Describe the bug
Running the following code prints out nice pretty markdown, which is great 👍 .
The only problem is that when I copy the code from the terminal, every line is right padded with spaces to the full width of the terminal, there's also one space to the left of the code.
Hard to show that output here, so here's a screenshot from pycharm showing the spaces (as dots)
Copied SQL:
It would be great if there was a way to:
Platform
Click to expand
What platform (Win/Linux/Mac) are you running on? What terminal software are you using? Mac, I think I saw the same on Ubuntu.
I may ask you to copy and paste the output of the following commands. It may save some time if you do it now.
If you're using Rich in a terminal:
==
The text was updated successfully, but these errors were encountered: