@@ -86,38 +86,38 @@ inFilteredTrav deeper = traverseElems trav
88 :: (Monad m, Foldable g, DomTraversable f)
88 :: (Monad m, Foldable g, DomTraversable f)
89− => Name -- ^ Name of tag to traverse in
89+ => NameMatcher -- ^ Name of tag to traverse in
90 -> DomParserT Identity m a
90 -> DomParserT Identity m a
91 -> DomParserT g m (f a)
91 -> DomParserT g m (f a)
92inElemTrav n = inFilteredTrav deeper
92inElemTrav n = inFilteredTrav deeper
94− deeper = (DomPath [n],) . toListOf (folded . nodes . folded . _Element . el n)
94+ deeper = (DomPath [_nmShow n],) . toListOf (folded . nodes . folded . _Element . elMatchName n)
96-- | Runs parser inside first children element with given name
96-- | Runs parser inside first children element with given name
98 :: (Monad m, Foldable g)
98 :: (Monad m, Foldable g)
99− => Name
99+ => NameMatcher
100 -> DomParserT Identity m a
100 -> DomParserT Identity m a
101 -> DomParserT g m a
101 -> DomParserT g m a
102inElem n = fmap runIdentity . inElemTrav n
102inElem n = fmap runIdentity . inElemTrav n
105 :: (Monad m, Foldable g)
105 :: (Monad m, Foldable g)
106− => Name
106+ => NameMatcher
107 -> DomParserT Identity m a
107 -> DomParserT Identity m a
108 -> DomParserT g m [a]
108 -> DomParserT g m [a]
109inElemAll = inElemTrav
109inElemAll = inElemTrav
112 :: (Monad m, Foldable g)
112 :: (Monad m, Foldable g)
113− => Name
113+ => NameMatcher
114 -> DomParserT Identity m a
114 -> DomParserT Identity m a
115 -> DomParserT g m (Maybe a)
115 -> DomParserT g m (Maybe a)
116inElemMay = inElemTrav
116inElemMay = inElemTrav
119 :: (Monad m, Foldable g)
119 :: (Monad m, Foldable g)
120− => Name
120+ => NameMatcher
121 -> DomParserT Identity m a
121 -> DomParserT Identity m a
122 -> DomParserT g m (NonEmpty a)
122 -> DomParserT g m (NonEmpty a)
123inElemNe = inElemTrav
123inElemNe = inElemTrav
@@ -149,24 +149,24 @@ in given path.
150 :: forall m g a
150 :: forall m g a
151 . (Monad m, Foldable g)
151 . (Monad m, Foldable g)
152− => DomPath
152+ => [NameMatcher]
153 -> DomParserT [] m a
153 -> DomParserT [] m a
154 -> DomParserT g m a
154 -> DomParserT g m a
155divePath path = magnify $ to modElems
155divePath path = magnify $ to modElems
158 = over pdElements (toListOf $ folded . diver)
158 = over pdElements (toListOf $ folded . diver)
159− . over pdPath (<> path)
159+ . over pdPath (<> DomPath (map _nmShow path))
160 diver :: Fold Element Element
160 diver :: Fold Element Element
161− diver = foldr (.) id $ map toDive $ unDomPath path
161+ diver = foldr (.) id $ map toDive path
162− toDive n = nodes . folded . _Element . el n
162+ toDive n = nodes . folded . _Element . elMatchName n
165 :: (Monad m, Foldable g)
165 :: (Monad m, Foldable g)
166− => Name
166+ => NameMatcher
167 -> DomParserT [] m a
167 -> DomParserT [] m a
168 -> DomParserT g m a
168 -> DomParserT g m a
169−diveElem p = divePath $ DomPath [p]
169+diveElem p = divePath [p]
171-- | Ignore arbitrary current element if it conforms to predicate.
171-- | Ignore arbitrary current element if it conforms to predicate.
172ignoreElem
172ignoreElem
@@ -219,14 +219,14 @@ getCurrentName = view $ pdElements . to runIdentity . name
219-- document's element name.
219-- document's element name.
220checkCurrentName
220checkCurrentName
221 :: (Monad m)
221 :: (Monad m)
222− => Name
222+ => NameMatcher
223 -> DomParserT Identity m ()
223 -> DomParserT Identity m ()
224checkCurrentName n = do
224checkCurrentName n = do
225 cn <- getCurrentName
225 cn <- getCurrentName
226− unless (cn == n) $ do
226+ unless ((n ^. nmMatch) cn) $ do
227 p <- view pdPath
227 p <- view pdPath
228 let pinit = if null (unDomPath p) then [] else init $ unDomPath p
228 let pinit = if null (unDomPath p) then [] else init $ unDomPath p
229− throwError $ ParserErrors [PENotFound $ DomPath $ pinit ++ [n]]
229+ throwError $ ParserErrors [PENotFound $ DomPath $ pinit ++ [_nmShow n]]
230 return ()
230 return ()
232-- | Get current content. If current element contains no content or
232-- | Get current content. If current element contains no content or
@@ -288,22 +288,28 @@ readContent = maybeReadContent $ readMaybe . T.unpack . T.strip
288-- | Retuns map of attributes of current element
288-- | Retuns map of attributes of current element
290-- @since 1.0.0
290-- @since 1.0.0
291−getCurrentAttributes :: (Monad m) => DomParserT Identity m (M.Map Name Text)
293+ => DomParserT Identity m (M.Map Name Text)
292getCurrentAttributes = view $ pdElements . to runIdentity . attrs
294getCurrentAttributes = view $ pdElements . to runIdentity . attrs
294-- | Returns element with given name or 'Nothing'
296-- | Returns element with given name or 'Nothing'
296-- @since 1.0.0
298-- @since 1.0.0
297−getCurrentAttribute :: (Monad m) => Name -> DomParserT Identity m (Maybe Text)
302+ -> DomParserT Identity m (Maybe Text)
298getCurrentAttribute attrName
303getCurrentAttribute attrName
299− = preview $ pdElements . to runIdentity . attr attrName
304+ = preview $ pdElements . to runIdentity . attrs . to M.toList
305+ . traversed . filtered (views _1 (attrName ^. nmMatch)) . _2
301-- | Parses attribute with given name, throws error if attribute is not found.
307-- | Parses attribute with given name, throws error if attribute is not found.
303-- @since 1.0.0
309-- @since 1.0.0
304parseAttribute
310parseAttribute
305 :: (Monad m)
311 :: (Monad m)
306− => Name
312+ => NameMatcher
307 -- ^ Attribute name
313 -- ^ Attribute name
308 -> (Text -> Either Text a)
314 -> (Text -> Either Text a)
309 -- ^ Attribute content parser
315 -- ^ Attribute content parser
@@ -318,7 +324,7 @@ parseAttribute attrName parser =
318-- @since 1.0.0
324-- @since 1.0.0
319parseAttributeMaybe
325parseAttributeMaybe
320 :: (Monad m)
326 :: (Monad m)
321− => Name
327+ => NameMatcher
322 -- ^ Attribute name
328 -- ^ Attribute name
323 -> (Text -> Either Text a)
329 -> (Text -> Either Text a)
324 -- ^ Attribute content parser
330 -- ^ Attribute content parser