OpenQuizz
Une application de gestion des contenus pédagogiques
Markup Class Reference
Inheritance diagram for Markup:
Collaboration diagram for Markup:

Public Member Functions

"Markup" __new__ (cls, t.Any base="", t.Optional[str] encoding=None, str errors="strict")
 
"Markup" __html__ (self)
 
"Markup" __add__ (self, t.Union[str, "HasHTML"] other)
 
"Markup" __radd__ (self, t.Union[str, "HasHTML"] other)
 
"Markup" __mul__ (self, int num)
 
"Markup" __mod__ (self, t.Any arg)
 
str __repr__ (self)
 
"Markup" join (self, t.Iterable[t.Union[str, "HasHTML"]] seq)
 
t.List["Markup"] split (self, t.Optional[str] sep=None, int maxsplit=-1)
 
t.List["Markup"] rsplit (self, t.Optional[str] sep=None, int maxsplit=-1)
 
t.List["Markup"] splitlines (self, bool keepends=False)
 
str unescape (self)
 
str striptags (self)
 
"Markup" escape (cls, t.Any s)
 
t.Tuple["Markup", "Markup", "Markup"] partition (self, str sep)
 
t.Tuple["Markup", "Markup", "Markup"] rpartition (self, str sep)
 
"Markup" format (self, *t.Any args, **t.Any kwargs)
 
"Markup" __html_format__ (self, str format_spec)
 

Detailed Description

A string that is ready to be safely inserted into an HTML or XML
document, either because it was escaped or because it was marked
safe.

Passing an object to the constructor converts it to text and wraps
it to mark it safe without escaping. To escape the text, use the
:meth:`escape` class method instead.

>>> Markup("Hello, <em>World</em>!")
Markup('Hello, <em>World</em>!')
>>> Markup(42)
Markup('42')
>>> Markup.escape("Hello, <em>World</em>!")
Markup('Hello &lt;em&gt;World&lt;/em&gt;!')

This implements the ``__html__()`` interface that some frameworks
use. Passing an object that implements ``__html__()`` will wrap the
output of that method, marking it safe.

>>> class Foo:
...     def __html__(self):
...         return '<a href="/foo">foo</a>'
...
>>> Markup(Foo())
Markup('<a href="/foo">foo</a>')

This is a subclass of :class:`str`. It has the same methods, but
escapes their arguments and returns a ``Markup`` instance.

>>> Markup("<em>%s</em>") % ("foo & bar",)
Markup('<em>foo &amp; bar</em>')
>>> Markup("<em>Hello</em> ") + "<foo>"
Markup('<em>Hello</em> &lt;foo&gt;')

Member Function Documentation

◆ __add__()

"Markup" __add__ (   self,
t.Union[str, "HasHTML"]  other 
)

◆ __html__()

"Markup" __html__ (   self)

◆ __html_format__()

"Markup" __html_format__ (   self,
str  format_spec 
)

◆ __mod__()

"Markup" __mod__ (   self,
t.Any  arg 
)

◆ __mul__()

"Markup" __mul__ (   self,
int  num 
)

◆ __new__()

"Markup" __new__ (   cls,
t.Any   base = "",
t.Optional[str]   encoding = None,
str   errors = "strict" 
)

◆ __radd__()

"Markup" __radd__ (   self,
t.Union[str, "HasHTML"]  other 
)

◆ __repr__()

str __repr__ (   self)

◆ escape()

"Markup" escape (   cls,
t.Any  s 
)
Escape a string. Calls :func:`escape` and ensures that for
subclasses the correct type is returned.

◆ format()

"Markup" format (   self,
*t.Any  args,
**t.Any  kwargs 
)

◆ join()

"Markup" join (   self,
t.Iterable[t.Union[str, "HasHTML"]]  seq 
)

◆ partition()

t.Tuple["Markup", "Markup", "Markup"] partition (   self,
str  sep 
)

◆ rpartition()

t.Tuple["Markup", "Markup", "Markup"] rpartition (   self,
str  sep 
)

◆ rsplit()

t.List["Markup"] rsplit (   self,
t.Optional[str]   sep = None,
int   maxsplit = -1 
)

◆ split()

t.List["Markup"] split (   self,
t.Optional[str]   sep = None,
int   maxsplit = -1 
)

◆ splitlines()

t.List["Markup"] splitlines (   self,
bool   keepends = False 
)

◆ striptags()

str striptags (   self)
:meth:`unescape` the markup, remove tags, and normalize
whitespace to single spaces.

>>> Markup("Main &raquo;\t<em>About</em>").striptags()
'Main » About'

◆ unescape()

str unescape (   self)
Convert escaped markup back into a text string. This replaces
HTML entities with the characters they represent.

>>> Markup("Main &raquo; <em>About</em>").unescape()
'Main » <em>About</em>'

The documentation for this class was generated from the following file: