@@ -547,6 +547,20 @@ attrValue attr elt =
547547named :: String -> Element -> Bool
548548named s e = qName (elName e) == s
549549
550+isBlockElement :: Content -> Bool
551+isBlockElement (Elem e) = qName (elName e) `elem` blocktags
552+ where blocktags = ["toc","index","para","formalpara","simpara",
553+ "ackno","epigraph","blockquote","bibliography","bibliodiv",
554+ "biblioentry","glossee","glosseealso","glossary",
555+ "glossdiv","glosslist","chapter","appendix","preface",
556+ "sect1","sect2","sect3","sect4","sect5","section",
557+ "refsect1","refsect2","refsect3","refsection",
558+ "important","caution","note","tip","warning","qandadiv",
559+ "question","answer","abstract","itemizedlist","orderedlist",
560+ "variablelist","article","book","table","informaltable",
561+ "computeroutput","screen","programlisting"]
562+isBlockElement _ = False
563+
550564-- Trim leading and trailing newline characters
551565trimNl :: String -> String
552566trimNl = reverse . go . reverse . go
@@ -586,15 +600,15 @@ parseBlock (Elem e) =
586600 case qName (elName e) of
587601 "toc" -> return mempty -- skip TOC, since in pandoc it's autogenerated
588602 "index" -> return mempty -- skip index, since page numbers meaningless
589− "para" -> para <$> getInlines e
603+ "para" -> parsePara (elContent e)
590604 "formalpara" -> do
591605 tit <- case filterChild (named "title") e of
592606 Just t -> (<> str "." <> linebreak) <$> emph
593607 <$> getInlines t
594608 Nothing -> return mempty
595− addToStart tit <$> para <$> getInlines e
596− "simpara" -> para <$> getInlines e
597− "ackno" -> para <$> getInlines e
609+ addToStart tit <$> parsePara (elContent e)
610+ "simpara" -> parsePara (elContent e)
611+ "ackno" -> parsePara (elContent e)
598612 "epigraph" -> parseBlockquote
599613 "blockquote" -> parseBlockquote
600614 "attribution" -> return mempty
@@ -603,7 +617,7 @@ parseBlock (Elem e) =
603617 "title" -> return mempty -- handled by getTitle or sect
604618 "bibliography" -> sect 0
605619 "bibliodiv" -> sect 1
606− "biblioentry" -> para <$> getInlines e
620+ "biblioentry" -> parsePara (elContent e)
607621 "glosssee" -> para . (\ils -> text "See " <> ils <> str ".")
608622 <$> getInlines e
609623 "glossseealso" -> para . (\ils -> text "See also " <> ils <> str ".")
@@ -689,6 +703,16 @@ parseBlock (Elem e) =
689703 "?xml" -> return mempty
690704 _ -> getBlocks e
691705 where getBlocks e' = mconcat <$> (mapM parseBlock $ elContent e')
706+ parsePara conts = do
707+ let (ils,rest) = break isBlockElement conts
708+ ils' <- (trimInlines . mconcat) <$> mapM parseInline ils
709+ let p = if ils' == mempty then mempty else para ils'
710+ case rest of
711+ [] -> return p
712+ (r:rs) -> do
713+ b <- parseBlock r
714+ x <- parsePara rs
715+ return $ p <> b <> x
692716 codeBlockWithLang classes = do
693717 let classes' = case attrValue "language" e of
694718 "" -> classes