textoutpc.builtin.parsers – Built-in tag and parser definitions#

This module defines four parsers:

strict_inline_parser

Parser only defining tags and smileys used in inline contexts on PCv43, without extensions.

strict_parser

Parser only defining tags and smileys used in other contexts on PCv43, without extensions.

default_inline_parser

Parser defining tags and smileys used in inline contexts on PCv43, with extensions.

default_parser

Parser defining tags and smileys used in other contexts on PCv43, with extensions.

class textoutpc.builtin.parsers.TextTag(*, name: str, value: str | None, parser: Parser)#

Bases: Tag

Main tag for setting text formatting.

Example uses:

[b]Bold text.[/b]
[i]Italic text.[/i]
[u]Underlined text.[/u]
[strike]Striked text.[/strike]
[striked]Text strikes again.[/striked]
[font=arial]Arial text.[/font]
[arial]Arial text again.[/arial]
[blue]This will be in blue[/blue]
[color=blue]This as well[/color]
[color=rgb(255, 255, 255, 0.4)]BLACKNESS[/color]
[color=hsl(0, 100%, 0.5)]This will be red.[/color]

Also supports a hack used on Planète Casio for a while, which is a CSS injection, e.g.:

[color=brown; size: 16pt]Hello world![/color]

See the following sections for more information:

SIZE_ALLOWED: ClassVar[bool] = False#

Whether size changes are allowed.

BIG_FONT_SIZE: ClassVar[float] = 2.0#

Big font size, in points.

SMALL_FONT_SIZE: ClassVar[float] = 0.75#

Small font size, in points.

FONT_NAMES: ClassVar[dict[str, str]] = {'arial': 'Arial', 'comic': 'Comic MS', 'courier': 'Courier', 'haettenschweiler': 'Haettenschweiler', 'mono': 'monospace', 'monospace': 'monospace', 'tahoma': 'Tahoma'}#

Tag names to decode as fonts, and corresponding font family names.

COLOR_TAG_NAMES: ClassVar[set[str]] = {'blue', 'brown', 'gray', 'green', 'grey', 'maroon', 'purple', 'red', 'yellow'}#

Tag names to decode as colors.

strong: bool#

Whether the text should be set as strong or not.

italic: bool#

Whether the text should be set as italic or not.

underline: bool#

Whether the text should be underlined or not.

overline: bool#

Whether the text should be overlined or not.

strike: bool#

Whether the text should be striked or not.

font_name: FontName | None#

Name of the font to set to the text.

font_size: float | None#

Size of the font to set to the text.

font_size_unit: Literal['pt', 'em']#

Unit of the font size.

text_color: Color | None#

Color to set to the text.

back_color: Color | None#

Color to set to the text background.

validate() None#

Validate the name and value for this tag.

Raises:

TagValidationError – The name and value combination is invalid.

process(*, children: Sequence[Node]) Iterator[Node]#

Process the tag with children to build document nodes.

Parameters:

children – The children to process.

Returns:

The produced nodes.

class textoutpc.builtin.parsers.InlineCodeTag(*, name: str, value: str | None, parser: Parser)#

Bases: RawTag

Inline code tag.

This tag does not display a box, simply doesn’t evaluate the content and uses a monospace font.

Example uses:

`some inline code`
[inlinecode][b]The tags will be shown verbatim.[/b][/inlinecode]
[inlinecode][inlinecode][i]This also[/inlinecode] works![/inlinecode]

See Code blocks or spans for more information.

process(*, children: Sequence[Node]) Iterator[Node]#

Process the tag with children to build document nodes.

Parameters:

children – The children to process.

Returns:

The produced nodes.

class textoutpc.builtin.parsers.LinkTag(*, name: str, value: str | None, parser: Parser)#

Bases: Tag

Tag for linking to an external resource.

Example uses:

