Skip to content

Commit ead2b31

Browse files
committed
added escaping to docs
1 parent 21e91cd commit ead2b31

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

docs/api/markup.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: "textual.markup"
3+
---
4+
5+
::: textual.markup

docs/guide/content.md

+22
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,28 @@ Here's what that looks like:
312312
```{.textual path="docs/examples/guide/content/playground.py" lines=16 type="Play the [on $success 30% @click=app.bell]bell[/]"]}
313313
```
314314

315+
### Escaping
316+
317+
If you precede an open bracket with a backslash (`\`), then Textual will not consider it to be a tag and the square bracket will be displayed without modification.
318+
319+
For example, the backslash in the following content prevents the following text from becoming bold, and the text `[bold]` will be in the output.
320+
321+
```{.textual path="docs/examples/guide/content/playground.py" lines=16 type="\[bold]This is not bold"]}
322+
```
323+
324+
!!! tip "Escaping markup"
325+
326+
You can also use the [escape][textual.markup.escape] function to escape tags
327+
328+
Some methods, such as [`notify()`][textual.widget.Widget.notify], have a `markup` switch that you can use to disable markup.
329+
You may want to use this if you want to output a Python repr strings, so that Textual doesn't interpret a list as a tag.
330+
331+
Here's an example:
332+
333+
```python
334+
# debug code: what is my_list at this point?
335+
self.notify(repr(my_list), markup=False)
336+
```
315337

316338
## Content class
317339

mkdocs-nav.yml

+2
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ nav:
194194
- "api/command.md"
195195
- "api/constants.md"
196196
- "api/containers.md"
197+
- "api/content.md"
197198
- "api/coordinate.md"
198199
- "api/dom_node.md"
199200
- "api/events.md"
@@ -206,6 +207,7 @@ nav:
206207
- "api/logger.md"
207208
- "api/logging.md"
208209
- "api/map_geometry.md"
210+
- "api/markup.md"
209211
- "api/message_pump.md"
210212
- "api/message.md"
211213
- "api/on.md"

src/textual/markup.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""
2+
Utilities related to content markup.
3+
4+
"""
5+
16
from __future__ import annotations
27

38
from textual.css.parse import substitute_references
@@ -171,7 +176,7 @@ def escape_backslashes(match: Match[str]) -> str:
171176

172177

173178
def parse_style(style: str, variables: dict[str, str] | None = None) -> Style:
174-
"""Parse an encoded style.
179+
"""Parse a style with substituted variables.
175180
176181
Args:
177182
style: Style encoded in a string.

0 commit comments

Comments
 (0)