textoutpc.nodes – Node definitions#

class textoutpc.nodes.LinkTarget(value)#

Bases: str, Enum

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: BaseModel

Node rendering environment.

stream: TextIOBase#

Stream into which to write the result.

Link target.

host: str#

Host to include in URLs.

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.

get_program_url(program_id: str) → str#

Get the URL for a program.

Parameters:

program_id – Identifier of the program.

Returns:

Obtained URL.

get_email_url(email: str) → str#

Get the URL for an e-mail.

Parameters:

email –

class textoutpc.nodes.Node#

Bases: ABC, BaseModel

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: Node

Textual node in a textoutpc tree.

content: str#

Content.

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: Node

Container 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, MySecondNode or MyThirdNode;

  • There must be exactly 4 MySecondNode instances;

  • There must be 1 or 2 MyThirdNode instances.

children: tuple[Node, ...]#

Children.

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.BlockNode#

Bases: Node

Block-level node.

class textoutpc.nodes.BlockContainerNode(children: Iterable[Node] | None = None)#

Bases: ContainerNode, BlockNode

Block-level node that can contain both block and inline nodes.

children: tuple[Node, ...]#

Children.

class textoutpc.nodes.BlockInlineContainerNode(children: Iterable[Node] | None = None)#

Bases: ContainerNode, BlockNode

Block-level node that can contain inline nodes.

children: tuple[Node, ...]#

Children.

class textoutpc.nodes.InlineNode#

Bases: Node

Inline-level node.

class textoutpc.nodes.InlineContainerNode(children: Iterable[Node] | None = None)#

Bases: ContainerNode, InlineNode

Inline-level node that can contain other inline nodes.

children: tuple[Node, ...]#

Children.

class textoutpc.nodes.ParagraphNode(children: Iterable[Node] | None = None)#

Bases: BlockInlineContainerNode

Paragraph node.

render_html(env: NodeHTMLRenderEnvironment, /) → None#

Render the node as HTML.

Parameters:

env – Environment with all of the options.

children: tuple[Node, ...]#

Children.

class textoutpc.nodes.SmileyNode(*, name: str, style: str | None = None)#

Bases: InlineNode

Smiley node.

name: str#

Smiley name.

style: str | None#

Optional inline style.

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: InlineNode

E-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: InlineContainerNode

Reference to an HTTP URL.

children: tuple[Node, ...]#

Children.

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: BaseReferenceNode

Reference 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.