[url=https://example.org/hi]Go to example.org[/url]!
[url=/Fr/index.php][/url]
[url]https://random.org/randomize.php[/url]

See Hyperlinks for more information.

url: str | None#

The stored URL for the link tag.

validate() None#

Validate the name and value for this tag.

Raises:

TagValidationError – The name and value combination is invalid.

is_raw() bool#

Return whether the content of this tag should be read as raw.

Returns:

Whether the tag should be read as raw or not.

process(*, children: Sequence[Node]) Iterator[Node]#

Process the tag with children to build document nodes.

Parameters:

children – The children to process.

Returns:

The produced nodes.

process_url(url: str) str | None#

Process the URL.

Parameters:

url – The URL to process.

Returns:

The adapted URL, or None if the URL is invalid.

class textoutpc.builtin.parsers.ProfileTag(*, name: str, value: str | None, parser: Parser)#

Bases: RawTag

Tag for linking to a profile for the current site.

This tag was originally made for Planète Casio’s profiles. It adds a prefix to the content, and sets the value.

Example uses:

[profil]Cakeisalie5[/]

See Hyperlinks for more information.

validate() None#

Validate the name and value for this tag.

Raises:

TagValidationError – The name and value combination is invalid.

process(*, children: Sequence[Node]) Iterator[Node]#

Process the tag with children to build document nodes.

Parameters:

children – The children to process.

Returns:

The produced nodes.

class textoutpc.builtin.parsers.NoEvalTag(*, name: str, value: str | None, parser: Parser)#

Bases: RawTag

Tag for not evaluating content.

Same as above, except doesn’t apply any parent container or additional style.

Example uses:

[noeval][b]wow, and no need for monospace![/b][/noeval]
process(*, children: Sequence[Node]) Iterator[Node]#

Process the tag with children to build document nodes.

Parameters:

children – The children to process.

Returns:

The produced nodes.

class textoutpc.builtin.parsers.CalcTag(*, name: str, value: str | None, parser: Parser)#

Bases: RawTag

Tag for displaying a calculator icon.

Example use:

[calc]g90+e[/calc]
process(*, children: Sequence[Node]) Iterator[Node]#

Process the tag with children to build document nodes.

Parameters:

children – The children to process.

Returns:

The produced nodes.

class textoutpc.builtin.parsers.TextTagWithSizeAllowed(*, name: str, value: str | None, parser: Parser)#

Bases: TextTag

Extended text tag.

SIZE_ALLOWED: ClassVar[bool] = True#

Whether size changes are allowed.

back_color: Color | None#

Color to set to the text background.

font_name: FontName | None#

Name of the font to set to the text.

font_size: float | None#

Size of the font to set to the text.

font_size_unit: Literal['pt', 'em']#

Unit of the font size.

italic: bool#

Whether the text should be set as italic or not.

overline: bool#

Whether the text should be overlined or not.

strike: bool#

Whether the text should be striked or not.

strong: bool#

Whether the text should be set as strong or not.

text_color: Color | None#

Color to set to the text.

underline: bool#

Whether the text should be underlined or not.

class textoutpc.builtin.parsers.LabelTag(*, name: str, value: str | None, parser: Parser)#

Bases: Tag

Tag for defining an anchor at a point of the document.

Example uses:

[label=installation]Installation de tel logiciel... (no ending req.)
[label=compilation][/label] Compilation de tel logiciel...

See Labels and targets for more information.

validate() None#

Validate the name and value for this tag.

Raises:

TagValidationError – The name and value combination is invalid.

process(*, children: Sequence[Node]) Iterator[Node]#

Process the tag with children to build document nodes.

Parameters:

children – The children to process.

Returns:

The produced nodes.

class textoutpc.builtin.parsers.TargetTag(*, name: str, value: str | None, parser: Parser)#

Bases: Tag

Tag for linking to an anchor defined in the document.

Example uses:

[target=installation]Check out the installation manual[/target]!

See Labels and targets for more information.

validate() None#

Validate the name and value for this tag.

Raises:

TagValidationError – The name and value combination is invalid.

process(*, children: Sequence[Node]) Iterator[Node]#

Process the tag with children to build document nodes.

Parameters:

children – The children to process.

Returns:

The produced nodes.

class textoutpc.builtin.parsers.ImageTag(*, name: str, value: str | None, parser: Parser)#

Bases: RawTag

Tag for displaying an image.

Example uses:

[img]picture_url[/img]
[img=center]picture_url[/img]
[img=12x24]picture_url[/img]
[img=center|12x24]picture_url[/img]
[img=x24|right]picture_url[/img]

See Images for more information.

MODES: ClassVar[dict[str, tuple[Literal['center', 'left', 'right'] | None, bool]]] = {'center': ('center', False), 'centre': ('center', False), 'float': (None, True), 'float-center': ('center', True), 'float-centre': ('center', True), 'float-left': ('left', True), 'float-right': ('right', True), 'floating': (None, True), 'left': ('left', False), 'right': ('right', False)}#

The mapping between mode strings and alignment and floating.

width: int | None#

The width in pixels to display the image as, if provided.

height: int | None#

The height in pixels to display the image as, if provided.

alignment: Literal['center', 'left', 'right'] | None#

The alignment to display the image as, if provided.

floating: bool#

Whether the image should be floating or not.

validate() None#

Validate the name and value for this tag.

Raises:

TagValidationError – The name and value combination is invalid.

process(*, children: Sequence[Node]) Iterator[Node]#

Process the tag with children to build document nodes.

Parameters:

children – The children to process.

Returns:

The produced nodes.

build_node(*, url: str) ImageNode#

Build the image node.

Parameters:

url – The URL of the image node.

Returns:

Built node.

class textoutpc.builtin.parsers.AdminImageTag(*, name: str, value: str | None, parser: Parser)#

Bases: ImageTag

Tag for displaying an image from the administration.

This tag is special for Planète Casio, as it takes images from the administration’s (hence ad) image folder. It adds the folder’s prefix.

Example uses:

[adimg]some_picture.png[/img]
[adimg=center]some_picture.png[/img]
[adimg=12x24]some_picture.png[/img]
[adimg=center|12x24]some_picture.png[/img]
[adimg=x24|right]some_picture.png[/img]

See Images for more information.

build_node(*, url: str) ImageNode#

Build the image node.

Parameters:

url – The URL of the image node.

Returns:

Built node.

class textoutpc.builtin.parsers.AlignTag(*, name: str, value: str | None, parser: Parser)#

Bases: Tag

Main tag for aligning paragraphs.

Example uses:

[align=center]This text is centered horizontally.[/align]
[justify]This text is justified.[/justify]

See Alignment for more information.

ALIGN_KEYS: ClassVar[dict[str, Literal['center', 'left', 'right', 'justify']]] = {'center': 'center', 'centre': 'center', 'justify': 'justify', 'left': 'left', 'right': 'right'}#

Alignment keys recognized as tags or tag values.

kind: Literal['center', 'left', 'right', 'justify']#

Kind of alignment.

validate() None#

Validate the name and value for this tag.

Raises:

TagValidationError – The name and value combination is invalid.

process(*, children: Sequence[Node]) Iterator[Node]#

Process the tag with children to build document nodes.

Parameters:

children – The children to process.

Returns:

The produced nodes.

class textoutpc.builtin.parsers.QuoteTag(*, name: str, value: str | None, parser: Parser)#

Bases: Tag

Tag for presenting a quote.

Example uses:

[quote]Someone said that.[/]
[quote=Cakeisalie5]Ever realized that my name contained “Cake”?[/]

See Quotes for more information.

process(*, children: Sequence[Node]) Iterator[Node]#

Process the tag with children to build document nodes.

Parameters:

children – The children to process.

Returns:

The produced nodes.

class textoutpc.builtin.parsers.SpoilerTag(*, name: str, value: str | None, parser: Parser)#

Bases: Tag

Tag for hiding content at first glance.

This tag produces a node that requires the reader to click on a button to read its content. It can help to contain “secret” nodes, such as solutions, source code, or various other things.

Example uses:

[spoiler]This is hidden![/spoiler]

[spoiler=Y a quelque chose de caché !|Ah, bah en fait non :)]:E
And it's multiline, [big]and formatted[/big], as usual :D[/spoiler]

