Skip to content

Commit e228dc7

Browse files
committed
Add a title to all appropriate code examples in the user-guide.
1 parent ec8e748 commit e228dc7

File tree

15 files changed

+123
-121
lines changed

15 files changed

+123
-121
lines changed

docs/beginning-pyscript.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ PyScript, and so we create a `<script>` tag that references the PyScript
111111
module, and a `<link>` to some PyScript specific CSS, in the document's
112112
`<head>` tag:
113113

114-
```html
114+
```html title="The head of index.html"
115115
<!DOCTYPE html>
116116
<html>
117117
<head>
@@ -133,7 +133,7 @@ Notice that the `<body>` of the document is empty except for the TODO comment.
133133
It's in here that we put standard HTML content to define our user interface, so
134134
the `<body>` now looks like:
135135

136-
```html
136+
```html title="The body of index.html"
137137
<body>
138138
<h1>Polyglot 🦜 💬 🇬🇧 ➡️ 🏴‍☠️</h1>
139139
<p>Translate English into Pirate speak...</p>
@@ -158,7 +158,7 @@ where PyScript should find the configuration (`config="./pyscript.json"`).
158158

159159
In the end, our HTML should look like this:
160160

161-
```html title="index.html"
161+
```html title="The complete index.html"
162162
<!DOCTYPE html>
163163
<html>
164164
<head>

docs/user-guide/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ filename in the destination directory.
273273

274274
For example, the end of the previous config file could be:
275275

276-
```toml
276+
```toml title="Automatic use of the source filename into a destination directory."
277277
"{TO}" = "./my_module/"
278278
"{FROM}/__init__.py" = "{TO}"
279279
"{FROM}/foo.py" = "{TO}"

docs/user-guide/display.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ superpowers.
1414

1515
The simplest use is displaying text:
1616

17-
```python
17+
```python title="Simple Python objects via display()"
1818
from pyscript import display
1919

2020

@@ -29,7 +29,7 @@ page. Each call appends content unless you specify otherwise.
2929

3030
Control where content appears using the `target` parameter:
3131

32-
```python
32+
```python title="Specify where to display things."
3333
from pyscript import display
3434

3535

@@ -45,7 +45,7 @@ display("Hello", target="#output-div")
4545
By default, `display()` appends content. Use `append=False` to replace
4646
existing content:
4747

48-
```python
48+
```python title="Append or replace."
4949
from pyscript import display
5050

5151

@@ -62,7 +62,7 @@ display("More content", target="output-div", append=True)
6262

6363
Plain strings are automatically HTML-escaped for safety:
6464

65-
```python
65+
```python title="Strings are escaped."
6666
from pyscript import display
6767

6868

@@ -75,7 +75,7 @@ display("<script>alert('XSS')</script>")
7575

7676
To display unescaped HTML, wrap it in the `HTML` class:
7777

78-
```python
78+
```python title="The HTML class unescapes (handle with care!)"
7979
from pyscript import HTML, display
8080

8181

@@ -93,7 +93,7 @@ display(HTML("<p>This is <strong>bold</strong> text.</p>"))
9393

9494
Most Python objects display using their `__repr__()` method:
9595

96-
```python
96+
```python title="Default behaviour via __repr__()."
9797
from pyscript import display
9898

9999

@@ -120,7 +120,7 @@ display(Person("Bob"))
120120

121121
Display images from various sources:
122122

123-
```python
123+
```python title="Image handling."
124124
from pyscript import display
125125

126126

@@ -162,7 +162,7 @@ Objects are checked for these methods in order of preference:
162162

163163
Create objects that display beautifully:
164164

165-
```python
165+
```python title="Custom HTML rendering."
166166
from pyscript import display
167167

168168

@@ -199,7 +199,7 @@ display(ColourSwatch("#0000FF", "Blue"))
199199

200200
Provide multiple representations for maximum compatibility:
201201

202-
```python
202+
```python title="Define rendering via mime-type."
203203
from pyscript import display
204204

205205

@@ -247,7 +247,7 @@ display(table)
247247
When PyScript runs a `<script type="mpy">` tag, `display()` outputs to
248248
that script's location by default:
249249

250-
```html
250+
```html title="Output at the &lt;script&gt;'s location in the DOM."
251251
<div>
252252
<h2>Output appears here:</h2>
253253
<script type="mpy">
@@ -261,7 +261,7 @@ that script's location by default:
261261

262262
Use the `target` attribute on your script tag to send output elsewhere:
263263

264-
```html
264+
```html title="Specify an output target."
265265
<div id="results"></div>
266266

267267
<script type="mpy" target="results">
@@ -293,7 +293,7 @@ This example demonstrates:
293293
294294
**Never use `HTML()` with untrusted content:**
295295
296-
```python
296+
```python title="This is dangerous!"
297297
# DANGEROUS - don't do this!
298298
user_input = "<script>alert('XSS')</script>"
299299
display(HTML(user_input))
@@ -316,7 +316,7 @@ For frequent or rapid updates:
316316
317317
Keep display logic close to your data:
318318
319-
```python
319+
```python title="_repr_ logic on a class."
320320
class Report:
321321
def __init__(self, data):
322322
self.data = data

docs/user-guide/dom.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ management, and Pythonic method names.
4040
The `page` object represents your web page. Use it to find elements by
4141
their ID or with CSS selectors:
4242

43-
```python
43+
```python title="Referencing elements via the page object."
4444
from pyscript import web
4545

4646

