使用 python Rich 库缩进文本块

Indenting text-block with python Rich library

提问人:Windeycastle 提问时间:11/13/2023 更新时间:11/13/2023 访问量:25

问:

我正在尝试使用 Rich 库中的 rich.console.print(Markdown(text)) 将格式化的 markdown 文本块打印到终端。但是,我想让这个文本块缩进一个制表符。 通常我会使用 textwrap 模块,但在使用它时,rich。Markdown() 会将其解释为代码块,因此除了给它一个不同的背景之外,不会对 Markdown 应用任何格式。

使用 textwrap 的示例:textwrap

不使用 textwrap 的示例:no textwrap

我的 Python 代码:

    pretty_console.console.print("[u bright_blue]All series:[/]")
    for e in display_data:
        pretty_console.console.print(
            f"{e['id'].ljust(max_series_id_length)}: "
            f"[bold]{e['name'].ljust(max_series_name_length)}[/]\n"
        )
        if e['description']:
            text = e['description']
            markdown_text = Markdown(text)
            pretty_console.console.print(markdown_text)

请原谅图片中的荷兰人,但在这种情况下,语言并不重要。

有谁知道如何打印富格式文本,缩进在(软)换行时也有效?

Python 格式 丰富

评论


答: 暂无答案