Rich text
rich_text ¶
Utilities for working with plain & rich texts in Notion.
RTBO_co = TypeVar('RTBO_co', bound=(objs.RichTextBaseObject), default=(objs.RichTextBaseObject), covariant=True) module-attribute ¶
Math(expression: str, *, bold: bool = False, italic: bool = False, strikethrough: bool = False, code: bool = False, underline: bool = False, color: Color = Color.DEFAULT, href: str | None = None) ¶
An inline equation object.
A LaTeX equation in inline mode, e.g. $ \mathrm{E=mc^2} $, but without the $ signs.
Note
Only used internally. Use the math function instead, to create proper Text object.
Mention(target: User | Page | Database | CustomEmoji | objs.DateTimeOrRange, *, bold: bool = False, italic: bool = False, strikethrough: bool = False, code: bool = False, underline: bool = False, color: Color = Color.DEFAULT) ¶
RichText(text: str, *, bold: bool = False, italic: bool = False, strikethrough: bool = False, code: bool = False, underline: bool = False, color: Color | BGColor | None = None, href: str | None = None) ¶
A RichText object defining a formatted text fragment.
Note
Only used internally. Use Text instead or the text function (recommended).
RichTextBase(*args: Any, href: str | None, **kwargs: Any) ¶
Super class for text, equation and mentions of various kinds.
is_equation: bool property ¶
Return True if this rich text object is a Math (equation).
is_mention: bool property ¶
Return True if this rich text object is a Mention.
is_text: bool property ¶
Return True if this rich text object is a Text.
plain_text: str property ¶
Return the plain text representation of this rich text object.
Text(text: str) ¶
User-facing class holding several RichTextsBase objects.
Rather use the constructor function text to create a Text object from a normal string with formatting.
mentions: tuple[Mention, ...] property ¶
Return all mentions in the text.
obj_ref: list[objs.RichTextBaseObject] property ¶
rich_texts: tuple[RichTextBase, ...] property ¶
Return the rich texts as immutable tuple.
__add__(other: str) -> Text ¶
__eq__(other: object) -> bool ¶
__hash__() -> int ¶
from_markdown(text: str) -> Text classmethod ¶
Create RichTextList by parsing the markdown.
from_plain_text(text: str) -> Text classmethod ¶
Create RichTextList from plain text.
This method is a more explicit alias for the default constructor.
to_html() -> str ¶
Return rich text as HTML.
to_markdown() -> str ¶
Convert the list of RichText objects to markdown.
to_plain_text() -> str ¶
Return rich text as plain text
This method is a more explicit variant then just using the object.
wrap_obj_ref(obj_refs: list[objs.RichTextBaseObject] | None) -> Self classmethod ¶
camel_case(string: str) -> str ¶
Make a Python identifier in CamelCase.
Attention: This may result in an empty string and a CamelCase sting will be capitalized!
chunky(text: str, length: int = MAX_TEXT_OBJECT_SIZE) -> Iterator[str] ¶
Break the given text into chunks of at most length size.
decapitalize(string: str) -> str ¶
Inverse of capitalize.
html_img(url: str, size: float) -> str ¶
Create a img tag in HTML.
is_url(string: str) -> bool ¶
Check if a string is a valid URL.
join(texts: Sequence[str], *, delim: str = ' ') -> Text ¶
Join multiple str objects, including Text, into a single Text object with a given delimeter.
math(expression: str, *, bold: bool = False, italic: bool = False, strikethrough: bool = False, code: bool = False, underline: bool = False, color: Color = Color.DEFAULT) -> Text ¶
Create a Text that holds a formula.
mention(target: User | Page | Database | CustomEmoji | objs.DateTimeOrRange, *, bold: bool = False, italic: bool = False, strikethrough: bool = False, code: bool = False, underline: bool = False, color: Color = Color.DEFAULT) -> Text ¶
Create a Text that mentions another object.
python_identifier(string: str) -> str ¶
Make a valid Python identifier.
This will remove any leading characters that are not valid and change all invalid interior sequences to underscore.
Attention: This may result in an empty string!
snake_case(string: str) -> str ¶
Make a Python identifier in snake_case.
Attention: This may result in an empty string!
text(text: str, *, bold: bool = False, italic: bool = False, strikethrough: bool = False, code: bool = False, underline: bool = False, color: Color | BGColor | None = None, href: str | None = None) -> Text ¶
Create a rich text Text object from a normal string with formatting.
Note
With the color parameter the font color or the background color can be set. Unfortunately Notion's API does not allow to set both at the same time like in the Notion UI.
Warning
If a Text object is passed, the original formatting will be lost!