@@ -69,7 +69,7 @@ names correspond to HTML tags, and are lower-case to match web
6969
conventions. Compose elements together in a
7070
[declarative style](https://en.wikipedia.org/wiki/Declarative_programming):
7171

72-
```python
72+
```python title="Declaratively creating elements on the page."
7373
from pyscript import web
7474

7575

@@ -100,7 +100,7 @@ arguments like `id`, `classes`, and `style` set HTML attributes.
100100
You can also create elements
101101
[imperatively](https://en.wikipedia.org/wiki/Imperative_programming):
102102

103-
```python
103+
```python title="Imperatively created elements on the web page."
104104
from pyscript import web
105105

106106

@@ -122,7 +122,7 @@ my_div.append(my_p)
122122
Once you have an element, you can modify its content and attributes
123123
using idiomatic Python:
124124

125-
```python
125+
```python title="Modifying an element."
126126
from pyscript import web
127127

128128

@@ -149,7 +149,7 @@ element.update(
149149
Element classes behave like a Python `set`, and styles behave like a
150150
Python `dict`:
151151

152-
```python
152+
```python title="CSS classes are a Python set, CSS styles a Python dict."
153153
from pyscript import web
154154

155155

@@ -186,7 +186,7 @@ if "color" in element.style:
186186
When you find multiple elements, you get an `ElementCollection` that
187187
you can iterate over, slice, or update in bulk:
188188

189-
```python
189+
```python title="Working with ElementCollections."
190190
from pyscript import web
191191

192192

@@ -231,7 +231,7 @@ select. When rendered on a web page, it looks like this:
231231
The `options` property of `select` elements provides convenient methods
232232
for managing such options:
233233

234-
```python
234+
```python title="Elements with options (e.g. &lt;select&gt;)."
235235
from pyscript import web
236236

237237

@@ -264,7 +264,7 @@ lists of options to function.
264264

265265
The `@when` decorator works seamlessly with `pyscript.web` elements:
266266

267-
```python
267+
```python title="@when working with Element instances."
268268
from pyscript import when, web
269269

270270

@@ -290,7 +290,7 @@ Learn more about event handling in the [events guide](events.md).
290290

291291
When needed, you can access the underlying DOM element directly:
292292

293-
```python
293+
```python title="Use _dom_element to get the underlying JavaScript Element."
294294
from pyscript import web
295295

296296

@@ -339,7 +339,7 @@ This is available via the `pyscript.window` and `pyscript.document`
339339
objects, which are proxies for JavaScript's `globalThis` and `document`
340340
objects:
341341

342-
```python
342+
```python title="Complete JavaScript access via the FFI."
343343
from pyscript import window, document
344344

345345

@@ -392,7 +392,7 @@ list `["hello", 1, 2, 3]`, and vice versa.
392392
Instantiating JavaScript classes requires special handling because
393393
Python and JavaScript do it differently:
394394

395-
```python
395+
```python title="Use .new() to instantiate JavaScript classes."
396396
from pyscript import window
397397

398398

docs/user-guide/editor.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ demonstrations, and interactive coding experiences.
2020
Create an editor by setting the script type to `py-editor` for Pyodide
2121
or `mpy-editor` for MicroPython:
2222

23-
```html
23+
```html title="A simple editor example."
2424
<script type="py-editor">
2525
import sys
2626
print(sys.version)
@@ -42,7 +42,7 @@ only when needed.
4242
Each editor runs in its own isolated environment by default. Variables
4343
and state don't leak between editors:
4444

45-
```html
45+
```html title="Independent editor environments."
4646
<script type="py-editor">
4747
import sys
4848
print(sys.version)
@@ -64,7 +64,7 @@ exist in the first.
6464

6565
Editors can share state by using the same interpreter and `env` attribute:
6666

67-
```html
67+
```html title="Shared editor environments."
6868
<script type="mpy-editor" env="shared">
6969
if 'a' not in globals():
7070
a = 1
@@ -92,7 +92,7 @@ of each editor, showing which environment it belongs to.
9292
Sometimes you need boilerplate code that runs automatically without
9393
cluttering the visible editor. The `setup` attribute handles this:
9494

95-
```html
95+
```html title="Editor setup."
9696
<script type="mpy-editor" env="classroom" setup>
9797
# This code runs automatically but isn't visible.
9898
import math
@@ -131,7 +131,7 @@ code. This speeds up the edit-run-debug cycle.
131131
132132
Access and control editors from Python code using the `code` property:
133133
134-
```python
134+
```python title="Updating code in the editor via Python."
135135
from pyscript import document
136136
137137
# Get reference to an editor.
@@ -159,7 +159,7 @@ based on user actions elsewhere on the page.
159159
By default, editors render where their script tag appears. Use the
160160
`target` attribute to render elsewhere:
161161
162-
```html
162+
```html title="Specify a target in which to render the editor."
163163
<script type="mpy-editor" target="editor-container">
164164
import sys
165165
print(sys.version)
@@ -176,7 +176,7 @@ script tag. This gives you control over page layout.
176176
Editors require explicit configuration through the `config` attribute.
177177
They don't use `<py-config>` or `<mpy-config>` tags:
178178
179-
```html
179+
```html title="Sample configuration."
180180
<script type="py-editor" config='{"packages": ["numpy"]}'>
181181
import numpy as np
182182
print(np.array([1, 2, 3]))
@@ -191,7 +191,7 @@ subsequent editors in the same environment share that configuration.
191191
Advanced use cases may require custom execution behaviour. Override the
192192
editor's `handleEvent` method:
193193
194-
```html
194+
```html title="Custom execution behaviour."
195195
<script type="mpy-editor" id="custom">
196196
print(6 * 7)
197197
</script>

0 commit comments

Comments
 (0)