Skip to main content

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

AttributeTypeDescription
keystr = " 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

NameTypeDescription
valuet.AnyThe value to check for HTML serialization capability.

Returns

TypeDescription
boolTrue 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

NameTypeDescription
valuet.AnyThe object to serialize, which must have an __html__ method.

Returns

TypeDescription
t.AnyThe 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

NameTypeDescription
valuet.AnyThe value to deserialize into a Markup object.

Returns

TypeDescription
t.AnyA Markup object created from the input value.