Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add FormattedText component #29

Open
samuelcolvin opened this issue Dec 1, 2023 · 0 comments
Open

add FormattedText component #29

samuelcolvin opened this issue Dec 1, 2023 · 0 comments
Labels
Milestone

Comments

@samuelcolvin
Copy link
Member

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants