textoutpc.parser – Parser definition#
- class textoutpc.parser.Parser(name: str | None = None, *, tags: dict[str, type[textoutpc.tags.Tag]] = <factory>, smileys: dict[str, textoutpc.parser.SmileyData] = <factory>)#
- Bases: - BaseModel- Parser definition. - tags: Annotated[dict[str, type[Tag]], Field(default_factory=dict)]#
- Currently registered tags. 
 - smileys: Annotated[dict[str, SmileyData], Field(default_factory=dict)]#
- Currently registered emojis. 
 - copy(name: str | None = None, /) ParserT#
- Copy as another parser. - Parameters:
- name – Name as which to copy the parser. 
- Returns:
- Copied parser. 
 
 - add_smiley(smiley: str, /, *, name: str, style: str | None = None) None#
- Register an emoji. - Parameters:
- smiley – Smiley to match. 
- name – Name to match the smiley as, or include in the URL. 
- style – Optional HTML inline style to add. 
 
 
 - add_tag(tag: type[textoutpc.tags.Tag], name: str, /, *other_names: str, replace: bool = False) None#
- Register a tag as one or more names. - Parameters:
- tag – Tag class to register the tag as. 
- name – First name to register the tag as. 
- other_names – Other names to register the tag as. 
- replace – If any of the provided names is already registered, whether to replace the tag silently, or raise an exception. 
 
- Raises:
- AlreadyRegistered – At least one of the provided names was already registered to another tag. 
 
 - tag(name: str, /, *other_names: str, replace: bool = False) Callable[[type[TagT]], type[TagT]]#
- Register a tag as one or more names (decorator syntax). - Parameters:
- name – First name to register the tag as. 
- other_names – Other names to register the tag as. 
- replace – If any of the provided names is already registered, whether to replace the tag silently, or raise an exception. 
 
- Returns:
- Callable to pass the tag type to. 
- Raises:
- AlreadyRegistered – At least one of the provided names was already registered to another tag.