See Spoilers / Content Warnings for more information.

validate() None#

Validate the name and value for this tag.

Raises:

TagValidationError – The name and value combination is invalid.

process(*, children: Sequence[Node]) Iterator[Node]#

Process the tag with children to build document nodes.

Parameters:

children – The children to process.

Returns:

The produced nodes.

class textoutpc.builtin.parsers.CodeTag(*, name: str, value: str | None, parser: Parser)#

Bases: RawTag

Basic code tag, for displaying code.

Example uses:

[code]int main()
{
    printf("hello, world");
}[/code]

See Code blocks or spans for more information.

process(*, children: Sequence[Node]) Iterator[Node]#

Process the tag with children to build document nodes.

Parameters:

children – The children to process.

Returns:

The produced nodes.

class textoutpc.builtin.parsers.IndentTag(*, name: str, value: str | None, parser: Parser)#

Bases: RawTag

Indentation tag.

Example uses:

[indent]Indented text![/indent]
process(*, children: Sequence[Node]) Iterator[Node]#

Process the tag with children to build document nodes.

Parameters:

children – The children to process.

Returns:

The produced nodes.

class textoutpc.builtin.parsers.ProgressTag(*, name: str, value: str | None, parser: Parser)#

Bases: Tag

Tag for displaying a progress bar.

Example uses:

[progress=50]My great progress bar[/progress]
[progress=100][/progress]

See Progress bars for more information.

progress_value: int#

The progress value, between 0 and 100 included.

validate() None#

Validate the name and value for this tag.

Raises:

TagValidationError – The name and value combination is invalid.

process(*, children: Sequence[Node]) Iterator[Node]#

Process the tag with children to build document nodes.

Parameters:

children – The children to process.

Returns:

The produced nodes.

class textoutpc.builtin.parsers.ListTag(*, name: str, value: str | None, parser: Parser)#

Bases: Tag

Tag for creating a list.

Example uses:

[list]
    [li]hello[/li]
    [li]world[/li]
[/list]
type: ListType#

List type.

validate() None#

Validate the name and value for this tag.

Raises:

TagValidationError – The name and value combination is invalid.

process(*, children: Sequence[Node]) Iterator[Node]#

Process the tag with children to build document nodes.

Parameters:

children – The children to process.

Returns:

The produced nodes.

name: str#

Name of the tag.

This is surrounded by brackets in case of a normal tag, or the character directly if a special character has been used, e.g. backquotes.

parser: Parser#

Parser for which the tag has been instanciated.

This can be used to parse the value or any subcontent as BBCode as well.

value: str | None#

Value passed to the tag, e.g. [tag=my_value].

Set to None if no value has been passed, e.g. [tag].

class textoutpc.builtin.parsers.ListItemTag(*, name: str, value: str | None, parser: Parser)#

Bases: Tag

Tag for creating a list element.

See ListTag for more information.

CLOSE_IF_OPENED_WITHIN_ITSELF: ClassVar[bool] = True#

Whether to close and re-open the tag, if opened within itself.

This is for tags such as [li] not to have to be closed if placed within themselves, e.g.:

[list]
[li]Bullet 1
[li]Bullet 2
[/list]
process(*, children: Sequence[Node]) Iterator[Node]#

Process the tag with children to build document nodes.

Parameters:

children – The children to process.

Returns:

The produced nodes.

name: str#

Name of the tag.

This is surrounded by brackets in case of a normal tag, or the character directly if a special character has been used, e.g. backquotes.

parser: Parser#

Parser for which the tag has been instanciated.

This can be used to parse the value or any subcontent as BBCode as well.

value: str | None#

Value passed to the tag, e.g. [tag=my_value].

Set to None if no value has been passed, e.g. [tag].

class textoutpc.builtin.parsers.TableTag(*, name: str, value: str | None, parser: Parser)#

Bases: Tag

Tag for creating a table.

An example use of the base elements is the following:

[table]
    [tr][th]Col 1[/th][th]Col 2[/th][/tr]
    [tr][td]Data 1_1[/td][td]Data 1_2[/td][/tr]
    [tr][td]Data 2_1[/td][td]Data 2_2[/td][/tr]
