aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--reference.odtbin9572 -> 9720 bytes
-rw-r--r--src/Text/Pandoc/Writers/OpenDocument.hs33
-rw-r--r--tests/writer.opendocument48
3 files changed, 46 insertions, 35 deletions
diff --git a/reference.odt b/reference.odt
index 64a74493b..32e14f8b4 100644
--- a/reference.odt
+++ b/reference.odt
Binary files 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 "&#8216;" <> s <> text "&#8217;"
@@ -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</text:span></text:a></text:h>
<text:h text:style-name="Heading_20_2" text:outline-level="2">Level 2 with
<text:span text:style-name="T2">emphasis</text:span></text:h>
<text:h text:style-name="Heading_20_3" text:outline-level="3">Level 3</text:h>
-<text:p text:style-name="Text_20_body">with no blank line</text:p>
+<text:p text:style-name="First_20_paragraph">with no blank line</text:p>
<text:h text:style-name="Heading_20_2" text:outline-level="2">Level 2</text:h>
-<text:p text:style-name="Text_20_body">with no blank line</text:p>
+<text:p text:style-name="First_20_paragraph">with no blank line</text:p>
<text:p text:style-name="Horizontal_20_Line" />
<text:h text:style-name="Heading_20_1" text:outline-level="1">Paragraphs</text:h>
-<text:p text:style-name="Text_20_body">Here&#8217;s a regular
+<text:p text:style-name="First_20_paragraph">Here&#8217;s a regular
paragraph.</text:p>
<text:p text:style-name="Text_20_body">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 @@ break<text:line-break />here.</text:p>
<text:p text:style-name="Horizontal_20_Line" />
<text:h text:style-name="Heading_20_1" text:outline-level="1">Block
Quotes</text:h>
-<text:p text:style-name="Text_20_body">E-mail style:</text:p>
+<text:p text:style-name="First_20_paragraph">E-mail style:</text:p>
<text:p text:style-name="P1">This is a block quote. It is pretty
short.</text:p>
<text:p text:style-name="P2">Code in a block quote:</text:p>
@@ -916,7 +916,7 @@ short.</text:p>
<text:p text:style-name="Horizontal_20_Line" />
<text:h text:style-name="Heading_20_1" text:outline-level="1">Code
Blocks</text:h>
-<text:p text:style-name="Text_20_body">Code:</text:p>
+<text:p text:style-name="First_20_paragraph">Code:</text:p>
<text:p text:style-name="P9">---- (should be four hyphens)</text:p>
<text:p text:style-name="P10"></text:p>
<text:p text:style-name="P11">sub status {</text:p>
@@ -931,7 +931,7 @@ Blocks</text:h>
<text:p text:style-name="Horizontal_20_Line" />
<text:h text:style-name="Heading_20_1" text:outline-level="1">Lists</text:h>
<text:h text:style-name="Heading_20_2" text:outline-level="2">Unordered</text:h>
-<text:p text:style-name="Text_20_body">Asterisks tight:</text:p>
+<text:p text:style-name="First_20_paragraph">Asterisks tight:</text:p>
<text:list text:style-name="L2">
<text:list-item>
<text:p text:style-name="P19">asterisk 1</text:p>
@@ -1004,7 +1004,7 @@ Blocks</text:h>
</text:list-item>
</text:list>
<text:h text:style-name="Heading_20_2" text:outline-level="2">Ordered</text:h>
-<text:p text:style-name="Text_20_body">Tight:</text:p>
+<text:p text:style-name="First_20_paragraph">Tight:</text:p>
<text:list text:style-name="L8">
<text:list-item>
<text:p text:style-name="P25">First</text:p>
@@ -1080,7 +1080,7 @@ Blocks</text:h>
</text:list>
</text:list-item>
</text:list>
-<text:p text:style-name="Text_20_body">Here&#8217;s another:</text:p>
+<text:p text:style-name="First_20_paragraph">Here&#8217;s another:</text:p>
<text:list text:style-name="L16">
<text:list-item>
<text:p text:style-name="P33">First</text:p>
@@ -1176,7 +1176,7 @@ markers</text:h>
</text:list>
</text:list-item>
</text:list>
-<text:p text:style-name="Text_20_body">Nesting:</text:p>
+<text:p text:style-name="First_20_paragraph">Nesting:</text:p>
<text:list text:style-name="L23">
<text:list-item>
<text:p text:style-name="P40">Upper Alpha</text:p>
@@ -1217,7 +1217,7 @@ markers</text:h>
<text:p text:style-name="Horizontal_20_Line" />
<text:h text:style-name="Heading_20_1" text:outline-level="1">Definition
Lists</text:h>
-<text:p text:style-name="Text_20_body">Tight using spaces:</text:p>
+<text:p text:style-name="First_20_paragraph">Tight using spaces:</text:p>
<text:p text:style-name="Definition_20_Term_20_Tight">apple</text:p>
<text:p text:style-name="Definition_20_Definition_20_Tight">red fruit</text:p>
<text:p text:style-name="Definition_20_Term_20_Tight">orange</text:p>
@@ -1282,7 +1282,8 @@ fruit</text:p><text:list text:style-name="L25">
</text:list>
<text:h text:style-name="Heading_20_1" text:outline-level="1">HTML
Blocks</text:h>
-<text:p text:style-name="Text_20_body">Simple block on one line:</text:p>
+<text:p text:style-name="First_20_paragraph">Simple block on one
+line:</text:p>
<text:p text:style-name="Text_20_body">foo</text:p>
<text:p text:style-name="Text_20_body">And nested without
indentation:</text:p>
@@ -1318,7 +1319,7 @@ spaces on the line:</text:p>
<text:p text:style-name="Horizontal_20_Line" />
<text:h text:style-name="Heading_20_1" text:outline-level="1">Inline
Markup</text:h>
-<text:p text:style-name="Text_20_body">This is
+<text:p text:style-name="First_20_paragraph">This is
<text:span text:style-name="T7">emphasized</text:span>, and so
<text:span text:style-name="T8">is</text:span><text:span text:style-name="T9">
</text:span><text:span text:style-name="T10">this</text:span>.</text:p>
@@ -1365,8 +1366,8 @@ subscripts, because of the unescaped spaces: a^b c^d, a~b c~d.</text:p>
<text:p text:style-name="Horizontal_20_Line" />
<text:h text:style-name="Heading_20_1" text:outline-level="1">Smart quotes,
ellipses, dashes</text:h>
-<text:p text:style-name="Text_20_body">&#8220;Hello,&#8221; said the spider.
-&#8220;&#8216;Shelob&#8217; is my name.&#8221;</text:p>
+<text:p text:style-name="First_20_paragraph">&#8220;Hello,&#8221; said the
+spider. &#8220;&#8216;Shelob&#8217; is my name.&#8221;</text:p>
<text:p text:style-name="Text_20_body">&#8216;A&#8217;, &#8216;B&#8217;, and
&#8216;C&#8217; are letters.</text:p>
<text:p text:style-name="Text_20_body">&#8216;Oak,&#8217; &#8216;elm,&#8217;
@@ -1413,7 +1414,8 @@ three&#8212;four &#8212; five.</text:p>
α + ω × <text:span text:style-name="T61">x</text:span><text:span text:style-name="T62">2</text:span>.</text:p>
</text:list-item>
</text:list>
-<text:p text:style-name="Text_20_body">These shouldn&#8217;t be math:</text:p>
+<text:p text:style-name="First_20_paragraph">These shouldn&#8217;t be
+math:</text:p>
<text:list text:style-name="L27">
<text:list-item>
<text:p text:style-name="P52">To get the famous equation, write
@@ -1441,7 +1443,7 @@ three&#8212;four &#8212; five.</text:p>
<text:p text:style-name="Horizontal_20_Line" />
<text:h text:style-name="Heading_20_1" text:outline-level="1">Special
Characters</text:h>
-<text:p text:style-name="Text_20_body">Here is some unicode:</text:p>
+<text:p text:style-name="First_20_paragraph">Here is some unicode:</text:p>
<text:list text:style-name="L28">
<text:list-item>
<text:p text:style-name="P53">I hat: Î</text:p>
@@ -1485,7 +1487,7 @@ it.</text:p>
<text:p text:style-name="Horizontal_20_Line" />
<text:h text:style-name="Heading_20_1" text:outline-level="1">Links</text:h>
<text:h text:style-name="Heading_20_2" text:outline-level="2">Explicit</text:h>
-<text:p text:style-name="Text_20_body">Just a
+<text:p text:style-name="First_20_paragraph">Just a
<text:a xlink:type="simple" xlink:href="/url/" office:name=""><text:span text:style-name="Definition">URL</text:span></text:a>.</text:p>
<text:p text:style-name="Text_20_body"><text:a xlink:type="simple" xlink:href="/url/" office:name="title"><text:span text:style-name="Definition">URL
and title</text:span></text:a>.</text:p>
@@ -1502,7 +1504,7 @@ and title</text:span></text:a></text:p>
link</text:span></text:a></text:p>
<text:p text:style-name="Text_20_body"><text:a xlink:type="simple" xlink:href="" office:name=""><text:span text:style-name="Definition">Empty</text:span></text:a>.</text:p>
<text:h text:style-name="Heading_20_2" text:outline-level="2">Reference</text:h>
-<text:p text:style-name="Text_20_body">Foo
+<text:p text:style-name="First_20_paragraph">Foo
<text:a xlink:type="simple" xlink:href="/url/" office:name=""><text:span text:style-name="Definition">bar</text:span></text:a>.</text:p>
<text:p text:style-name="Text_20_body">Foo
<text:a xlink:type="simple" xlink:href="/url/" office:name=""><text:span text:style-name="Definition">bar</text:span></text:a>.</text:p>
@@ -1527,7 +1529,7 @@ by itself should be a link.</text:p>
<text:a xlink:type="simple" xlink:href="/url/" office:name="Title with &quot;quote&quot; inside"><text:span text:style-name="Definition">biz</text:span></text:a>.</text:p>
<text:h text:style-name="Heading_20_2" text:outline-level="2">With
ampersands</text:h>
-<text:p text:style-name="Text_20_body">Here&#8217;s a
+<text:p text:style-name="First_20_paragraph">Here&#8217;s a
<text:a xlink:type="simple" xlink:href="http://example.com/?foo=1&amp;bar=2" office:name=""><text:span text:style-name="Definition">link
with an ampersand in the URL</text:span></text:a>.</text:p>
<text:p text:style-name="Text_20_body">Here&#8217;s a link with an amersand in
@@ -1540,7 +1542,7 @@ link</text:span></text:a>.</text:p>
<text:a xlink:type="simple" xlink:href="/script?foo=1&amp;bar=2" office:name=""><text:span text:style-name="Definition">inline
link in pointy braces</text:span></text:a>.</text:p>
<text:h text:style-name="Heading_20_2" text:outline-level="2">Autolinks</text:h>
-<text:p text:style-name="Text_20_body">With an ampersand:
+<text:p text:style-name="First_20_paragraph">With an ampersand:
<text:a xlink:type="simple" xlink:href="http://example.com/?foo=1&amp;bar=2" office:name=""><text:span text:style-name="Definition"><text:span text:style-name="Teletype">http://example.com/?foo=1&amp;bar=2</text:span></text:span></text:a></text:p>
<text:list text:style-name="L29">
<text:list-item>
@@ -1562,15 +1564,15 @@ link in pointy braces</text:span></text:a>.</text:p>
<text:p text:style-name="P57">or here: &lt;http://example.com/&gt;</text:p>
<text:p text:style-name="Horizontal_20_Line" />
<text:h text:style-name="Heading_20_1" text:outline-level="1">Images</text:h>
-<text:p text:style-name="Text_20_body">From &#8220;Voyage dans la Lune&#8221;
-by Georges Melies (1902):</text:p>
+<text:p text:style-name="First_20_paragraph">From &#8220;Voyage dans la
+Lune&#8221; by Georges Melies (1902):</text:p>
<text:p text:style-name="Text_20_body"><draw:frame><draw:image xlink:href="lalune.jpg" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad" /></draw:frame></text:p>
<text:p text:style-name="Text_20_body">Here is a movie
<draw:frame><draw:image xlink:href="movie.jpg" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad" /></draw:frame>
icon.</text:p>
<text:p text:style-name="Horizontal_20_Line" />
<text:h text:style-name="Heading_20_1" text:outline-level="1">Footnotes</text:h>
-<text:p text:style-name="Text_20_body">Here is a footnote
+<text:p text:style-name="First_20_paragraph">Here is a footnote
reference,<text:note text:id="ftn0" text:note-class="footnote"><text:note-citation>1</text:note-citation><text:note-body><text:p text:style-name="Footnote">Here
is the footnote. It can go anywhere after the footnote reference. It need not
be placed at the end of the document.</text:p></text:note-body></text:note>