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 | string = m | The unique identifier used in the serialized JSON structure to mark a value for markup-safe processing. |
Methods
check()
@classmethod
def check(
value: t.Any
) - > bool
Determines if a value is compatible with the Markup API by checking for the presence of a callable html method.
Parameters
| Name | Type | Description |
|---|---|---|
| value | t.Any | The object to inspect for Markup API compatibility. |
Returns
| Type | Description |
|---|---|
bool | True if the value provides an html method, indicating it can be serialized as markup. |
to_json()
@classmethod
def to_json(
value: t.Any
) - > t.Any
Converts a markup-compatible object into a JSON-serializable string by invoking its html method.
Parameters
| Name | Type | Description |
|---|---|---|
| value | t.Any | The markup-compatible object to be serialized. |
Returns
| Type | Description |
|---|---|
t.Any | The raw HTML string representation of the object. |
to_python()
@classmethod
def to_python(
value: t.Any
) - > t.Any
Deserializes a value back into a Markup instance to ensure it is treated as safe HTML.
Parameters
| Name | Type | Description |
|---|---|---|
| value | t.Any | The serialized markup string to be converted back into a Markup object. |
Returns
| Type | Description |
|---|---|
t.Any | An instance of markupsafe.Markup containing the deserialized content. |