TagMarkup
Serialize anything matching the :class:~markupsafe.Markup API by having a __html__ method to the result of that method. Always deserializes to an instance of :class:~markupsafe.Markup.
Attributes
| Attribute | Type | Description |
|---|---|---|
| key | str = " m" | This attribute stores a string identifier used internally by the JSONTag system to identify this specific serialization/deserialization strategy. |
Methods
check()
@classmethod
def check(
value: t.Any
) - > bool
Checks if the provided value has an __html__ method, indicating it can be serialized as HTML. Callers use this to determine if a value is compatible with the TagMarkup serialization.
Parameters
| Name | Type | Description |
|---|---|---|
| value | t.Any | The value to check for HTML serialization capability. |
Returns
| Type | Description |
|---|---|
bool | True if the value has a callable __html__ method, False otherwise. |
to_json()
@classmethod
def to_json(
value: t.Any
) - > t.Any
Serializes the given value to a JSON-compatible string by calling its __html__ method. Callers use this to convert objects with an HTML representation into a string format suitable for JSON output.
Parameters
| Name | Type | Description |
|---|---|---|
| value | t.Any | The object to serialize, which must have an __html__ method. |
Returns
| Type | Description |
|---|---|
t.Any | The string result of the value's __html__ method. |
to_python()
@classmethod
def to_python(
value: t.Any
) - > t.Any
Deserializes a value into a Markup object. Callers use this to convert a string back into a Markup instance, ensuring it is treated as safe HTML.
Parameters
| Name | Type | Description |
|---|---|---|
| value | t.Any | The value to deserialize into a Markup object. |
Returns
| Type | Description |
|---|---|
t.Any | A Markup object created from the input value. |