diff --git a/cspell.json b/cspell.json index 8f3fcf32ab4..298817b1eb3 100644 --- a/cspell.json +++ b/cspell.json @@ -90,7 +90,9 @@ "tschüß", "TSCHÜSS", "ὈΔΥΣΣΕΎΣ", - "ὀδυσσεύς" + "ὀδυσσεύς", + "commonmark", + "strikethroughs" ], } ], diff --git a/docs/astro/astro.config.mjs b/docs/astro/astro.config.mjs index 04e25a7771d..7686614232b 100644 --- a/docs/astro/astro.config.mjs +++ b/docs/astro/astro.config.mjs @@ -217,6 +217,10 @@ export default defineConfig({ label: "Timer", slug: "reference/timer", }, + { + label: "Styled Text", + slug: "reference/styled-text", + }, ], }, { diff --git a/docs/astro/src/content/docs/reference/styled-text.mdx b/docs/astro/src/content/docs/reference/styled-text.mdx new file mode 100644 index 00000000000..272d3b0c6f3 --- /dev/null +++ b/docs/astro/src/content/docs/reference/styled-text.mdx @@ -0,0 +1,57 @@ +--- +title: Styled Text +description: Styled Text +--- + +import CodeSnippetMD from "@slint/common-files/src/components/CodeSnippetMD.astro"; + +The `StyledText` type renders text with various styling and interactive properties, such as bolded, underlined and colored sections as well as HTTP links. It is based on a subset of the [commonmark](https://commonmark.org/) spec. + + +```slint +export component Example inherits Window { + width: 200px; + height: 200px; + StyledText { + text: @markdown("This is a piece of Styled Text\nwith a red value inserted: {}", 55); + } +} +``` + + + +## Features + +Styled Text supports the following features: + +Feature | Method +---------------|------- +Italics | Builtin +Strikethroughs | Builtin +Inline code | Builtin +Links | Builtin +Ordered and unordered lists | Builtin +Underlines | `` HTML tag +Text Colors |`` HTML tags + +### Currently Unsupported + + +Feature | +-----------------| +Headings | +Images | +Tables | +Block Quotes | +Subscripts | +Superscripts | +Horizontal Rules | +Footnotes | +Math expressions | +Other HTML tags | + +## Interpolation + +Text can be interpolated into strings for styled text with the `@markdown` macro. For example, `@markdown("Hello *{}*", "World")` becomes `"Hello *World*"`. + +Any text passed as an argument to the macro will be escaped, for example `@markdown("Hello {}", "*World*")` will become `"Hello \*World\*"` diff --git a/tools/docsnapper/Cargo.toml b/tools/docsnapper/Cargo.toml index 71ceaf8c5bb..4c1dadb1ee8 100644 --- a/tools/docsnapper/Cargo.toml +++ b/tools/docsnapper/Cargo.toml @@ -16,7 +16,7 @@ keywords = ["viewer", "gui", "ui", "toolkit"] [dependencies] i-slint-compiler = { workspace = true } -i-slint-core = { workspace = true } +i-slint-core = { workspace = true, features = ["experimental-rich-text"] } slint-interpreter = { workspace = true, features = ["display-diagnostics", "compat-1-2", "internal", "accessibility"] } i-slint-renderer-skia = { workspace = true, features = ["default", "wayland"] } diff --git a/tools/docsnapper/main.rs b/tools/docsnapper/main.rs index 7fc60a82844..319da289048 100644 --- a/tools/docsnapper/main.rs +++ b/tools/docsnapper/main.rs @@ -525,11 +525,12 @@ fn init_compiler(args: &Cli) -> slint_interpreter::Compiler { compiler.set_style(style.clone()); } - compiler.compiler_configuration(i_slint_core::InternalToken).components_to_generate = - match &args.component { - Some(component) => ComponentSelection::Named(component.clone()), - None => ComponentSelection::LastExported, - }; + let config = compiler.compiler_configuration(i_slint_core::InternalToken); + config.components_to_generate = match &args.component { + Some(component) => ComponentSelection::Named(component.clone()), + None => ComponentSelection::LastExported, + }; + config.enable_experimental = true; compiler }