22// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
33
44#[ derive( Clone , Debug , PartialEq ) ]
5+ /// Styles that can be applied to text spans
56#[ allow( missing_docs) ]
67pub enum Style {
78 Emphasis ,
@@ -14,31 +15,34 @@ pub enum Style {
1415}
1516
1617#[ derive( Clone , Debug , PartialEq ) ]
17- # [ allow ( missing_docs ) ]
18+ /// A style and a text span
1819pub struct FormattedSpan {
20+ /// Span of text to style
1921 pub range : core:: ops:: Range < usize > ,
22+ /// The style to apply
2023 pub style : Style ,
2124}
2225
23- #[ cfg( feature = "experimental-rich-text" ) ]
2426#[ derive( Clone , Debug ) ]
2527enum ListItemType {
2628 Ordered ( u64 ) ,
2729 Unordered ,
2830}
2931
30- # [ cfg ( feature = "experimental-rich- text" ) ]
32+ /// A section of styled text, split up by a linebreak
3133#[ derive( Clone , Debug , PartialEq ) ]
32- #[ allow( missing_docs) ]
3334pub struct StyledTextParagraph {
35+ /// The raw paragraph text
3436 pub text : std:: string:: String ,
37+ /// Formatting styles and spans
3538 pub formatting : std:: vec:: Vec < FormattedSpan > ,
39+ /// Locations of clickable links within the paragraph
3640 pub links : std:: vec:: Vec < ( std:: ops:: Range < usize > , std:: string:: String ) > ,
3741}
3842
39- #[ cfg( feature = "experimental-rich-text" ) ]
4043#[ derive( Debug , thiserror:: Error ) ]
4144#[ allow( missing_docs) ]
45+ #[ non_exhaustive]
4246pub enum StyledTextError < ' a > {
4347 #[ error( "Spans are unbalanced: stack already empty when popped" ) ]
4448 Pop ,
@@ -64,14 +68,11 @@ pub enum StyledTextError<'a> {
6468
6569/// Internal styled text type
6670#[ derive( Debug , PartialEq , Clone , Default ) ]
67- #[ allow( missing_docs) ]
6871pub struct StyledText {
69- # [ cfg ( feature = "experimental-rich- text" ) ]
72+ /// Paragraphs of styled text
7073 pub paragraphs : std:: vec:: Vec < StyledTextParagraph > ,
7174}
7275
73- #[ cfg( feature = "experimental-rich-text" ) ]
74- #[ allow( missing_docs) ]
7576impl StyledText {
7677 fn begin_paragraph ( & mut self , indentation : u32 , list_item_type : Option < ListItemType > ) {
7778 let mut text = std:: string:: String :: with_capacity ( indentation as usize * 4 ) ;
@@ -98,6 +99,7 @@ impl StyledText {
9899 } ) ;
99100 }
100101
102+ /// Parse a markdown string as styled text
101103 pub fn parse ( string : & str ) -> Result < Self , StyledTextError < ' _ > > {
102104 let parser =
103105 pulldown_cmark:: Parser :: new_ext ( string, pulldown_cmark:: Options :: ENABLE_STRIKETHROUGH ) ;
@@ -356,7 +358,6 @@ impl StyledText {
356358 }
357359}
358360
359- #[ cfg( feature = "experimental-rich-text" ) ]
360361#[ test]
361362fn markdown_parsing ( ) {
362363 assert_eq ! (
0 commit comments