| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Scrappy.Elem.Types
Synopsis
- class HtmlMatcher a
- class ShowHTML a where
- class ElementRep (a :: Type -> Type) where
- class (ShowHTML c, ElementRep a) => InnerHTMLRep (a :: Type -> Type) (b :: Type -> Type) c | a c -> b c where
- foldHtmlMatcher :: [HTMLMatcher a c] -> b c
- innerText :: b c -> String
- matches :: b c -> [c]
- noPat :: forall s u (m :: Type -> Type). Maybe (ParsecT s u m String)
- coerceAttrs :: Attrs -> [(String, Maybe String)]
- f :: String -> Maybe String
- data TreeHTML a = TreeHTML {}
- data InnerTextHTMLTree a = InnerTextHTMLTree {}
- data Elem' a = Elem' {
- _el :: Elem
- _attrs :: Map String String
- innerMatches :: [a]
- innerHtmlFull :: String
- data InnerTextResult a = InnerTextResult {
- _matchesITR :: [a]
- _fullInner :: String
- type HMatcher' (a :: Type -> Type) (b :: Type -> Type) c = [HTMLMatcher b c] -> a c
- data HTMLMatcher (a :: Type -> Type) b
- type HTMLMatcherM a = HTMLMatcher TreeHTML a
- type Inner a = HTMLMatcher Elem' a
- type HTMLMatcherList a = HTMLMatcher [] a
- data HTMLBare (e :: Type -> Type) a = HTMLBare {}
- type ElemHead = (Elem, Attrs)
- type Attrs = Map String String
- type Elem = String
- data AttrsError = IncorrectAttrs
- data MessyTree a b
- data MessyTreeMatch a b c
- = Noise' a
- | Match' b
- | Node' c [MessyTreeMatch a b c]
- type TreeIndex = [Int]
- data GroupHtml (element :: Type -> Type) a = GroupHtml [element a] Glength MaxLength
- type Glength = Int
- type MaxLength = Int
- ungroup :: ElementRep e => GroupHtml e a -> [e a]
- mkGH :: ElementRep e => [e a] -> GroupHtml e a
- longestElem :: [Elem' a] -> Maybe (Elem' a)
- maxLength :: [[a]] -> [a]
- biggestHtmlGroup :: forall (e :: Type -> Type) a. [GroupHtml e a] -> GroupHtml e a
- biggestGroup :: forall (e :: Type -> Type) a. ElementRep e => [GroupHtml e a] -> GroupHtml e a
- getHrefEl :: ElementRep e => Bool -> LastUrl -> e a -> Maybe Link
- getHrefAttrs :: Bool -> LastUrl -> Map String String -> Maybe Link
- elemToStr :: Elem' a -> String
- selfClosingElems :: [String]
- treeElemToStr :: ShowHTML a => TreeHTML a -> String
- foldFuncMatchlist :: forall a (e :: Type -> Type). (ShowHTML a, ElementRep e) => HTMLMatcher e a -> InnerTextResult a -> InnerTextResult a
- foldFuncTup :: forall (e :: Type -> Type) a. (ShowHTML (e a), ShowHTML a, ElementRep e) => HTMLMatcher e a -> (String, [a]) -> (String, [a])
- foldFuncTrup :: ShowHTML a => HTMLMatcher TreeHTML a -> (String, [a], Forest ElemHead) -> (String, [a], Forest ElemHead)
- data Clickable = Clickable ElemHead Link
- mkClickableEH :: Bool -> LastUrl -> ElemHead -> Maybe Clickable
- mkClickable :: ElementRep e => Bool -> LastUrl -> e a -> Maybe Clickable
- getLink :: Clickable -> Link
- getSrc :: a
- fst' :: (a, b, c) -> a
- snd' :: (a, b, c) -> b
- thd' :: (a, b, c) -> c
- foldFuncITR :: forall a (e :: Type -> Type). (ShowHTML a, ElementRep e) => HTMLMatcher e a -> InnerTextResult a -> InnerTextResult a
- fHM_c :: (InnerHTMLRep TreeHTML InnerTextHTMLTree a, ShowHTML a) => HTMLMatcher TreeHTML a -> InnerTextHTMLTree a -> InnerTextHTMLTree a
- makeBranch :: TreeHTML a -> Tree ElemHead
- endTag :: forall s (m :: Type -> Type) u. Stream s m Char => String -> ParsecT s u m String
- enoughMatches :: forall a s u (m :: Type -> Type). Int -> String -> Map String String -> (String, [a]) -> ParsecT s u m (Elem' a)
- enoughMatchesTree :: forall a s u (m :: Type -> Type). Int -> String -> Map String String -> (String, [a], Forest ElemHead) -> ParsecT s u m (TreeHTML a)
- selfClosingTextful :: forall a s (m :: Type -> Type) u (e :: Type -> Type). (ShowHTML a, Stream s m Char) => Maybe (ParsecT s u m a) -> ParsecT s u m [HTMLMatcher e a]
- data UrlPagination = UrlPagination String String
- type Tag = String
Documentation
class HtmlMatcher a Source #
class ElementRep (a :: Type -> Type) where Source #
Instances
class (ShowHTML c, ElementRep a) => InnerHTMLRep (a :: Type -> Type) (b :: Type -> Type) c | a c -> b c where Source #
Instances
| ShowHTML c => InnerHTMLRep Elem' InnerTextResult c Source # | |
Defined in Scrappy.Elem.Types Methods foldHtmlMatcher :: [HTMLMatcher Elem' c] -> InnerTextResult c Source # innerText :: InnerTextResult c -> String Source # matches :: InnerTextResult c -> [c] Source # | |
| ShowHTML c => InnerHTMLRep TreeHTML InnerTextHTMLTree c Source # | Tree
func :: Show a => [HTMLMatcher a] -> InnerTextHTMLTree a -> InnerTextHTMLTree a
func [] state = state
func (htmlM:htmlMatchers) (InnerTextHTMLTree{..}) = case htmlM of
IText str ->
func htmlMatchers (InnerTextHTMLTree matches (innerText <> str) innerTree)
-- | May need to enforce a Show Instance on SimpleElem
func :: (ShowHTML a, ElementRep e) => [HTMLMatcher e a] -> InnerTextResult a
func state [] = state
func InnerTextResult{..} (next:inners) = case next of
IText str ->
func (InnerTextResult matches (innerText <> str)) inners
-- | May need to enforce a Show Instance on |
Defined in Scrappy.Elem.Types Methods foldHtmlMatcher :: [HTMLMatcher TreeHTML c] -> InnerTextHTMLTree c Source # innerText :: InnerTextHTMLTree c -> String Source # matches :: InnerTextHTMLTree c -> [c] Source # | |
coerceAttrs :: Attrs -> [(String, Maybe String)] Source #
Parser is configured via the return type but gives the input type
Note, this is the representation i'll be using
Constructors
| TreeHTML | |
Instances
| ElementRep TreeHTML Source # | |
| ShowHTML c => InnerHTMLRep TreeHTML InnerTextHTMLTree c Source # | Tree
func :: Show a => [HTMLMatcher a] -> InnerTextHTMLTree a -> InnerTextHTMLTree a
func [] state = state
func (htmlM:htmlMatchers) (InnerTextHTMLTree{..}) = case htmlM of
IText str ->
func htmlMatchers (InnerTextHTMLTree matches (innerText <> str) innerTree)
-- | May need to enforce a Show Instance on SimpleElem
func :: (ShowHTML a, ElementRep e) => [HTMLMatcher e a] -> InnerTextResult a
func state [] = state
func InnerTextResult{..} (next:inners) = case next of
IText str ->
func (InnerTextResult matches (innerText <> str)) inners
-- | May need to enforce a Show Instance on |
Defined in Scrappy.Elem.Types Methods foldHtmlMatcher :: [HTMLMatcher TreeHTML c] -> InnerTextHTMLTree c Source # innerText :: InnerTextHTMLTree c -> String Source # matches :: InnerTextHTMLTree c -> [c] Source # | |
| Show a => Show (TreeHTML a) Source # | |
| ShowHTML a => ShowHTML (TreeHTML a) Source # | |
data InnerTextHTMLTree a Source #
Constructors
| InnerTextHTMLTree | |
Instances
| ShowHTML c => InnerHTMLRep TreeHTML InnerTextHTMLTree c Source # | Tree
func :: Show a => [HTMLMatcher a] -> InnerTextHTMLTree a -> InnerTextHTMLTree a
func [] state = state
func (htmlM:htmlMatchers) (InnerTextHTMLTree{..}) = case htmlM of
IText str ->
func htmlMatchers (InnerTextHTMLTree matches (innerText <> str) innerTree)
-- | May need to enforce a Show Instance on SimpleElem
func :: (ShowHTML a, ElementRep e) => [HTMLMatcher e a] -> InnerTextResult a
func state [] = state
func InnerTextResult{..} (next:inners) = case next of
IText str ->
func (InnerTextResult matches (innerText <> str)) inners
-- | May need to enforce a Show Instance on |
Defined in Scrappy.Elem.Types Methods foldHtmlMatcher :: [HTMLMatcher TreeHTML c] -> InnerTextHTMLTree c Source # innerText :: InnerTextHTMLTree c -> String Source # matches :: InnerTextHTMLTree c -> [c] Source # | |
| Monoid (InnerTextHTMLTree a) Source # | |
Defined in Scrappy.Elem.Types Methods mempty :: InnerTextHTMLTree a # mappend :: InnerTextHTMLTree a -> InnerTextHTMLTree a -> InnerTextHTMLTree a # mconcat :: [InnerTextHTMLTree a] -> InnerTextHTMLTree a # | |
| Semigroup (InnerTextHTMLTree a) Source # | |
Defined in Scrappy.Elem.Types Methods (<>) :: InnerTextHTMLTree a -> InnerTextHTMLTree a -> InnerTextHTMLTree a # sconcat :: NonEmpty (InnerTextHTMLTree a) -> InnerTextHTMLTree a # stimes :: Integral b => b -> InnerTextHTMLTree a -> InnerTextHTMLTree a # | |
node-like
Constructors
| Elem' | |
Fields
| |
Instances
| ElementRep Elem' Source # | |
| ShowHTML c => InnerHTMLRep Elem' InnerTextResult c Source # | |
Defined in Scrappy.Elem.Types Methods foldHtmlMatcher :: [HTMLMatcher Elem' c] -> InnerTextResult c Source # innerText :: InnerTextResult c -> String Source # matches :: InnerTextResult c -> [c] Source # | |
| Show a => Show (Elem' a) Source # | |
| ShowHTML a => ShowHTML (Elem' a) Source # | |
data InnerTextResult a Source #
Constructors
| InnerTextResult | |
Fields
| |
Instances
| ShowHTML c => InnerHTMLRep Elem' InnerTextResult c Source # | |
Defined in Scrappy.Elem.Types Methods foldHtmlMatcher :: [HTMLMatcher Elem' c] -> InnerTextResult c Source # innerText :: InnerTextResult c -> String Source # matches :: InnerTextResult c -> [c] Source # | |
| Monoid (InnerTextResult a) Source # | |
Defined in Scrappy.Elem.Types Methods mempty :: InnerTextResult a # mappend :: InnerTextResult a -> InnerTextResult a -> InnerTextResult a # mconcat :: [InnerTextResult a] -> InnerTextResult a # | |
| Semigroup (InnerTextResult a) Source # | |
Defined in Scrappy.Elem.Types Methods (<>) :: InnerTextResult a -> InnerTextResult a -> InnerTextResult a # sconcat :: NonEmpty (InnerTextResult a) -> InnerTextResult a # stimes :: Integral b => b -> InnerTextResult a -> InnerTextResult a # | |
| Show a => Show (InnerTextResult a) Source # | |
Defined in Scrappy.Elem.Types Methods showsPrec :: Int -> InnerTextResult a -> ShowS # show :: InnerTextResult a -> String # showList :: [InnerTextResult a] -> ShowS # | |
data HTMLMatcher (a :: Type -> Type) b Source #
Instances
| (Show b, Show (a b)) => Show (HTMLMatcher a b) Source # | |
Defined in Scrappy.Elem.Types Methods showsPrec :: Int -> HTMLMatcher a b -> ShowS # show :: HTMLMatcher a b -> String # showList :: [HTMLMatcher a b] -> ShowS # | |
type HTMLMatcherM a = HTMLMatcher TreeHTML a Source #
type Inner a = HTMLMatcher Elem' a Source #
type HTMLMatcherList a = HTMLMatcher [] a Source #
data AttrsError Source #
Constructors
| IncorrectAttrs |
Instances
| Show AttrsError Source # | |
Defined in Scrappy.Elem.Types Methods showsPrec :: Int -> AttrsError -> ShowS # show :: AttrsError -> String # showList :: [AttrsError] -> ShowS # | |
At end will be able to do Eq2 of trees where tree params are (tag,attrs) | Need some "Flexible Equality" match
Would treeElemParser fail on cases like input with no end tag?
data MessyTreeMatch a b c Source #
Constructors
| Noise' a | |
| Match' b | |
| Node' c [MessyTreeMatch a b c] |
data GroupHtml (element :: Type -> Type) a Source #
Instances
| (ElementRep e, Show (e a), Show a, ShowHTML a) => Show (GroupHtml e a) Source # | |
| Eq (GroupHtml e a) Source # | |
| Ord (GroupHtml e a) Source # | |
Defined in Scrappy.Elem.Types Methods compare :: GroupHtml e a -> GroupHtml e a -> Ordering # (<) :: GroupHtml e a -> GroupHtml e a -> Bool # (<=) :: GroupHtml e a -> GroupHtml e a -> Bool # (>) :: GroupHtml e a -> GroupHtml e a -> Bool # (>=) :: GroupHtml e a -> GroupHtml e a -> Bool # | |
ungroup :: ElementRep e => GroupHtml e a -> [e a] Source #
mkGH :: ElementRep e => [e a] -> GroupHtml e a Source #
biggestGroup :: forall (e :: Type -> Type) a. ElementRep e => [GroupHtml e a] -> GroupHtml e a Source #
selfClosingElems :: [String] Source #
List of HTML self-closing (void) elements
foldFuncMatchlist :: forall a (e :: Type -> Type). (ShowHTML a, ElementRep e) => HTMLMatcher e a -> InnerTextResult a -> InnerTextResult a Source #
foldFuncTup :: forall (e :: Type -> Type) a. (ShowHTML (e a), ShowHTML a, ElementRep e) => HTMLMatcher e a -> (String, [a]) -> (String, [a]) Source #
Bug found: matches start right way then get reversed
foldFuncTrup :: ShowHTML a => HTMLMatcher TreeHTML a -> (String, [a], Forest ElemHead) -> (String, [a], Forest ElemHead) Source #
In our failed test case with the command : parse f "" "a/div/a" where f :: (Stream s m Char) => ParsecT s u m (TreeHTML String); f = treeElemParser (Just ["a"]) Nothing []
we can tell that foldFuncTrup has been called twice (we believe)
we will test how an element named "div" inside of "a" element would behave
TODO(galen): As we advance scrappy we need to be more realistic in what a clickable is | since here we really have a LinkEl rather than a button (which is clickable but doesn't fit here) | and can emit a side effect such as that of a LinkEl or some other event like we can handle with lazy-js
mkClickableEH :: Bool -> LastUrl -> ElemHead -> Maybe Clickable Source #
In the future this definitely could be expanded upon for our JS interface | right now this only works for links but wouldn't literally click a button mkClickable :: ElemHead -> Elem' a -> Maybe Clickable mkClickable eHead emnt = do href <- getHref emnt pure $ Clickable eHead href
mkClickable :: ElementRep e => Bool -> LastUrl -> e a -> Maybe Clickable Source #
foldFuncITR :: forall a (e :: Type -> Type). (ShowHTML a, ElementRep e) => HTMLMatcher e a -> InnerTextResult a -> InnerTextResult a Source #
fHM_c :: (InnerHTMLRep TreeHTML InnerTextHTMLTree a, ShowHTML a) => HTMLMatcher TreeHTML a -> InnerTextHTMLTree a -> InnerTextHTMLTree a Source #
endTag :: forall s (m :: Type -> Type) u. Stream s m Char => String -> ParsecT s u m String Source #
enoughMatches :: forall a s u (m :: Type -> Type). Int -> String -> Map String String -> (String, [a]) -> ParsecT s u m (Elem' a) Source #
enoughMatchesTree :: forall a s u (m :: Type -> Type). Int -> String -> Map String String -> (String, [a], Forest ElemHead) -> ParsecT s u m (TreeHTML a) Source #
selfClosingTextful :: forall a s (m :: Type -> Type) u (e :: Type -> Type). (ShowHTML a, Stream s m Char) => Maybe (ParsecT s u m a) -> ParsecT s u m [HTMLMatcher e a] Source #
Explanation: This is for the edge case of p tags that are allowed to "contain" text without actually having | an end tag | If i recall correctly, self-closing tags dont allow embedded elements, only plaintext. | this means that the text belonging to the tag read, is that up until the next HTML control section
data UrlPagination Source #
Constructors
| UrlPagination String String |
Instances
| Show UrlPagination Source # | |
Defined in Scrappy.Elem.Types Methods showsPrec :: Int -> UrlPagination -> ShowS # show :: UrlPagination -> String # showList :: [UrlPagination] -> ShowS # | |
| Eq UrlPagination Source # | |
Defined in Scrappy.Elem.Types Methods (==) :: UrlPagination -> UrlPagination -> Bool # (/=) :: UrlPagination -> UrlPagination -> Bool # | |