Skip to content

add FormattedText component #29

@samuelcolvin

Description

@samuelcolvin

Defined as something like

class FormattedText(pydantic.BaseModel, extra='forbid'):
    text: str
    text_format: typing.Literal['bold', 'italic', 'underline', 'strikethrough'] | None = pydantic.Field(None, serialization_alias='textFormat')
    # TODO, use pydantic-extra-types Color?
    text_color: str | None = pydantic.Field(None, serialization_alias='textColor')
    background_color: str | None = pydantic.Field(None, serialization_alias='backgroundColor')
    type: typing.Literal['FormattedText'] = 'FormattedText'

The items in components like Button and Link become list[str | FormattedText | Link]. We might want too provide a few more components specifically for typography, like Bullets and Numbers

Two reasons to do this over relying on Markdown:

  1. Markdown is a relatively heave lazy module, that it would be nice not to have to load
  2. Markdown by it's definition is terrible for templating or user defined values - it's virtually impossible to escape. Providing these types would allow text to be defined which included uses values safely

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions