From 40602c3df69c23c9bc5c42b2de423965cdc2a103 Mon Sep 17 00:00:00 2001 From: Matthew Pickering Date: Fri, 8 Aug 2014 11:24:26 +0100 Subject: HTML EPUB exts: switch element can now be in either the inline or block position --- src/Text/Pandoc/Readers/HTML.hs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Readers/HTML.hs b/src/Text/Pandoc/Readers/HTML.hs index 42ef11065..3d988cd80 100644 --- a/src/Text/Pandoc/Readers/HTML.hs +++ b/src/Text/Pandoc/Readers/HTML.hs @@ -126,8 +126,8 @@ block = do tr <- getOption readerTrace pos <- getPosition res <- choice - [ eSwitch - , eSection + [ eSection + , eSwitch B.para block , mempty <$ eFootnote , mempty <$ eTOC , pPara @@ -147,26 +147,26 @@ block = do (take 60 $ show $ B.toList res)) (return ()) return res -namespaces :: [(String, TagParser Blocks)] -namespaces = [(mathMLNamespace, B.para <$> pMath True)] +namespaces :: [(String, TagParser Inlines)] +namespaces = [(mathMLNamespace, pMath True)] mathMLNamespace :: String mathMLNamespace = "http://www.w3.org/1998/Math/MathML" -eSwitch :: TagParser Blocks -eSwitch = try $ do +eSwitch :: Monoid a => (Inlines -> a) -> TagParser a -> TagParser a +eSwitch constructor parser = try $ do guardEnabled Ext_epub_html_exts pSatisfy (~== TagOpen "switch" []) cases <- getFirst . mconcat <$> manyTill (First <$> (eCase <* skipMany pBlank) ) (lookAhead $ try $ pSatisfy (~== TagOpen "default" [])) skipMany pBlank - fallback <- pInTags "default" ( skipMany pBlank *> block <* skipMany pBlank ) + fallback <- pInTags "default" (skipMany pBlank *> parser <* skipMany pBlank) skipMany pBlank pSatisfy (~== TagClose "switch") - return (fromMaybe fallback cases) + return $ maybe fallback constructor cases -eCase :: TagParser (Maybe Blocks) +eCase :: TagParser (Maybe Inlines) eCase = do skipMany pBlank TagOpen _ attr <- lookAhead $ pSatisfy $ (~== TagOpen "case" []) @@ -443,6 +443,7 @@ pCodeBlock = try $ do inline :: TagParser Inlines inline = choice [ eNoteref + , eSwitch id inline , pTagText , pQ , pEmph -- cgit v1.2.3