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

Code-blocks end on line-breaks #1515

Closed
Shivansh-007 opened this issue Sep 23, 2021 · 1 comment · Fixed by #1655
Closed

Code-blocks end on line-breaks #1515

Shivansh-007 opened this issue Sep 23, 2021 · 1 comment · Fixed by #1655

Comments

@Shivansh-007
Copy link

Shivansh-007 commented Sep 23, 2021

Hey @willmcgugan,

Great work on the library thanks! I have noticed that the Markdown code-block doesn't break itself when reaching line breaks, not sure if that's the expected behaviour and there is some other method to make it a new line (with proper indentation if possible) that I am not aware of.

EDIT: After going through the relevant section of rich's source code, the issue lies on this line:
https://github.com/willmcgugan/rich/blob/522f8411984abb5ff5ad749b8852835ff09b7ae5/rich/markdown.py#L180
There is no way to pass word_wrap=True which would wrap the code and not end it on line-breaks.

Currently, I have implemented a custom CodeBlock element and have been using that.

Screenshot from 2021-09-23 19-41-44


Here it works perfectly as I am not encountering line breaks

Screenshot from 2021-09-23 19-07-03

but now with just "disappear" the rest of the signature and not take it to a new line

Screenshot from 2021-09-23 19-07-26


Here, is the relevant section of my code:

if signatures is not None:
    for signature in signatures:
        self.console.print(Markdown(f"```py\n{signature.lstrip()}\n```"))
        self.console.print("\n")

Where signature represents (for the rich.console.Console) example:

class rich.console.Console(*, color_system: Optional[typing_extensions.Literal[auto, standard, 256, truecolor, windows]] = 'auto', force_terminal: Optional[bool] = None, force_jupyter: Optional[bool] = None, force_interactive: Optional[bool] = None, soft_wrap: bool = False, theme: Optional[rich.theme.Theme] = None, stderr: bool = False, file: Optional[IO[str]] = None, quiet: bool = False, width: Optional[int] = None, height: Optional[int] = None, style: Optional[Union[str, rich.style.Style]] = None, no_color: Optional[bool] = None, tab_size: int = 8, record: bool = False, markup: bool = True, emoji: bool = True, emoji_variant: Optional[typing_extensions.Literal[emoji, text]] = None, highlight: bool = True, log_time: bool = True, log_path: bool = True, log_time_format: Union[str, Callable[[datetime.datetime], rich.text.Text]] = '[%X]', highlighter: Optional[Callable[[Union[str, Text]], Text]] = <rich.highlighter.ReprHighlighter object>, legacy_windows: Optional[bool] = None, safe_box: bool = True, get_datetime: Optional[Callable[[], datetime.datetime]] = None, get_time: Optional[Callable[[], float]] = None, _environ: Optional[Mapping[str, str]] = None)
@Shivansh-007 Shivansh-007 changed the title [BUG] Code-blocks end on line-breaks Code-blocks end on line-breaks Sep 23, 2021
@github-actions
Copy link

github-actions bot commented Nov 7, 2021

Did I solve your problem?

Consider sponsoring the ongoing work on Rich and Textual.

Or buy me a coffee to say thanks.

Will McGugan

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

Successfully merging a pull request may close this issue.

1 participant