Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some support for unicode-range and @font-face{font-weight}. #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hasmin.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ executable hasmin
, gitrev >=1.0.0 && <1.4
, hasmin
, hopfli >=0.2 && <0.4
, optparse-applicative >=0.11 && <0.17
, optparse-applicative >=0.11 && <0.18
, text >=1.2 && <1.3

other-modules: Paths_hasmin
Expand Down
17 changes: 14 additions & 3 deletions src/Hasmin/Parser/Value.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ module Hasmin.Parser.Value

import Control.Applicative ((<|>), many, optional)
import Control.Arrow (first)
import Control.Monad (mzero)
import Control.Monad (mzero, when)
import Data.Functor (($>))
import Data.Monoid ((<>))
import Data.Maybe (fromMaybe, isNothing)
import Data.Text (Text)
import Data.Char (isAscii)
import Data.Char (isAscii, isHexDigit)
import Text.Parser.Permutation ((<|?>), (<$$>), (<$?>), (<||>), permute)
import qualified Data.Set as Set
import Data.Attoparsec.Text (asciiCI, char, option, Parser, skipSpace, string)
Expand Down Expand Up @@ -297,14 +297,19 @@ backgroundSize = parseCommaSeparated (BgSizeV <$> bgSize)
auto :: Parser Auto
auto = asciiCI "auto" $> Auto

unicodeRange :: Parser Value
unicodeRange = mkOther <$> do
_ <- string "u+" <|> string "U+"
("u+" <>) <$> A.takeWhile1 (\c -> isHexDigit c || c == '-' || c == '?')

propertyValueParsersMap :: Map Text (Parser Values)
propertyValueParsersMap = Map.fromList
[--("color", (:[]) <$> colorvalue)
("display", singleValue textualvalue)
,("font", singleValue font)
,("font-size", singleValue fontSize)
,("font-style", singleValue fontStyle)
,("font-weight", singleValue numberOrText)
,("font-weight", parseSpaceSeparated numberOrText)
,("font-family", fontFamilyValues)
,("background", background)
,("background-repeat", parseCommaSeparated (RepeatStyleV <$> repeatStyle))
Expand Down Expand Up @@ -339,6 +344,7 @@ propertyValueParsersMap = Map.fromList
,("mask-position", positionList)
,("-webkit-mask-position", positionList)
,("object-position", singleValue positionvalue)
,("unicode-range", parseCommaSeparated unicodeRange)
-- ,("transform-origin", transformOrigin)
-- ,("-ms-transform-origin", transformOrigin)
-- ,("-webkit-transform-origin", transformOrigin)
Expand Down Expand Up @@ -668,6 +674,11 @@ parseCommaSeparated p = do
else mzero
Nothing -> pure $ Values v vs

parseSpaceSeparated :: Parser Value -> Parser Values
parseSpaceSeparated p = do
v : vs <- A.sepBy1 p (A.many1 A.space)
pure $ Values v $ map (Space,) vs


shadow :: Parser Shadow
shadow = permute (mkShadow <$?> (False, asciiCI "inset" $> True <* skipComments)
Expand Down