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
keystring = mThe 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

NameTypeDescription
valuet.AnyThe object to inspect for Markup API compatibility.

Returns

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

NameTypeDescription
valuet.AnyThe markup-compatible object to be serialized.

Returns

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

NameTypeDescription
valuet.AnyThe serialized markup string to be converted back into a Markup object.

Returns

TypeDescription
t.AnyAn instance of markupsafe.Markup containing the deserialized content.