Skip to content

Commit 97feb9c

Browse files
committed
content docs
1 parent bba0b4f commit 97feb9c

File tree

1 file changed

+37
-29
lines changed

1 file changed

+37
-29
lines changed

docs/guide/content.md

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -40,63 +40,61 @@ To launch the playground, run the following command:
4040
python -m textual.markup
4141
```
4242

43-
The interface looks something like this:
43+
You can experiment with markup by entering it in to the textarea at the top of the terminal, and seeing the results in the lower pane:
4444

4545
```{.textual path="docs/examples/guide/content/playground.py", type="[i]Hello!"] lines=15}
4646
```
4747

48-
If you are trying Textual Markup for the first time, it is worthwhile to test what you read with he Playground app!
48+
You might find it helpful to try out some of the examples from this guide in the playground.
4949

5050
### Tags
5151

5252
There are two types of tag: an *opening* tag which starts a style change, and a *closing* tag which ends a style change.
53-
An opening tag looks something like the following:
53+
An opening tag looks like this:
5454

5555
```
5656
[bold]
5757
```
5858

59-
This will make following text bold. For instance, the following would result in the text "Hello, World!" in bold:
6059

60+
The second type of tag, known as a *closing* tag, is almost identical, but starts with a forward slash inside the first square bracket.
61+
A closing tag looks like this:
6162

6263
```
63-
[bold]Hello, World!
64+
[/bold]
6465
```
6566

66-
The second type of tag, a *closing* tag, is almost identical, but starts with a forward slash inside the first square bracket.
67-
A closing tag ends a style, started by a previous opening tag.
68-
69-
!!! note
70-
71-
Without a closing tag, the style will persist to the end of the string. This can be a convenient shortcut if you want to style the entire string.
67+
A closing tag marks the end of a style from the corresponding opening tag.
7268

73-
74-
For instance, the following is a closing tag to end the bold style:
69+
By wrapping text in an opening and closing tag, we can apply the style to just the characters we want.
70+
For example, the following makes just the first word in "Hello, World!" bold:
7571

7672
```
77-
[/bold]
73+
[bold]Hello[/bold], World!
7874
```
7975

80-
A closing tag must match a previous opening tag, so that Textual knows which style is being closed.
81-
Let's use this to embolden just the first word in our example:
76+
Note how the tags change the style but are removed from the output:
8277

78+
```{.textual path="docs/examples/guide/content/playground.py", type="[bold]Hello[/bold], World!" lines=15}
8379
```
84-
[bold]Hello[/bold], World!
85-
```
86-
87-
This will make "Hello" bold, but the rest of the text will be non-bold.
8880

89-
You can use any number of tags, and they may overlap which combines their styles.
81+
You can use any number of tags.
82+
If tags overlap their styles are combined.
9083
For instance, the following combines the bold and italic styles:
9184

9285
```
9386
[bold]Bold [italic]Bold and italic[/italic][/bold]
9487
```
9588

89+
Here's the output:
90+
91+
```{.textual path="docs/examples/guide/content/playground.py", type="[bold]Bold [italic]Bold and italic[/italic][/bold]" lines=15}
92+
```
93+
9694
#### Auto-closing tags
9795

9896
A closing tag without any style information (i.e. `[/]`) is an *auto-closing* tag.
99-
Auto-closing tags will close the last tag, regardless of it's style.
97+
Auto-closing tags will close the last opened tag.
10098

10199
The following uses an auto-closing tag to end the bold style:
102100

@@ -135,7 +133,8 @@ Styles can also be combined within the same tag, so `[bold italic]` produces tex
135133
You can invert a style by preceding it with the word `not`.
136134
This is useful if you have text with a given style, but you temporarily want to disable it.
137135

138-
For instance, the following markup starts with `[bold]` which makes the text bold until it reaches `[not bold]` which disables the bold style, until the corresponding `[/not bold]`.
136+
For instance, the following starts with `[bold]`, which would normally make the rest of the text bold.
137+
However, the `[not bold]` tag disables bold until the corresponding `[/not bold]` tag:
139138

140139
```
141140
[bold]This is bold [not bold]This is not bold[/not bold] This is bold.
@@ -166,23 +165,28 @@ You can also any of the [named colors](/css_types/color).
166165

167166
Colors may also include an *alpha* component, which makes the color fade in to the background.
168167
For instance, if we specify the color with `rgba(...)`, then we can add an alpha component between 0 and 1.
169-
An alpha of zero is fully transparent (and therefore invisible). An alpha of 1 is fully opaque, and equivalent to a color without an alpha component.
170-
A value between 0 and 1 results in a faded color.
168+
An alpha of 0 is fully transparent (and therefore invisible). An alpha of 1 is fully opaque, and equivalent to a color without an alpha component.
169+
A value between 0 and 1 results in a faded color.
171170

172171
In the following example we have an alpha of 0.5, which will produce a color half way between the background and solid green:
173172

174173
```
175174
[rgba(0, 255, 0, 0.5)]Faded green (and probably hard to read)[/]
176175
```
177176

178-
!!! tip
177+
Here's the output:
178+
179+
```{.textual path="docs/examples/guide/content/playground.py", type="[rgba(0, 255, 0, 0.5)]Faded green (and probably hard to read)[/]" lines=15}
180+
```
181+
182+
!!! warning
179183

180184
Be careful when using colors with an alpha component. Text that is blended too much with the background may become hard to read.
181185

182186

183187
#### Auto colors
184188

185-
You can specify a color as "auto", which is a special value that tells Textual to pick either white or black text -- whichever has the best contrast.
189+
You can also specify a color as "auto", which is a special value that tells Textual to pick either white or black text -- whichever has the best contrast.
186190

187191
For example, the following will produce either white or black text (I haven't checked) on a sienna background:
188192

@@ -193,7 +197,7 @@ For example, the following will produce either white or black text (I haven't ch
193197

194198
#### Opacity
195199

196-
While you can set the opacity in the color itself, you can also add a percentage which will modify the alpha component of the previous color.
200+
While you can set the opacity in the color itself by adding an alpha component to the color, you can also modify the alpha of the previous color with a percentage.
197201

198202
For example, the addition of `50%` will result in a color half way between the background and "red":
199203

@@ -220,6 +224,7 @@ Here's an example that tints the background with 20% red:
220224
[on #ff0000 20%]The background has a red tint.[/]
221225
```
222226

227+
Here's the output:
223228

224229
```{.textual path="docs/examples/guide/content/playground.py" lines=15 type="[on #ff0000 20%]The background has a red tint.[/]"]}
225230
```
@@ -243,14 +248,16 @@ The following displays text in the 'warning' style on a muted 'warning' backgrou
243248
[$warning on $warning-muted]This is a warning![/]
244249
```
245250

251+
Here's the result of that markup:
252+
246253
```{.textual path="docs/examples/guide/content/playground.py" lines=15 type="[$warning on $warning-muted]This is a warning![/]"]}
247254
```
248255

249256
### Links
250257

251258
Styles may contain links which will create clickable links that launch your web browser, if supported by your terminal.
252259

253-
To create a link add `link=` followed by your link in quotes.
260+
To create a link add `link=` followed by your link in quotes (single or double).
254261
For instance, the following create a clickable link:
255262

256263
```
@@ -262,6 +269,7 @@ This will produce the following output:
262269

263270

264271

272+
265273
## Content class
266274

267275
Under the hood, Textual will convert markup into a [Content][textual.content.Content] instance.

0 commit comments

Comments
 (0)