-
I'm trying to display Rich-formatted text in a table. With Textual 0.2+, this code from textual.app import App, ComposeResult, RenderResult
from textual.widgets import Static
from textual.widget import Widget
from rich.table import Table
class Info(Widget):
def render(self):
table = Table(show_header=False, expand=True, box=None, padding=0)
table.add_column(justify="left", no_wrap=True)
table.add_column(justify="right", no_wrap=True)
table.add_row("[b]abc[/]", "[green]xyz[/]")
return table
class FooApp(App):
CSS = """
.box {
width: 100%;
border: white;
height: 1;
}
"""
def compose(self) -> ComposeResult:
yield Static("One [b]two[/] three", classes="box")
yield Info(classes="box")
foo_app = FooApp()
foo_app.run() gives Formatting is respected in Any hints? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi! I've checked with @willmcgugan and, as of now, Textual won't render markup that is within a renderable, but will render markup when the def render(self):
table = Table(show_header=False, expand=True, box=None, padding=0)
table.add_column(justify="left", no_wrap=True)
table.add_column(justify="right", no_wrap=True)
table.add_row(
Text.from_markup("[b]abc[/]"),
Text.from_markup("[green]xyz[/]")
)
return table That will of course also need a |
Beta Was this translation helpful? Give feedback.
Hi! I've checked with @willmcgugan and, as of now, Textual won't render markup that is within a renderable, but will render markup when the
render
method returns a string with markup in it. This is by design but we're going to have a rethink of this. Meanwhile, to make your code work as you were intending, you can use Rich'sText.from_markup
on your string data. For example, taking yourInfo.Render
method above: