~alcinnz/haskell-stylist

9d1815a24921ec0e5b9a08914368b1c50bb39a84 — Adrian Cochrane 1 year, 7 months ago 3d212fb
Add support for marker-side property.
1 files changed, 35 insertions(+), 9 deletions(-)

M src/Data/CSS/Preprocessor/Text.hs
M src/Data/CSS/Preprocessor/Text.hs => src/Data/CSS/Preprocessor/Text.hs +35 -9
@@ 13,7 13,7 @@ import Data.CSS.Preprocessor.Text.CounterStyle
        (parseCounter, counterRender, CounterStore'(..), decimalCounter,
        defaultCounterStore, CounterStore, CounterStyle(..))

import Data.Maybe (fromMaybe)
import Data.Maybe (fromMaybe, isJust)
import qualified Data.HashMap.Lazy as M
import Data.Function ((&))



@@ 36,7 36,8 @@ data TextStyle p = TextStyle {
    listStyleImage :: [Token],
    listStyleType :: [Token],
    listPosInside :: Bool,
    markerMatchParent :: Bool,
    markerIsRight :: Maybe Bool,
    isRTL :: Bool,

    beforePseudo :: Maybe (TextStyle p),
    afterPseudo  :: Maybe (TextStyle p),


@@ 56,7 57,8 @@ instance PropertyParser p => PropertyParser (TextStyle p) where
            listStyleImage = [],
            listStyleType = [Ident "disc"],
            listPosInside = False,
            markerMatchParent = False,
            markerIsRight = Nothing,
            isRTL = False,
            beforePseudo = Nothing,
            afterPseudo  = Nothing,
            markerPseudo = Nothing


@@ 73,7 75,9 @@ instance PropertyParser p => PropertyParser (TextStyle p) where
            listStyleImage = listStyleImage parent,
            listStyleType = listStyleType parent,
            listPosInside = listPosInside parent,
            markerMatchParent = markerMatchParent parent,
            markerIsRight = if isJust $ markerIsRight parent
                then Just $ isRTL parent else Nothing,
            isRTL = isRTL parent,
            beforePseudo = Nothing,
            afterPseudo  = Nothing,
            markerPseudo = Nothing


@@ 134,12 138,19 @@ instance PropertyParser p => PropertyParser (TextStyle p) where
        Just self { listPosInside = False }
    longhand _ self "list-style-position" [Ident "initial"] =
        Just self { listPosInside = False }

    longhand _ self "marker-side" [Ident "match-self"] =
        Just self { markerMatchParent = False }
    longhand _ self "marker-side" [Ident "match-parent"] =
        Just self { markerMatchParent = True }
        Just self { markerIsRight = Nothing }
    longhand parent self "marker-side" [Ident "match-parent"] =
        Just self { markerIsRight = Just $ isRTL parent }
    longhand _ self "marker-side" [Ident "initial"] =
        Just self { markerMatchParent = False }
        Just self { markerIsRight = Nothing }
    longhand _ self k@"direction" v@[Ident "ltr"] = Just self {
        isRTL = False, counterProps = insertList k v $ counterProps self }
    longhand _ self k@"direction" v@[Ident "rtl"] = Just self {
        isRTL = True, counterProps = insertList k v $ counterProps self }
    longhand _ self k@"direction" v@[Ident "initial"] = Just self {
        isRTL = False, counterProps = insertList k v $ counterProps self }

    -- Capture `content` properties & anything else using counter(s) functions.
    -- This is important in Rhapsode for the sake of navigational markers.


@@ 249,7 260,10 @@ addBullet (StyleTree self@TextStyle {
        StyleTree self { isListItem = False } (t child {
            counterProps = insertList "content" txt $ counterProps child
        } : childs)
addBullet (StyleTree self@TextStyle {
addBullet (StyleTree self@TextStyle { markerIsRight = Nothing } childs) store txt
    = addBullet (StyleTree self { markerIsRight = Just $ isRTL self } childs)
        store txt
addBullet (StyleTree self@TextStyle { markerIsRight = Just False,
        isListItem = True, listPosInside = False, markerPseudo = Just child
    } childs) store txt = insertPseudos store $
        StyleTree self {


@@ 263,6 277,18 @@ addBullet (StyleTree self@TextStyle {
            -- Generate a new layout box for the bullet to sit outside of.
            StyleTree temp childs
        ]
addBullet (StyleTree self@TextStyle { markerIsRight = Just True,
        isListItem = True, listPosInside = False, markerPseudo = Just child
    } childs) store txt = insertPseudos store $
        StyleTree self {
            isListItem = False,
            counterProps=insertList "display" [Ident "flex"] $ counterProps child
        } [
            StyleTree temp childs,
            t child {
                counterProps= insertList "content" txt $ counterProps child
            }
        ]
addBullet (StyleTree self childs) store _ =
    insertPseudos store $ StyleTree self {
        isListItem = False,