@@ 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