microformats2-parser 1.0.0 → 1.0.1
raw patch · 4 files changed
+16/−13 lines, 4 filesdep ~basePVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: base
API changes (from Hackage documentation)
- Data.Microformats2.Parser: [baseUri] :: Mf2ParserSettings -> Maybe URI
- Data.Microformats2.Parser: [htmlMode] :: Mf2ParserSettings -> HtmlContentMode
- Data.Microformats2.Parser: instance Data.Default.Class.Default Data.Microformats2.Parser.Mf2ParserSettings
- Data.Microformats2.Parser: instance GHC.Classes.Eq Data.Microformats2.Parser.Mf2ParserSettings
- Data.Microformats2.Parser: instance GHC.Show.Show Data.Microformats2.Parser.Mf2ParserSettings
- Data.Microformats2.Parser.HtmlUtil: instance GHC.Classes.Eq Data.Microformats2.Parser.HtmlUtil.HtmlContentMode
- Data.Microformats2.Parser.HtmlUtil: instance GHC.Show.Show Data.Microformats2.Parser.HtmlUtil.HtmlContentMode
+ Data.Microformats2.Parser: baseUri :: Mf2ParserSettings -> Maybe URI
+ Data.Microformats2.Parser: htmlMode :: Mf2ParserSettings -> HtmlContentMode
+ Data.Microformats2.Parser: instance Default Mf2ParserSettings
+ Data.Microformats2.Parser: instance Eq Mf2ParserSettings
+ Data.Microformats2.Parser: instance Show Mf2ParserSettings
+ Data.Microformats2.Parser.HtmlUtil: instance Eq HtmlContentMode
+ Data.Microformats2.Parser.HtmlUtil: instance Show HtmlContentMode
- Data.Microformats2.Parser.Util: groupBy' :: (Ord β) => (α -> β) -> [α] -> [(β, [α])]
+ Data.Microformats2.Parser.Util: groupBy' :: Ord β => (α -> β) -> [α] -> [(β, [α])]
Files
- executable/Main.hs +4/−1
- library/Data/Microformats2/Parser.hs +6/−6
- library/Data/Microformats2/Parser/Util.hs +1/−1
- microformats2-parser.cabal +5/−5
executable/Main.hs view
@@ -1,8 +1,11 @@ {-# OPTIONS_GHC -fno-warn-missing-signatures #-}-{-# LANGUAGE OverloadedStrings, UnicodeSyntax #-}+{-# LANGUAGE OverloadedStrings, UnicodeSyntax, CPP #-} module Main (main) where +#if __GLASGOW_HASKELL__ < 709+import Control.Applicative+#endif import Control.Exception import Data.Microformats2.Parser import Data.List
library/Data/Microformats2/Parser.hs view
@@ -68,7 +68,7 @@ addImpliedProperties ∷ Mf2ParserSettings → Element → Value → Value addImpliedProperties settings e v@(Object o) = Object $ addIfNull "photo" "photo" resolveUrl' $ addIfNull "url" "url" resolveUrl' $ addIfNull "name" "name" id o- where addIfNull nameJ nameH f obj = if null $ v ^? key nameJ then HMS.insert nameJ (singleton $ f <$> implyProperty nameH e) obj else obj+ where addIfNull nameJ nameH f obj = if isNothing $ v ^? key nameJ then HMS.insert nameJ (singleton $ f <$> implyProperty nameH e) obj else obj singleton x = fromMaybe Null $ (Array . V.singleton . String) <$> x resolveUrl' = resolveUrl settings addImpliedProperties _ _ v = v@@ -91,8 +91,8 @@ "type" .= filter isMf2Class (classes e) , "properties" .= properties , "children" .= childrenMf2- , "shape" .= fromMaybe Null (String <$> e ^. el "area" . attribute "shape")- , "coords" .= fromMaybe Null (String <$> e ^. el "area" . attribute "coords") ]+ , "shape" .= fromMaybe Null (String <$> e ^? el "area" . attr "shape")+ , "coords" .= fromMaybe Null (String <$> e ^? el "area" . attr "coords") ] where childrenMf2 = map ((\x → addValue "p" x Null) . parseH settings) $ filter (not . isProperty) $ deduplicateElements allMf2Descendants allMf2Descendants = filter (/= e) $ e ^.. entire . mf2Elements -- we have to do all of this because multiple elements can become multiple properties (with overlap)@@ -115,10 +115,10 @@ , linkAttr "type" "type" e , linkAttr "media" "media" e , linkAttr "hreflang" "hreflang" e ])- linkAttr nameJ nameH e = nameJ .= fromMaybe Null (String <$> e ^. attribute nameH)- linkEls = filter (not . null . (^. attribute "href")) $ filter (not . null . (^. attribute "rel")) $ rootEl' ^.. entire . els [ "a", "link" ]+ linkAttr nameJ nameH e = nameJ .= fromMaybe Null (String <$> e ^? attr nameH)+ linkEls = filter (isJust . (^? attr "href")) $ filter (isJust . (^? attr "rel")) $ rootEl' ^.. entire . els [ "a", "link" ] -- Obligatory WTF comment about base[href] being relative to the URI the page was requested from! <https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base>- settings' = settings { baseUri = case (baseUri settings, parseURIReference =<< T.unpack <$> (rootEl' ^. entire . el "base" . attribute "href")) of+ settings' = settings { baseUri = case (baseUri settings, parseURIReference =<< T.unpack <$> (rootEl' ^? entire . el "base" . attr "href")) of (Just sU, Just tU) → Just (tU `relativeTo` sU) (Just sU, Nothing) → Just sU (Nothing, Just tU) → Just tU
library/Data/Microformats2/Parser/Util.hs view
@@ -41,5 +41,5 @@ groupBy' f = M.toAscList . M.fromListWith (++) . map (\a → (f a, [a])) -- https://hackage.haskell.org/package/liquid-fixpoint-0.4.0.0/docs/src/Language-Fixpoint-Misc.html#expandSnd-expandSnd ∷ Foldable φ ⇒ φ ([α], β) → [(α, β)]+expandSnd ∷ F.Foldable φ ⇒ φ ([α], β) → [(α, β)] expandSnd = F.concatMap (\(xs, y) → (, y) <$> xs)
microformats2-parser.cabal view
@@ -1,5 +1,5 @@ name: microformats2-parser-version: 1.0.0+version: 1.0.1 synopsis: A Microformats 2 parser. category: Web homepage: https://github.com/myfreeweb/microformats2-parser@@ -9,7 +9,7 @@ license: PublicDomain license-file: UNLICENSE build-type: Simple-cabal-version: >= 1.18+cabal-version: >= 1.10 extra-source-files: README.md tested-with:@@ -21,7 +21,7 @@ library build-depends:- base >= 4.0.0.0 && < 5+ base >= 4.7.0.0 && < 5 , transformers , text , bytestring@@ -52,7 +52,7 @@ executable microformats2-parser build-depends:- base >= 4.0.0.0 && < 5+ base >= 4.7.0.0 && < 5 , options , warp , wai-extra@@ -76,7 +76,7 @@ test-suite tests build-depends:- base >= 4.0.0.0 && < 5+ base >= 4.7.0.0 && < 5 , mtl , time , text