[/table]

An example use with separators is the following:

[table]
    [tr=|]Col 1 | Col 2[/tr]
    [tr=|]Data 1_1 | Data 1_2[/tr]
    [tr=|]Data 2_1 | Data 2_2[/tr]
[/table]
process(*, children: Sequence[Node]) Iterator[Node]#

Process the tag with children to build document nodes.

Parameters:

children – The children to process.

Returns:

The produced nodes.

name: str#

Name of the tag.

This is surrounded by brackets in case of a normal tag, or the character directly if a special character has been used, e.g. backquotes.

parser: Parser#

Parser for which the tag has been instanciated.

This can be used to parse the value or any subcontent as BBCode as well.

value: str | None#

Value passed to the tag, e.g. [tag=my_value].

Set to None if no value has been passed, e.g. [tag].

class textoutpc.builtin.parsers.TableRowTag(*, name: str, value: str | None, parser: Parser)#

Bases: Tag

Tag for creating a table row.

See TableTag for more information.

separator: str | None = None#
validate() None#

Validate the name and value for this tag.

Raises:

TagValidationError – The name and value combination is invalid.

is_raw() bool#

Return whether the content of this tag should be read as raw.

Returns:

Whether the tag should be read as raw or not.

process(*, children: Sequence[Node]) Iterator[Node]#

Process the tag with children to build document nodes.

Parameters:

children – The children to process.

Returns:

The produced nodes.

name: str#

Name of the tag.

This is surrounded by brackets in case of a normal tag, or the character directly if a special character has been used, e.g. backquotes.

parser: Parser#

Parser for which the tag has been instanciated.

This can be used to parse the value or any subcontent as BBCode as well.

value: str | None#

Value passed to the tag, e.g. [tag=my_value].

Set to None if no value has been passed, e.g. [tag].

class textoutpc.builtin.parsers.TableHeaderTag(*, name: str, value: str | None, parser: Parser)#

Bases: Tag

Tag for creating a table header (cell).

See TableTag for more information.

process(*, children: Sequence[Node]) Iterator[Node]#

Process the tag with children to build document nodes.

Parameters:

children – The children to process.

Returns:

The produced nodes.

name: str#

Name of the tag.

This is surrounded by brackets in case of a normal tag, or the character directly if a special character has been used, e.g. backquotes.

parser: Parser#

Parser for which the tag has been instanciated.

This can be used to parse the value or any subcontent as BBCode as well.

value: str | None#

Value passed to the tag, e.g. [tag=my_value].

Set to None if no value has been passed, e.g. [tag].

class textoutpc.builtin.parsers.TableCellTag(*, name: str, value: str | None, parser: Parser)#

Bases: Tag

Tag for creating a table cell.

See TableTag for more information.

process(*, children: Sequence[Node]) Iterator[Node]#

Process the tag with children to build document nodes.

Parameters:

children – The children to process.

Returns:

The produced nodes.

name: str#

Name of the tag.

This is surrounded by brackets in case of a normal tag, or the character directly if a special character has been used, e.g. backquotes.

parser: Parser#

Parser for which the tag has been instanciated.

This can be used to parse the value or any subcontent as BBCode as well.

value: str | None#

Value passed to the tag, e.g. [tag=my_value].

Set to None if no value has been passed, e.g. [tag].

class textoutpc.builtin.parsers.VideoTag(*, name: str, value: str | None, parser: Parser)#

Bases: RawTag

Tag for displaying a video player.

Example uses:

[video]https://www.youtube.com/watch?v=yDp3cB5fHXQ[/video]
[video tiny]https://youtu.be/0twDETh6QaI[/video tiny]
format: Literal['normal', 'tiny']#

Format.

width: int | None#

Explicit width, if specified.

validate() None#

Validate the name and value for this tag.

Raises:

TagValidationError – The name and value combination is invalid.

process(*, children: Sequence[Node]) Iterator[Node]#

Process the tag with children to build document nodes.

Parameters:

children – The children to process.

Returns:

The produced nodes.

