Skip to content

Instantly share code, notes, and snippets.

@avh4
Forked from Janiczek/RichText.elm
Last active October 14, 2016 18:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avh4/bbd7b8153df0ef00896e6e34e83d42cb to your computer and use it in GitHub Desktop.
Save avh4/bbd7b8153df0ef00896e6e34e83d42cb to your computer and use it in GitHub Desktop.
-- 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