mangrove-0.1.0.0: src/Web/Mangrove/Parse/Tree/InSelectInTable.hs
{-# LANGUAGE OverloadedStrings #-}
{-|
Description: Token processing rules within a @\<select\>@ input, which is contained within a table.
Copyright: (c) 2020 Sam May
License: MPL-2.0
Maintainer: ag.eitilt@gmail.com
Stability: stable
Portability: portable
-}
module Web.Mangrove.Parse.Tree.InSelectInTable
( treeInSelectInTable
) where
import Web.Mangrove.Parse.Common.Error
import Web.Mangrove.Parse.Tokenize.Common
import Web.Mangrove.Parse.Tree.Common
import Web.Mangrove.Parse.Tree.Patch
import Web.Mangrove.Parse.Tree.InSelect
import Web.Willow.Common.Parser
import Web.Willow.Common.Parser.Switch
-- | __HTML:__
-- @[the "in select in table" insertion mode]
-- (https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inselectintable)@
--
-- The parsing instructions corresponding to the 'InSelectInTable' section of the
-- state machine.
treeInSelectInTable :: TreeBuilder TreeOutput
treeInSelectInTable = next >>= switch
[ If (isStartTag
[ "caption"
, "table"
, "tbody"
, "tfoot"
, "thead"
, "tr"
, "td"
, "th"
]) $ \t' -> do
push t'
close <- closeElement "select"
resetInsertionMode
packTree_ . consTreeError_ (MalformedTableStructure $ tokenElement t') $ close
, If (isEndTag
[ "caption"
, "table"
, "tbody"
, "tfoot"
, "thead"
, "tr"
, "td"
, "th"
]) $ \t' -> do
hasMatch <- hasInTableScope [tagName $ tokenTag t']
if hasMatch
then do
push t'
close <- closeElement "select"
resetInsertionMode
packTree_ close
else packTreeErrors [UnexpectedElementWithImpliedEndTag] t'
, Else $ \t' -> push t' *> treeInSelect
]