diff --git a/reference.odt b/reference.odt index 64a74493b..32e14f8b4 100644 Binary files a/reference.odt and b/reference.odt differ diff --git a/src/Text/Pandoc/Writers/OpenDocument.hs b/src/Text/Pandoc/Writers/OpenDocument.hs index b9444aac7..7d6731ed4 100644 --- a/src/Text/Pandoc/Writers/OpenDocument.hs +++ b/src/Text/Pandoc/Writers/OpenDocument.hs @@ -62,6 +62,7 @@ data WriterState = , stIndentPara :: Int , stInDefinition :: Bool , stTight :: Bool + , stFirstPara :: Bool } defaultWriterState :: WriterState @@ -75,6 +76,7 @@ defaultWriterState = , stIndentPara = 0 , stInDefinition = False , stTight = False + , stFirstPara = False } when :: Bool -> Doc -> Doc @@ -111,10 +113,15 @@ inTightList f = modify (\s -> s { stTight = True }) >> f >>= \r -> setInDefinitionList :: Bool -> State WriterState () setInDefinitionList b = modify $ \s -> s { stInDefinition = b } -inParagraphTags :: Doc -> Doc -inParagraphTags d | isEmpty d = empty -inParagraphTags d = - inTags False "text:p" [("text:style-name", "Text_20_body")] d +inParagraphTags :: Doc -> State WriterState Doc +inParagraphTags d | isEmpty d = return empty +inParagraphTags d = do + b <- gets stFirstPara + a <- if b + then do modify $ \st -> st { stFirstPara = False } + return $ [("text:style-name", "First_20_paragraph")] + else return [("text:style-name", "Text_20_body")] + return $ inTags False "text:p" a d inParagraphTagsWithStyle :: String -> Doc -> Doc inParagraphTagsWithStyle sty = inTags False "text:p" [("text:style-name", sty)] @@ -138,9 +145,11 @@ inTextStyle d = do $ selfClosingTag "style:text-properties" (concatMap snd $ Map.toList at) return $ inTags False "text:span" [("text:style-name","T" ++ show tn)] d -inHeaderTags :: Int -> Doc -> Doc -inHeaderTags i = inTags False "text:h" [ ("text:style-name", "Heading_20_" ++ show i) - , ("text:outline-level", show i)] +inHeaderTags :: Int -> Doc -> State WriterState Doc +inHeaderTags i d = do + modify $ \st -> st { stFirstPara = True } + return $ inTags False "text:h" [ ("text:style-name", "Heading_20_" ++ show i) + , ("text:outline-level", show i)] d inQuotes :: QuoteType -> Doc -> Doc inQuotes SingleQuote s = text "‘" <> s <> text "’" @@ -164,7 +173,7 @@ writeOpenDocument :: WriterOptions -> Pandoc -> String writeOpenDocument opts (Pandoc (Meta title authors date) blocks) = let ((doc, title', authors', date'),s) = flip runState defaultWriterState $ do - title'' <- inlinesToOpenDocument opts title + title'' <- inlinesToOpenDocument opts title authors'' <- mapM (inlinesToOpenDocument opts) authors date'' <- inlinesToOpenDocument opts date doc'' <- blocksToOpenDocument opts blocks @@ -274,9 +283,9 @@ blocksToOpenDocument o b = vcat <$> mapM (blockToOpenDocument o) b -- | Convert a Pandoc block element to OpenDocument. blockToOpenDocument :: WriterOptions -> Block -> State WriterState Doc blockToOpenDocument o bs - | Plain b <- bs = inParagraphTags <$> inlinesToOpenDocument o b - | Para b <- bs = inParagraphTags <$> inlinesToOpenDocument o b - | Header i b <- bs = inHeaderTags i <$> inlinesToOpenDocument o b + | Plain b <- bs = inParagraphTags =<< inlinesToOpenDocument o b + | Para b <- bs = inParagraphTags =<< inlinesToOpenDocument o b + | Header i b <- bs = inHeaderTags i =<< inlinesToOpenDocument o b | BlockQuote b <- bs = mkBlockQuote b | CodeBlock _ s <- bs = preformatted s | RawBlock _ _ <- bs = return empty @@ -388,7 +397,7 @@ inlineToOpenDocument o ils let footNote t = inTags False "text:note" [ ("text:id" , "ftn" ++ show n) , ("text:note-class", "footnote" )] $ - inTagsSimple "text:note-citation" (text . show $ n + 1) <> + inTagsSimple "text:note-citation" (text . show $ n + 1) <> inTagsSimple "text:note-body" t nn <- footNote <$> withParagraphStyle o "Footnote" l addNote nn diff --git a/tests/writer.opendocument b/tests/writer.opendocument index 05d45792a..6a9c18c1f 100644 --- a/tests/writer.opendocument +++ b/tests/writer.opendocument @@ -874,12 +874,12 @@ link Level 2 with emphasis Level 3 -with no blank line +with no blank line Level 2 -with no blank line +with no blank line Paragraphs -Here’s a regular +Here’s a regular paragraph. In Markdown 1.0.0 and earlier. Version 8. This line turns into a list item. Because a hard-wrapped line in the middle @@ -891,7 +891,7 @@ breakhere. Block Quotes -E-mail style: +E-mail style: This is a block quote. It is pretty short. Code in a block quote: @@ -916,7 +916,7 @@ short. Code Blocks -Code: +Code: ---- (should be four hyphens) sub status { @@ -931,7 +931,7 @@ Blocks Lists Unordered -Asterisks tight: +Asterisks tight: asterisk 1 @@ -1004,7 +1004,7 @@ Blocks Ordered -Tight: +Tight: First @@ -1080,7 +1080,7 @@ Blocks -Here’s another: +Here’s another: First @@ -1176,7 +1176,7 @@ markers -Nesting: +Nesting: Upper Alpha @@ -1217,7 +1217,7 @@ markers Definition Lists -Tight using spaces: +Tight using spaces: apple red fruit orange @@ -1282,7 +1282,8 @@ fruit HTML Blocks -Simple block on one line: +Simple block on one +line: foo And nested without indentation: @@ -1318,7 +1319,7 @@ spaces on the line: Inline Markup -This is +This is emphasized, and so is this. @@ -1365,8 +1366,8 @@ subscripts, because of the unescaped spaces: a^b c^d, a~b c~d. Smart quotes, ellipses, dashes -“Hello,” said the spider. -“‘Shelob’ is my name.” +“Hello,” said the +spider. “‘Shelob’ is my name.” ‘A’, ‘B’, and ‘C’ are letters. ‘Oak,’ ‘elm,’ @@ -1413,7 +1414,8 @@ three—four — five. α + ω × x2. -These shouldn’t be math: +These shouldn’t be +math: To get the famous equation, write @@ -1441,7 +1443,7 @@ three—four — five. Special Characters -Here is some unicode: +Here is some unicode: I hat: Î @@ -1485,7 +1487,7 @@ it. Links Explicit -Just a +Just a URL. URL and title. @@ -1502,7 +1504,7 @@ and title link Empty. Reference -Foo +Foo bar. Foo bar. @@ -1527,7 +1529,7 @@ by itself should be a link. biz. With ampersands -Here’s a +Here’s a link with an ampersand in the URL. Here’s a link with an amersand in @@ -1540,7 +1542,7 @@ link. inline link in pointy braces. Autolinks -With an ampersand: +With an ampersand: http://example.com/?foo=1&bar=2 @@ -1562,15 +1564,15 @@ link in pointy braces. or here: <http://example.com/> Images -From “Voyage dans la Lune” -by Georges Melies (1902): +From “Voyage dans la +Lune” by Georges Melies (1902): Here is a movie icon. Footnotes -Here is a footnote +Here is a footnote reference,1Here is the footnote. It can go anywhere after the footnote reference. It need not be placed at the end of the document.