Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data HtmlTagStack
- any :: (HtmlTag -> Bool) -> HtmlTagStack -> Bool
- descendsFrom :: HtmlTagStack -> HtmlTagStack -> Bool
- elem :: HtmlTag -> HtmlTagStack -> Bool
- depth :: HtmlTagStack -> Int
- empty :: HtmlTagStack
- fromList :: IsList l => [Item l] -> l
- last :: HtmlTagStack -> Maybe HtmlTag
- pop :: HtmlTag -> HtmlTagStack -> HtmlTagStack
- push :: HtmlTag -> HtmlTagStack -> HtmlTagStack
- rebase :: HtmlTagStack -> HtmlTagStack -> HtmlTagStack -> HtmlTagStack
- toList :: IsList l => l -> [Item l]
Documentation
data HtmlTagStack Source #
Represents a hierarchy of a currently parsing position in an HtmlTag
tree.
For example, if an scanHtml
has read "<a href="#"><b><i>foo</i> bar
"
it is represented as
.HtmlTagStack
[B
, A
]
Note that the tags are stored in reverse order, from the deepest to the shallowest, to make inserting a more deeper tag efficient.
Instances
any :: (HtmlTag -> Bool) -> HtmlTagStack -> Bool Source #
Determine whether any element of the tag stack satisfies the predicate.
>>>
:set -XOverloadedLists
>>>
Text.Seonbi.Html.TagStack.any ((== Void) . htmlTagKind) [Div, P, Script]
False>>>
Text.Seonbi.Html.TagStack.any ((== Void) . htmlTagKind) [BR, P, Script]
True
descendsFrom :: HtmlTagStack -> HtmlTagStack -> Bool Source #
Check if a node (HtmlEntity
) that a HtmlTagStack
(the first argument)
refers is contained by a node that another HtmlTagStack
(the second
argument), or they are sibling at least.
>>>
:set -XOverloadedLists
>>>
descendsFrom [Div, P, A, Em] [Div, P, A]
True>>>
descendsFrom [Div, P, A] [Div, P, A]
True>>>
descendsFrom [Div, P, Em] [Div, P, A]
False>>>
descendsFrom [Div, P] [Div, P, A]
False
elem :: HtmlTag -> HtmlTagStack -> Bool Source #
Determine whether the element occurs in the tag stack.
>>>
:set -XOverloadedLists
>>>
A `Text.Seonbi.Html.TagStack.elem` [A, B, Code]
True>>>
Em `Text.Seonbi.Html.TagStack.elem` [A, B, Code]
False
depth :: HtmlTagStack -> Int Source #
Count the depth of a stack.
>>>
:set -XOverloadedLists
>>>
depth empty
0>>>
depth [Div, Article, P, Em]
4
empty :: HtmlTagStack Source #
An empty stack.
fromList :: IsList l => [Item l] -> l #
The fromList
function constructs the structure l
from the given
list of Item l
last :: HtmlTagStack -> Maybe HtmlTag Source #
Get the deepest tag from a HtmlTagStack
.
>>>
:set -XOverloadedLists
>>>
let stack = [Div, Article, P, Em] :: HtmlTagStack
>>>
last stack
Just Em>>>
last []
Nothing
pop :: HtmlTag -> HtmlTagStack -> HtmlTagStack Source #
Pop the deepest tag
from a HtmlTagStack
.
>>>
:set -XOverloadedLists
>>>
pop Em [A, B, Em]
fromList [A,B]
It may pop a tag
in the middle if a tag
looking for is not the deepest:
>>>
pop B [A, B, Em]
fromList [A,Em]
It does not affect to the input if there is no such tag
in the input:
>>>
pop P [A, B, Em]
fromList [A,B,Em]>>>
pop A empty
fromList []
push :: HtmlTag -> HtmlTagStack -> HtmlTagStack Source #
Push one deeper tag
to a HtmlTagStack
.
>>>
push A empty
fromList [A]>>>
push B (push A empty)
fromList [A,B]
rebase :: HtmlTagStack -> HtmlTagStack -> HtmlTagStack -> HtmlTagStack Source #
Build a new stack from a stack by replacing its bottom with a new base.
>>>
:set -XOverloadedLists
>>>
rebase [Article, BlockQuote] [Div] [Article, BlockQuote, P, Em]
fromList [Div,P,Em]
If there are no such bottom elements, it replaces nothing.
>>>
rebase [Div, Article, BlockQuote] [Div] [Article, BlockQuote, P, Em]
fromList [Article,BlockQuote,P,Em]