class textoutpc.builtin.parsers.TopicTag(*, name: str, value: str | None, parser: Parser)#

Bases: LinkTag

Tag for linking topics for the current site.

Originally made for Planète Casio’s forum topics.

Example uses:

[topic]234[/]

See Hyperlinks for more information.

validate() None#

Validate the name and value for this tag.

Raises:

TagValidationError – The name and value combination is invalid.

process(*, children: Sequence[Node]) Iterator[Node]#

Process the tag with children to build document nodes.

Parameters:

children – The children to process.

Returns:

The produced nodes.

class textoutpc.builtin.parsers.TutorialTag(*, name: str, value: str | None, parser: Parser)#

Bases: LinkTag

Tag for linking tutorials for the current site.

Originally made for Planète Casio’s tutorials.

Example uses:

[tutorial]71[/]

See Hyperlinks for more information.

validate() None#

Validate the name and value for this tag.

Raises:

TagValidationError – The name and value combination is invalid.

process(*, children: Sequence[Node]) Iterator[Node]#

Process the tag with children to build document nodes.

Parameters:

children – The children to process.

Returns:

The produced nodes.

class textoutpc.builtin.parsers.ProgramTag(*, name: str, value: str | None, parser: Parser)#

Bases: LinkTag

Tag for linking programs for the current site.

Originally made for Planète Casio’s programs.

Example uses:

[program]3598[/]

See Hyperlinks for more information.

validate() None#

Validate the name and value for this tag.

Raises:

TagValidationError – The name and value combination is invalid.

process(*, children: Sequence[Node]) Iterator[Node]#

Process the tag with children to build document nodes.

Parameters:

children – The children to process.

Returns:

The produced nodes.

class textoutpc.builtin.parsers.RotTag(*, name: str, value: str | None, parser: Parser)#

Bases: RawTag

Tag for un-rot13-ing raw text and returning such text.

Example uses:

[rot=13]obawbhe[/rot]
[rot13]Obawbhe[/rot13]
general_tag_names = ('[rot]',)#

The accepted tag names for this tag, with an expected value.

embedded_tag_pattern = re.compile('\\[rot0*?([0-9]|1[0-9]|2[0-5])\\]', re.IGNORECASE)#

The compiled pattern for tag names with embedded rot values.

validate() None#

Validate the name and value for this tag.

Raises:

TagValidationError – The name and value combination is invalid.

process(*, children: Sequence[Node]) Iterator[Node]#

Process the tag with children to build document nodes.

Parameters:

children – The children to process.

Returns:

The produced nodes.

class textoutpc.builtin.parsers.TitleTag(*, name: str, value: str | None, parser: Parser)#

Bases: RawTag

Title tag.

Example uses:

[title]Example title[/]

See Titles and subtitles for more information.

validate() None#

Validate the name and value for this tag.

Raises:

TagValidationError – The name and value combination is invalid.

process(*, children: Sequence[Node]) Iterator[Node]#

Process the tag with children to build document nodes.

Parameters:

children – The children to process.

Returns:

The produced nodes.

class textoutpc.builtin.parsers.SubtitleTag(*, name: str, value: str | None, parser: Parser)#

Bases: RawTag

Subtitle tag.

Example uses:

[subtitle]Example subtitle[/]

See Titles and subtitles for more information.

validate() None#

Validate the name and value for this tag.

Raises:

TagValidationError – The name and value combination is invalid.

process(*, children: Sequence[Node]) Iterator[Node]#

Process the tag with children to build document nodes.

Parameters:

children – The children to process.

Returns:

The produced nodes.

class textoutpc.builtin.parsers.YoutubeTag(*, name: str, value: str | None, parser: Parser)#

Bases: RawTag

Tag for displaying a YouTube video player.

Example uses:

[youtube]yDp3cB5fHXQ[/youtube]
validate() None#

Validate the name and value for this tag.

Raises:

TagValidationError – The name and value combination is invalid.

process(*, children: Sequence[Node]) Iterator[Node]#

Process the tag with children to build document nodes.

Parameters:

children – The children to process.

Returns:

The produced nodes.