Skip to content

Commit

Permalink
Merge pull request #56 from apcamargo/clean-text-indentation
Browse files Browse the repository at this point in the history
Make `_make_rich_rext` remove text indentations with `inspect.cleandoc`
  • Loading branch information
ewels committed Apr 27, 2022
2 parents 964ebbd + 03a0031 commit 2941244
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Bumped minimum version of `rich` from `10` to `10.7.0` (when `Group` was introduced)
- Refactored CLI's patching functionality to support `from rich_click.cli import patch`.
- Make `_make_rich_rext` remove text indentations using `inspect.cleandoc` [[#55](https://github.com/ewels/rich-click/issues/55)]

## Version 1.3.0 (2022-03-29)

Expand Down
5 changes: 4 additions & 1 deletion src/rich_click/rich_click.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import inspect
import re
from typing import Dict, List, Optional, Union

Expand Down Expand Up @@ -114,7 +115,7 @@ def _get_rich_console() -> Console:


def _make_rich_rext(text: str, style: str = "") -> Union[rich.markdown.Markdown, rich.text.Text]:
"""Take a string and return styled text.
"""Take a string, remove indentations, and return styled text.
By default, return the text as a Rich Text with the request style.
If USE_RICH_MARKUP is True, also parse the text for Rich markup strings.
Expand All @@ -130,6 +131,8 @@ def _make_rich_rext(text: str, style: str = "") -> Union[rich.markdown.Markdown,
Returns:
MarkdownElement or Text: Styled text object
"""
# Remove indentations from input text
text = inspect.cleandoc(text)
if USE_MARKDOWN:
if USE_MARKDOWN_EMOJI:
text = Emoji.replace(text)
Expand Down

0 comments on commit 2941244

Please sign in to comment.