File size: 7,693 Bytes
036b3a6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# Javascript examples


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

To expedite fast development, FastHTML comes with several built-in
Javascript and formatting components. These are largely provided to
demonstrate FastHTML JS patterns. There’s far too many JS libs for
FastHTML to wrap them all, and as shown here the code to add FastHTML
support is very simple anyway.

------------------------------------------------------------------------

<a
href="https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/js.py#L16"
target="_blank" style="float:right; font-size:smaller">source</a>

### light_media

>  light_media (css:str)

*Render light media for day mode views*

<table>
<thead>
<tr>
<th></th>
<th><strong>Type</strong></th>
<th><strong>Details</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>css</td>
<td>str</td>
<td>CSS to be included in the light media query</td>
</tr>
</tbody>
</table>

``` python
light_media('.body {color: green;}')
```

``` html
<style>@media (prefers-color-scheme: light) {.body {color: green;}}</style>
```

------------------------------------------------------------------------

<a
href="https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/js.py#L23"
target="_blank" style="float:right; font-size:smaller">source</a>

### dark_media

>  dark_media (css:str)

*Render dark media for night mode views*

<table>
<thead>
<tr>
<th></th>
<th><strong>Type</strong></th>
<th><strong>Details</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>css</td>
<td>str</td>
<td>CSS to be included in the dark media query</td>
</tr>
</tbody>
</table>

``` python
dark_media('.body {color: white;}')
```

``` html
<style>@media (prefers-color-scheme:  dark) {.body {color: white;}}</style>
```

------------------------------------------------------------------------

<a
href="https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/js.py#L35"
target="_blank" style="float:right; font-size:smaller">source</a>

### MarkdownJS

>  MarkdownJS (sel='.marked')

*Implements browser-based markdown rendering.*

<table>
<thead>
<tr>
<th></th>
<th><strong>Type</strong></th>
<th><strong>Default</strong></th>
<th><strong>Details</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>sel</td>
<td>str</td>
<td>.marked</td>
<td>CSS selector for markdown elements</td>
</tr>
</tbody>
</table>

Usage example
[here](../tutorials/quickstart_for_web_devs.html#rendering-markdown).

``` python
__file__ = '../../fasthtml/katex.js'
```

------------------------------------------------------------------------

<a
href="https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/js.py#L43"
target="_blank" style="float:right; font-size:smaller">source</a>

### KatexMarkdownJS

>  KatexMarkdownJS (sel='.marked', inline_delim='$', display_delim='$$',
>                       math_envs=None)

<table>
<colgroup>
<col style="width: 6%" />
<col style="width: 25%" />
<col style="width: 34%" />
<col style="width: 34%" />
</colgroup>
<thead>
<tr>
<th></th>
<th><strong>Type</strong></th>
<th><strong>Default</strong></th>
<th><strong>Details</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>sel</td>
<td>str</td>
<td>.marked</td>
<td>CSS selector for markdown elements</td>
</tr>
<tr>
<td>inline_delim</td>
<td>str</td>
<td>$</td>
<td>Delimiter for inline math</td>
</tr>
<tr>
<td>display_delim</td>
<td>str</td>
<td>$$</td>
<td>Delimiter for long math</td>
</tr>
<tr>
<td>math_envs</td>
<td>NoneType</td>
<td>None</td>
<td>List of environments to render as display math</td>
</tr>
</tbody>
</table>

KatexMarkdown usage example:

``` python
longexample = r"""
Long example:

$$\begin{array}{c}

\nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} &
= \frac{4\pi}{c}\vec{\mathbf{j}}    \nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho \\

\nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \\

\nabla \cdot \vec{\mathbf{B}} & = 0

\end{array}$$
"""

app, rt = fast_app(hdrs=[KatexMarkdownJS()])

@rt('/')
def get():
    return Titled("Katex Examples", 
        # Assigning 'marked' class to components renders content as markdown
        P(cls='marked')("Inline example: $\sqrt{3x-1}+(1+x)^2$"),
        Div(cls='marked')(longexample)
    )
```

------------------------------------------------------------------------

<a
href="https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/js.py#L58"
target="_blank" style="float:right; font-size:smaller">source</a>

### HighlightJS

>  HighlightJS (sel='pre code:not([data-highlighted="yes"])',
>                   langs:str|list|tuple='python', light='atom-one-light',
>                   dark='atom-one-dark')

*Implements browser-based syntax highlighting. Usage example
[here](../tutorials/quickstart_for_web_devs.html#code-highlighting).*

<table>
<colgroup>
<col style="width: 6%" />
<col style="width: 25%" />
<col style="width: 34%" />
<col style="width: 34%" />
</colgroup>
<thead>
<tr>
<th></th>
<th><strong>Type</strong></th>
<th><strong>Default</strong></th>
<th><strong>Details</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>sel</td>
<td>str</td>
<td>pre code:not([data-highlighted=“yes”])</td>
<td>CSS selector for code elements. Default is industry standard, be
careful before adjusting it</td>
</tr>
<tr>
<td>langs</td>
<td>str | list | tuple</td>
<td>python</td>
<td>Language(s) to highlight</td>
</tr>
<tr>
<td>light</td>
<td>str</td>
<td>atom-one-light</td>
<td>Light theme</td>
</tr>
<tr>
<td>dark</td>
<td>str</td>
<td>atom-one-dark</td>
<td>Dark theme</td>
</tr>
</tbody>
</table>

------------------------------------------------------------------------

<a
href="https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/js.py#L81"
target="_blank" style="float:right; font-size:smaller">source</a>

### SortableJS

>  SortableJS (sel='.sortable', ghost_class='blue-background-class')

<table>
<colgroup>
<col style="width: 6%" />
<col style="width: 25%" />
<col style="width: 34%" />
<col style="width: 34%" />
</colgroup>
<thead>
<tr>
<th></th>
<th><strong>Type</strong></th>
<th><strong>Default</strong></th>
<th><strong>Details</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>sel</td>
<td>str</td>
<td>.sortable</td>
<td>CSS selector for sortable elements</td>
</tr>
<tr>
<td>ghost_class</td>
<td>str</td>
<td>blue-background-class</td>
<td>When an element is being dragged, this is the class used to
distinguish it from the rest</td>
</tr>
</tbody>
</table>

------------------------------------------------------------------------

<a
href="https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/js.py#L92"
target="_blank" style="float:right; font-size:smaller">source</a>

### MermaidJS

>  MermaidJS (sel='.language-mermaid', theme='base')

*Implements browser-based Mermaid diagram rendering.*

<table>
<thead>
<tr>
<th></th>
<th><strong>Type</strong></th>
<th><strong>Default</strong></th>
<th><strong>Details</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>sel</td>
<td>str</td>
<td>.language-mermaid</td>
<td>CSS selector for mermaid elements</td>
</tr>
<tr>
<td>theme</td>
<td>str</td>
<td>base</td>
<td>Mermaid theme to use</td>
</tr>
</tbody>
</table>

``` python
app, rt = fast_app(hdrs=[MermaidJS()])
@rt('/')
def get():
    return Titled("Mermaid Examples", 
        # Assigning 'marked' class to components renders content as markdown
        Pre(Code(cls ="language-mermaid")('''flowchart TD
            A[main] --> B["fact(5)"] --> C["fact(4)"] --> D["fact(3)"] --> E["fact(2)"] --> F["fact(1)"] --> G["fact(0)"]
           ''')))
```

In a markdown file, just like a code cell you can define

\`\`\`mermaid

        graph TD
        A --> B 
        B --> C 
        C --> E

\`\`\`