From 3cbd09700cbc4fd99ec583a183c25600a012ca6b Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Mon, 10 Apr 2023 09:28:20 +1200 Subject: [PATCH] Document Graphics.Layout.Inline.CSS --- Graphics/Layout/Inline/CSS.hs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Graphics/Layout/Inline/CSS.hs b/Graphics/Layout/Inline/CSS.hs index 99916d2..d099665 100644 --- a/Graphics/Layout/Inline/CSS.hs +++ b/Graphics/Layout/Inline/CSS.hs @@ -13,6 +13,7 @@ import Data.Text.ParagraphLayout (Span(..), SpanOptions(..), LineHeight(..), import Graphics.Layout.CSS.Font (Font'(..), hbScale) import Data.Char (isSpace) +-- | Document text with Balkón styling options, CSS stylable. data CSSInline = CSSInline Lz.Text SpanOptions instance PropertyParser CSSInline where @@ -31,16 +32,20 @@ instance PropertyParser CSSInline where Just $ CSSInline txt opts { spanLanguage = Txt.unpack x } longhand _ _ _ _ = Nothing +-- | Helper datastructure for concatenating CSSInlines. data ParagraphBuilder = ParagraphBuilder Lz.Text [Span] +-- | Convert a CSSInline to a paragraph builder, with a span covering the entire text. buildParagraph :: CSSInline -> ParagraphBuilder buildParagraph (CSSInline txt opts) = ParagraphBuilder txt [flip Span opts $ fromEnum $ Lz.length txt] +-- | Concatenate two `ParagraphBuilder`s, adjusting the spans appropriately. concatParagraph :: ParagraphBuilder -> ParagraphBuilder -> ParagraphBuilder concatParagraph (ParagraphBuilder aTxt aOpts) (ParagraphBuilder bTxt bOps) = ParagraphBuilder (aTxt `Lz.append` bTxt) (aOpts ++ [Span (toEnum (fromEnum $ Lz.length aTxt) + off) opts | Span off opts <- bOps]) +-- | Convert a builder + font to a Balkón paragraph. finalizeParagraph :: ParagraphBuilder -> Font' -> Maybe Paragraph finalizeParagraph (ParagraphBuilder txt _) _ | Lz.all isSpace txt || Lz.null txt = Nothing finalizeParagraph (ParagraphBuilder txt ops) font' = Just $ Paragraph txt' 0 ops pOps -- 2.30.2