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 as markup.

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 the markup-compatible object into a plain string by invoking its html method for JSON serialization.

Parameters​

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

Returns​

TypeDescription
t.AnyThe string representation of the markup content.

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.