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
//! The [`Context`] trait and its implementors.
/// A marker trait to represent the context that the value is being rendered to.
///
/// This can be [`Element`], [`AttributeValue`], [`DatastarSource`], or [`ScriptSource`]. [`Element`]
/// represents an HTML node, [`AttributeValue`] represents an attribute value
/// which will eventually be surrounded by double quotes, and [`DatastarSource`] represents
/// JavaScript source embedded inside a Datastar attribute value. [`ScriptSource`]
/// represents JavaScript source embedded inside a `<script>` element.
///
/// This is used to ensure that the correct rendering methods are called
/// for each context, and to prevent errors such as accidentally rendering
/// an HTML element into an attribute value.
/// A marker type to represent a complete element node.
///
/// All types and traits that are generic over the `Context` trait use
/// [`Element`] as the default for the generic type parameter.
///
/// Traits and types with this marker type expect complete HTML nodes. If
/// rendering string-like types, the value/implementation must escape `&` to
/// `&`, `<` to `<`, and `>` to `>`.
;
/// A marker type to represent an attribute value.
///
/// Traits and types with this marker type expect an attribute value which will
/// eventually be surrounded by double quotes. The value/implementation must
/// escape `&` to `&`, `<` to `<`, `>` to `>`, and `"` to `"`.
;
/// A marker type to represent a JavaScript expression or value inside a
/// Datastar attribute (e.g. `data-signals`, `data-class`, `data-on:click`).
///
/// Values rendered with this context are ultimately embedded inside a
/// double-quoted HTML attribute, so implementations must ensure the output
/// is valid JavaScript source and is also safe for HTML attribute parsing.
;
/// A marker type to represent JavaScript source inside a `<script>` element.
///
/// Values rendered with this context are ultimately embedded directly into a
/// script body, so implementations must ensure the output is valid JavaScript
/// source and cannot terminate the surrounding `<script>` element.
;