-
-
Save avh4/bbd7b8153df0ef00896e6e34e83d42cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- the type aliases would be private | |
type RichText | |
= RichText (List Line) | |
type alias Line = | |
{ left : List (Attributes, String) | |
, center : List (Attributes, String) | |
, right : List (Attributes, String) | |
} | |
type alias Attributes = | |
{ bold : Bool | |
, italic : Bool | |
, underline : Bool | |
, color : Maybe Color | |
, highlight : Maybe Highlight | |
} | |
plainAttributes : Attributes | |
plainAttributes = | |
{ bold = False | |
, italic = False | |
, underline = False | |
, alignment = Nothing | |
, color = Nothing | |
, highlight = Nothing | |
} | |
-- Stuff below isn't update to work with the addition of Line | |
text : String -> RichText | |
text string = | |
RichText [ ( plainAttributes, string ) ] | |
bold : String -> RichText | |
bold string = | |
RichText [ ( { plainAttributes | bold = True }, string ) ] | |
-- or maybe instead: | |
bold : RichText -> RichText | |
bold (RichText list) = | |
RichText (List.map (\(attrs, string) -> ( { attrs | bold = True }, string )) list) | |
append : RichText -> RichText -> RichText | |
append (RichText left) (RichText right) = | |
RichText (left ++ right) | |
concat : List RichText -> RichText | |
concat list = | |
RichText (List.concatMap (\(RichText l) -> l) list) | |
ex1 = | |
concat | |
[ text "Hello, " | |
, bold (text "World") | |
, text "." | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment