@@ -107,6 +107,7 @@ data WriterState = WriterState{
107107 , stChangesDate :: String
108108 , stPrintWidth :: Integer
109109 , stHeadingStyles :: [(Int,String)]
110+ , stFirstPara :: Bool
110111 }
111112
112113defaultWriterState :: WriterState
@@ -127,6 +128,7 @@ defaultWriterState = WriterState{
127128 , stChangesDate = "1969-12-31T19:00:00Z"
128129 , stPrintWidth = 1
129130 , stHeadingStyles = []
131+ , stFirstPara = False
130132 }
131133
132134type WS a = StateT WriterState IO a
@@ -643,6 +645,7 @@ blockToOpenXML opts (Div (_,["references"],_) bs) = do
643645 return (header ++ rest)
644646blockToOpenXML opts (Div _ bs) = blocksToOpenXML opts bs
645647blockToOpenXML opts (Header lev (ident,_,_) lst) = do
648+ setFirstPara
646649 headingStyles <- gets stHeadingStyles
647650 paraProps <- maybe id (withParaProp . pStyle) (lookup lev headingStyles) $
648651 getParaProps False
@@ -661,6 +664,7 @@ blockToOpenXML opts (Plain lst) = withParaProp (pStyle "Compact")
661664 $ blockToOpenXML opts (Para lst)
662665-- title beginning with fig: indicates that the image is a figure
663666blockToOpenXML opts (Para [Image alt (src,'f':'i':'g':':':tit)]) = do
667+ setFirstPara
664668 paraProps <- getParaProps False
665669 contents <- inlinesToOpenXML opts [Image alt (src,tit)]
666670 captionNode <- withParaProp (pStyle "ImageCaption")
@@ -669,24 +673,35 @@ blockToOpenXML opts (Para [Image alt (src,'f':'i':'g':':':tit)]) = do
669673-- fixDisplayMath sometimes produces a Para [] as artifact
670674blockToOpenXML _ (Para []) = return []
671675blockToOpenXML opts (Para lst) = do
672− paraProps <- getParaProps $ case lst of
673− [Math DisplayMath _] -> True
674− _ -> False
675− contents <- inlinesToOpenXML opts lst
676− return [mknode "w:p" [] (paraProps ++ contents)]
676+ isFirstPara <- gets stFirstPara
677+ if isFirstPara
678+ then do modify $ \s -> s { stFirstPara = False }
679+ withParaProp (pStyle "FirstParagraph") $ blockToOpenXML opts (Para lst)
680+ else do paraProps <- getParaProps $ case lst of
681+ [Math DisplayMath _] -> True
682+ _ -> False
683+ contents <- inlinesToOpenXML opts lst
684+ return [mknode "w:p" [] (paraProps ++ contents)]
677685blockToOpenXML _ (RawBlock format str)
678686 | format == Format "openxml" = return [ x | Elem x <- parseXML str ]
679687 | otherwise = return []
680−blockToOpenXML opts (BlockQuote blocks) =
681− withParaProp (pStyle "BlockQuote") $ blocksToOpenXML opts blocks
682−blockToOpenXML opts (CodeBlock attrs str) =
683− withParaProp (pStyle "SourceCode") $ blockToOpenXML opts $ Para [Code attrs str]
684−blockToOpenXML _ HorizontalRule = return [
685− mknode "w:p" [] $ mknode "w:r" [] $ mknode "w:pict" []
688+blockToOpenXML opts (BlockQuote blocks) = do
689+ p <- withParaProp (pStyle "BlockQuote") $ blocksToOpenXML opts blocks
690+ setFirstPara
691+ return p
692+blockToOpenXML opts (CodeBlock attrs str) = do
693+ p <- withParaProp (pStyle "SourceCode") $ (blockToOpenXML opts $ Para [Code attrs str])
694+ setFirstPara
695+ return p
696+blockToOpenXML _ HorizontalRule = do
697+ setFirstPara
698+ return [
699+ mknode "w:p" [] $ mknode "w:r" [] $ mknode "w:pict" []
686700 $ mknode "v:rect" [("style","width:0;height:1.5pt"),
687701 ("o:hralign","center"),
688702 ("o:hrstd","t"),("o:hr","t")] () ]
689703blockToOpenXML opts (Table caption aligns widths headers rows) = do
704+ setFirstPara
690705 let captionStr = stringify caption
691706 caption' <- if null caption
692707 then return []
@@ -733,14 +748,20 @@ blockToOpenXML opts (BulletList lst) = do
733748 let marker = BulletMarker
734749 addList marker
735750 numid <- getNumId
736− asList $ concat `fmap` mapM (listItemToOpenXML opts numid) lst
751+ l <- asList $ concat `fmap` mapM (listItemToOpenXML opts numid) lst
752+ setFirstPara
753+ return l
737754blockToOpenXML opts (OrderedList (start, numstyle, numdelim) lst) = do
738755 let marker = NumberMarker numstyle numdelim start
739756 addList marker
740757 numid <- getNumId
741− asList $ concat `fmap` mapM (listItemToOpenXML opts numid) lst
742−blockToOpenXML opts (DefinitionList items) =
743− concat `fmap` mapM (definitionListItemToOpenXML opts) items
758+ l <- asList $ concat `fmap` mapM (listItemToOpenXML opts numid) lst
759+ setFirstPara
760+ return l
761+blockToOpenXML opts (DefinitionList items) = do
762+ l <- concat `fmap` mapM (definitionListItemToOpenXML opts) items
763+ setFirstPara
764+ return l
744765
745766definitionListItemToOpenXML :: WriterOptions -> ([Inline],[[Block]]) -> WS [Element]
746767definitionListItemToOpenXML opts (term,defs) = do
@@ -847,6 +868,9 @@ formattedString str = do
847868 [ mknode (if inDel then "w:delText" else "w:t")
848869 [("xml:space","preserve")] str ] ]
849870
871+setFirstPara :: WS ()
872+setFirstPara = modify $ \s -> s { stFirstPara = True }
873+
850874-- | Convert an inline element to OpenXML.
851875inlineToOpenXML :: WriterOptions -> Inline -> WS [Element]
852876inlineToOpenXML _ (Str str) = formattedString str