textoutpc.nodes – Node definitions#
- class textoutpc.nodes.LinkTarget(value)#
-
Target to add to links.
- SELF = 'self'#
Whether the target is the current window and tab.
- BLANK = 'blank'#
Whether the target is a different window / tab.
In this case,
rel="noopener"is also added, in order for the new window / tab to have no access to the current window / tab.
- class textoutpc.nodes.NodeHTMLRenderEnvironment(*, stream: TextIOBase, link_target: LinkTarget = LinkTarget.BLANK, host: str = 'https://www.planet-casio.com/')#
Bases:
BaseModelNode rendering environment.
- stream: TextIOBase#
Stream into which to write the result.
- link_target: LinkTarget#
Link target.
- escape(content: str, /) str#
Escape HTML entities in the provided content.
- Parameters:
content – Content to escape.
- Returns:
Escaped content.
- write(content: str, /, *, escape: bool = False) None#
Write HTML contents to the stream.
- Parameters:
content – Content to write.
escape – Whether to escape the result.
- write_start_tag(name: str, /, *, cls: str | Sequence[str] | None = None, **kwargs: str | None) None#
Write an HTML start tag.
- Parameters:
name – Name of the tag to start, e.g. “div”.
cls – CSS class or classes for the tag.
- tag(name: str, /, cls: str | Sequence[str] | None = None, **kwargs: str | None) Iterator[None]#
Write a start and end tag.
- Parameters:
name – Name of the tag to open and close.
cls – CSS class or classes for the start tag.
kwargs – Keyword parameters for the start tag.
- get_smiley_url(name: str) str#
Get the URL for a smiley.
- Parameters:
name – Name of the smiley.
- Returns:
Obtained URL.
- get_calculator_icon_url(name: str) str#
Get the URL for a calculator’s icon.
- Parameters:
name – Name of the calculator.
- Returns:
Obtained URL.
- get_staff_image_url(path: str) str#
Get the URL for a staff image.
- Parameters:
path – Relative path to the staff image.
- Returns:
Obtained URL.
- get_user_profile_url(username: str) str#
Get the URL for a user profile.
- Parameters:
username – Name of the user.
- Returns:
Obtained URL.
- get_topic_url(topic_id: str) str#
Get the URL for a topic.
- Parameters:
topic_id – Identifier of the topic.
- Returns:
Obtained URL.
- get_tutorial_url(tutorial_id: str) str#
Get the URL for a tutorial.
- Parameters:
tutorial_id – Identifier of the topic.
- Returns:
Obtained URL.
- class textoutpc.nodes.Node#
-
Base node in a textoutpc tree.
- abstract render_html(env: NodeHTMLRenderEnvironment, /) None#
Render the node as HTML.
- Parameters:
env – Environment with all of the options.
- class textoutpc.nodes.TextNode(content: str | None = None)#
Bases:
NodeTextual node in a textoutpc tree.
- render_html(env: NodeHTMLRenderEnvironment, /) None#
Render the node as HTML.
- Parameters:
env – Environment with all of the options.
- class textoutpc.nodes.ContainerNode(children: Iterable[Node] | None = None)#
Bases:
NodeContainer node in a textoutpc tree.
- AUTHORIZED_CHILDREN_TYPES: ClassVar[Sequence[type[Node] | tuple[type[Node], int | range]] | None] = None#
Authorized children types.
This is a sequence of either the type to check, or the authorized count of this type of node. Here’s an example use of this property:
class MyContainerNode(ContainerNode): AUTHORIZED_CHILDREN_TYPES = ( MyFirstNode, (MySecondNode, 4), (MyThirdNode, range(1, 3)), )
This example presents the following constraints:
Children are either instances of
MyFirstNode,MySecondNodeorMyThirdNode;There must be exactly 4
MySecondNodeinstances;There must be 1 or 2
MyThirdNodeinstances.
- find_children(type_or_types: tuple[type, ...] | type | None = None, /, *, exclude_type: type | None = None, exclude_types: tuple[type, ...] | None = None) Iterator[Node]#
Find children with the provided filters.
- Parameters:
type_or_types – Only count children of the provided type or types.
exclude_type – Exclude the provided type in the count.
exclude_types – Exclude the provided types in the count.
- Returns:
Children for the provided filters.
- find_child(type_or_types: tuple[type, ...] | type | None = None, /, *, exclude_type: type | None = None, exclude_types: tuple[type, ...] | None = None, optional: Literal[True]) Node | None#
- find_child(type_or_types: tuple[type, ...] | type | None = None, /, *, exclude_type: type | None = None, exclude_types: tuple[type, ...] | None = None, optional: Literal[False] = False) Node
Find a single child with the provided filters.
- Parameters:
type_or_types – Only count children of the provided type or types.
exclude_type – Exclude the provided type in the count.
exclude_types – Exclude the provided types in the count.
- Returns:
Child for the provided filters.
- Raises:
- count_children(type_or_types: tuple[type, ...] | type | None = None, /, *, exclude_type: type | None = None, exclude_types: tuple[type, ...] | None = None) int#
Count children of a provided type.
- Parameters:
type_or_types – Only count children of the provided type or types.
exclude_type – Exclude the provided type in the count.
exclude_types – Exclude the provided types in the count.
- Returns:
Count of children for the provided filters.
- render_children_html(env: NodeHTMLRenderEnvironment, /) None#
Render the node’s children as HTML.
- Parameters:
env – Environment with all of the options.
- class textoutpc.nodes.BlockContainerNode(children: Iterable[Node] | None = None)#
Bases:
ContainerNode,BlockNodeBlock-level node that can contain both block and inline nodes.
- class textoutpc.nodes.BlockInlineContainerNode(children: Iterable[Node] | None = None)#
Bases:
ContainerNode,BlockNodeBlock-level node that can contain inline nodes.
- class textoutpc.nodes.InlineContainerNode(children: Iterable[Node] | None = None)#
Bases:
ContainerNode,InlineNodeInline-level node that can contain other inline nodes.
- class textoutpc.nodes.ParagraphNode(children: Iterable[Node] | None = None)#
Bases:
BlockInlineContainerNodeParagraph node.
- render_html(env: NodeHTMLRenderEnvironment, /) None#
Render the node as HTML.
- Parameters:
env – Environment with all of the options.
- class textoutpc.nodes.SmileyNode(*, name: str, style: str | None = None)#
Bases:
InlineNodeSmiley node.
- render_html(env: NodeHTMLRenderEnvironment, /) None#
Render the node as HTML.
- Parameters:
env – Environment with all of the options.
- class textoutpc.nodes.EmailAddressNode(*, email_address: str)#
Bases:
InlineNodeE-mail address node.
- email_address: Annotated[str, StringConstraints(pattern='^[^@]+@[^@]+$')]#
E-mail address.
- render_html(env: NodeHTMLRenderEnvironment, /) None#
Render the node as HTML.
- Parameters:
env – Environment with all of the options.
- class textoutpc.nodes.BaseReferenceNode(children: Iterable[Node] | None = None)#
Bases:
InlineContainerNodeReference to an HTTP URL.
- abstract build_html_url(env: NodeHTMLRenderEnvironment, /) str#
Build the URL for HTML output.
- Parameters:
env – Environment with all of the options.
- Returns:
Obtained URL.
- render_html(env: NodeHTMLRenderEnvironment, /) None#
Render the node as HTML.
- Parameters:
env – Environment with all of the options.
- class textoutpc.nodes.ReferenceNode(children: Iterable[Node] | None = None, *, url: AnyUrl)#
Bases:
BaseReferenceNodeReference to an HTTP URL.
- url: AnyUrl#
URL to reference.
- build_html_url(env: NodeHTMLRenderEnvironment, /) str#
Build the URL for HTML output.
- Parameters:
env – Environment with all of the options.
- Returns:
Obtained URL.