#13651·slint

StyledText should support declarative `Text` children instead of a Markdown-first API

Author: cnlancehuCreated Sep 25, 2026Updated Sep 28, 2026
Labelsa:textneed triaging

Feature Description

StyledText is a UI primitive for styled text, but its API currently centers on @markdown(). Even basic styling requires HTML-like markup: <u> for underline and <font color="..."> for text color.

For example, displaying text in different colors requires encoding styling into a string:

slint
StyledText {
    text: @markdown(
        "Hello <font color=\"red\">red</font> "
        "<font color=\"green\">green</font>"
    );
}

This feels backwards for a declarative UI language. I would like to express the same content using native Slint properties:

slint
StyledText {
    Text {
        text: "Hello ";
    }

    Text {
        text: "red";
        color: red;
    }

    Text {
        text: " green";
        color: green;
    }
}

The children's contents should be concatenated and laid out as one paragraph.

StyledText itself can naturally represent a paragraph. Multiple paragraphs could simply use multiple StyledText elements:

slint
// Paragraph 1
StyledText {
    text-indent: 16px;

    Text {
        text: "First paragraph, ";
    }

    Text {
        text: "with highlighted text.";
        color: red;
    }
}

// Paragraph 2
StyledText {
    text-indent: 16px;

    Text {
        text: "Second paragraph.";
    }
}

This would follow the same principle as Path, which already exposes its structure declaratively through children such as MoveTo, LineTo, and Close.

A close match for the existing internal representation

Slint already has an internal representation that fits this proposal.

In internal/core/styled_text.rs, StyledText stores a collection of StyledTextParagraphs. In internal/common/styled_text.rs, each paragraph contains:

  • raw text;
  • formatting ranges, each associating a text range with a style;
  • link ranges.

Markdown is parsed into this representation. Declarative Text children could produce the same representation directly: concatenate their text and apply each child's styling to the corresponding range.

For example, "Hello " followed by a red "world" would produce a paragraph containing "Hello world", with a formatting range covering "world".

There should be no need to serialize this information into Markdown or HTML-like markup just to parse it back into the model Slint already uses.

Images highlight the limitations of a Markdown-first API

An existing issue tracks support for additional Markdown elements, including headings, images, tables, block quotes, and math. Images illustrate the API problem particularly well.

Introducing images through ![alt](image.png) or <img> requires a mapping from Markdown or HTML to Slint's Image properties. Source, width, height, image-fit, clipping, and alignment all need a representation in that mapping. Whenever an application needs another property, the mapping must expand.

Slint already has an Image element with native properties. For separate image blocks, applications can compose Image and StyledText using normal Slint elements. If inline non-text content is supported in the future, a declarative API would also leave room for an actual Image {} child.

There is a broader question here: if StyledText grows to include images, video thumbnails, math, panels, and other content supported by Markdown, is it still a styled-text primitive, or has it become a general document renderer?

A Markdown-first API starts with limited customization. Expanding it then means building an increasingly complex Markdown/HTML-to-Slint mapping—effectively a second, restricted UI language.

Markdown parsing should be optional

The current design also affects dependencies.

i-slint-common defines a separate markdown feature that enables dependencies including pulldown-cmark and htmlparser. However:

  • i-slint-core enables i-slint-common/markdown through its std feature;
  • i-slint-compiler enables it directly.

As a result, a normal std Slint application cannot opt out of Markdown parsing support, even if it never uses @markdown() or StyledText::from_markdown().

A native declarative API would provide a foundation for separating styled text from Markdown parsing. Both declarative children and an optional Markdown parser could produce the same StyledTextParagraph representation.

Markdown should remain a supported input format, without defining how styled text must be authored or becoming a required dependency of the styled-text primitive.

Proposed API

slint
StyledText {
    Text {
        text: "Normal ";
    }

    Text {
        text: "bold";
        font-weight: 700;
    }

    Text {
        text: " red";
        color: red;
    }
}

All children would form a single paragraph, with styling expressed through Slint properties.

This would closely match the existing internal representation, follow Slint's declarative design, and keep StyledText focused on styled text. Markdown could remain a convenient, optional way to produce that content.

Product Impact

Nice to have