@@ -107,6 +107,7 @@ data WriterState = WriterState{
107 , stChangesDate :: String
107 , stChangesDate :: String
108 , stPrintWidth :: Integer
108 , stPrintWidth :: Integer
109 , stHeadingStyles :: [(Int,String)]
109 , stHeadingStyles :: [(Int,String)]
110+ , stFirstPara :: Bool
112defaultWriterState :: WriterState
113defaultWriterState :: WriterState
@@ -127,6 +128,7 @@ defaultWriterState = WriterState{
127 , stChangesDate = "1969-12-31T19:00:00Z"
128 , stChangesDate = "1969-12-31T19:00:00Z"
128 , stPrintWidth = 1
129 , stPrintWidth = 1
129 , stHeadingStyles = []
130 , stHeadingStyles = []
131+ , stFirstPara = False
132type WS a = StateT WriterState IO a
134type WS a = StateT WriterState IO a
@@ -643,6 +645,7 @@ blockToOpenXML opts (Div (_,["references"],_) bs) = do
643 return (header ++ rest)
645 return (header ++ rest)
644blockToOpenXML opts (Div _ bs) = blocksToOpenXML opts bs
646blockToOpenXML opts (Div _ bs) = blocksToOpenXML opts bs
645blockToOpenXML opts (Header lev (ident,_,_) lst) = do
647blockToOpenXML opts (Header lev (ident,_,_) lst) = do
646 headingStyles <- gets stHeadingStyles
649 headingStyles <- gets stHeadingStyles
647 paraProps <- maybe id (withParaProp . pStyle) (lookup lev headingStyles) $
650 paraProps <- maybe id (withParaProp . pStyle) (lookup lev headingStyles) $
648 getParaProps False
651 getParaProps False
@@ -661,6 +664,7 @@ blockToOpenXML opts (Plain lst) = withParaProp (pStyle "Compact")
661 $ blockToOpenXML opts (Para lst)
664 $ blockToOpenXML opts (Para lst)
662-- title beginning with fig: indicates that the image is a figure
665-- title beginning with fig: indicates that the image is a figure
663blockToOpenXML opts (Para [Image alt (src,'f':'i':'g':':':tit)]) = do
666blockToOpenXML opts (Para [Image alt (src,'f':'i':'g':':':tit)]) = do
664 paraProps <- getParaProps False
668 paraProps <- getParaProps False
665 contents <- inlinesToOpenXML opts [Image alt (src,tit)]
669 contents <- inlinesToOpenXML opts [Image alt (src,tit)]
666 captionNode <- withParaProp (pStyle "ImageCaption")
670 captionNode <- withParaProp (pStyle "ImageCaption")
@@ -669,24 +673,35 @@ blockToOpenXML opts (Para [Image alt (src,'f':'i':'g':':':tit)]) = do
669-- fixDisplayMath sometimes produces a Para [] as artifact
673-- fixDisplayMath sometimes produces a Para [] as artifact
670blockToOpenXML _ (Para []) = return []
674blockToOpenXML _ (Para []) = return []
671blockToOpenXML opts (Para lst) = do
675blockToOpenXML opts (Para lst) = do
676+ isFirstPara <- gets stFirstPara
678+ then do modify $ \s -> s { stFirstPara = False }
679+ withParaProp (pStyle "FirstParagraph") $ blockToOpenXML opts (Para lst)
672− paraProps <- getParaProps $ case lst of
680+ else do paraProps <- getParaProps $ case lst of
673− [Math DisplayMath _] -> True
681+ [Math DisplayMath _] -> True
674− _ -> False
682+ _ -> False
675− contents <- inlinesToOpenXML opts lst
683+ contents <- inlinesToOpenXML opts lst
676− return [mknode "w:p" [] (paraProps ++ contents)]
684+ return [mknode "w:p" [] (paraProps ++ contents)]
677blockToOpenXML _ (RawBlock format str)
685blockToOpenXML _ (RawBlock format str)
678 | format == Format "openxml" = return [ x | Elem x <- parseXML str ]
686 | format == Format "openxml" = return [ x | Elem x <- parseXML str ]
679 | otherwise = return []
687 | otherwise = return []
680−blockToOpenXML opts (BlockQuote blocks) =
688+blockToOpenXML opts (BlockQuote blocks) = do
681− withParaProp (pStyle "BlockQuote") $ blocksToOpenXML opts blocks
689+ p <- withParaProp (pStyle "BlockQuote") $ blocksToOpenXML opts blocks
682−blockToOpenXML opts (CodeBlock attrs str) =
692+blockToOpenXML opts (CodeBlock attrs str) = do
683− withParaProp (pStyle "SourceCode") $ blockToOpenXML opts $ Para [Code attrs str]
693+ p <- withParaProp (pStyle "SourceCode") $ (blockToOpenXML opts $ Para [Code attrs str])
684−blockToOpenXML _ HorizontalRule = return [
696+blockToOpenXML _ HorizontalRule = do
685− mknode "w:p" [] $ mknode "w:r" [] $ mknode "w:pict" []
699+ mknode "w:p" [] $ mknode "w:r" [] $ mknode "w:pict" []
686 $ mknode "v:rect" [("style","width:0;height:1.5pt"),
700 $ mknode "v:rect" [("style","width:0;height:1.5pt"),
687 ("o:hralign","center"),
701 ("o:hralign","center"),
688 ("o:hrstd","t"),("o:hr","t")] () ]
702 ("o:hrstd","t"),("o:hr","t")] () ]
689blockToOpenXML opts (Table caption aligns widths headers rows) = do
703blockToOpenXML opts (Table caption aligns widths headers rows) = do
690 let captionStr = stringify caption
705 let captionStr = stringify caption
691 caption' <- if null caption
706 caption' <- if null caption
692 then return []
707 then return []
@@ -733,14 +748,20 @@ blockToOpenXML opts (BulletList lst) = do
733 let marker = BulletMarker
748 let marker = BulletMarker
734 addList marker
749 addList marker
735 numid <- getNumId
750 numid <- getNumId
736− asList $ concat `fmap` mapM (listItemToOpenXML opts numid) lst
751+ l <- asList $ concat `fmap` mapM (listItemToOpenXML opts numid) lst
737blockToOpenXML opts (OrderedList (start, numstyle, numdelim) lst) = do
754blockToOpenXML opts (OrderedList (start, numstyle, numdelim) lst) = do
738 let marker = NumberMarker numstyle numdelim start
755 let marker = NumberMarker numstyle numdelim start
739 addList marker
756 addList marker
740 numid <- getNumId
757 numid <- getNumId
741− asList $ concat `fmap` mapM (listItemToOpenXML opts numid) lst
758+ l <- asList $ concat `fmap` mapM (listItemToOpenXML opts numid) lst
742−blockToOpenXML opts (DefinitionList items) =
761+blockToOpenXML opts (DefinitionList items) = do
743− concat `fmap` mapM (definitionListItemToOpenXML opts) items
762+ l <- concat `fmap` mapM (definitionListItemToOpenXML opts) items
745definitionListItemToOpenXML :: WriterOptions -> ([Inline],[[Block]]) -> WS [Element]
766definitionListItemToOpenXML :: WriterOptions -> ([Inline],[[Block]]) -> WS [Element]
746definitionListItemToOpenXML opts (term,defs) = do
767definitionListItemToOpenXML opts (term,defs) = do
@@ -847,6 +868,9 @@ formattedString str = do
847 [ mknode (if inDel then "w:delText" else "w:t")
868 [ mknode (if inDel then "w:delText" else "w:t")
848 [("xml:space","preserve")] str ] ]
869 [("xml:space","preserve")] str ] ]
871+setFirstPara :: WS ()
872+setFirstPara = modify $ \s -> s { stFirstPara = True }
850-- | Convert an inline element to OpenXML.
874-- | Convert an inline element to OpenXML.
851inlineToOpenXML :: WriterOptions -> Inline -> WS [Element]
875inlineToOpenXML :: WriterOptions -> Inline -> WS [Element]
852inlineToOpenXML _ (Str str) = formattedString str
876inlineToOpenXML _ (Str str) = formattedString str