You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide/content.md
+5-4Lines changed: 5 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
# Content
2
2
3
-
Custom widgets will typically implement a [`render()`][textual.widget.Widget.render]method which returns the *content* of the widget.
4
-
In other words, the output that will be displayed within the widget's borders.
3
+
The *content* of widget (displayed within the widget's borders) is typically specified in a call to [`Static.update`][textual.widgets.static.Static.update] or returned from [`render()`][textual.widget.Widget.render]in the case of [custom widgets](./widgets.md#custom-widgets).
4
+
5
5
There are a few ways for you to specify this content.
6
6
7
7
- Text — either plain text, or [markup](#markup).
@@ -13,6 +13,7 @@ In this chapter, we will cover all these methods.
13
13
## Markup
14
14
15
15
When building a custom widget you can embed color and style information in the string returned from the Widget's [`render()`][textual.widget.Widget.render] method.
16
+
Markup is specified as a string which contains
16
17
Text enclosed in square brackets (`[]`) won't appear in the output, but will modify the style of the text that follows.
17
18
This is known as *Textual markup*.
18
19
@@ -380,7 +381,7 @@ class WelcomeWidget(Widget):
380
381
381
382
While this is straightforward and intuitive, it can potentially break in subtle ways.
382
383
If the 'name' variable contains square brackets, these may be interpreted as markup.
383
-
For instance if the user entered their name at some point as "[magenta italic underline]Will is Cool!" then your app will display those styles where you didn't intend them to be.
384
+
For instance if the user entered their name at some point as "[magenta italic]Will" then your app will display those styles where you didn't intend them to be.
384
385
385
386
We can avoid this problem by relying on the [Content.from_markup][textual.content.Content.from_markup] method to insert the variables for us.
386
387
If you supply variables as keyword arguments, these will be substituted in the markup using the same syntax as [string.Template](https://docs.python.org/3/library/string.html#template-strings).
@@ -396,7 +397,7 @@ You can experiment with this feature by entering a dictionary of variables in th
396
397
397
398
Here's what that looks like:
398
399
399
-
```{.textual path="docs/examples/guide/content/playground.py" lines=16 type="hello [bold]$name[/bold]!\t{'name': '[magenta italic underline]Will is Cool!'}"]}
0 commit comments