aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Text/Pandoc/Writers/OpenDocument.hs24
-rw-r--r--tests/tables.opendocument15
-rw-r--r--tests/writer.opendocument73
3 files changed, 62 insertions, 50 deletions
diff --git a/src/Text/Pandoc/Writers/OpenDocument.hs b/src/Text/Pandoc/Writers/OpenDocument.hs
index 7d6731ed4..e51ae92d4 100644
--- a/src/Text/Pandoc/Writers/OpenDocument.hs
+++ b/src/Text/Pandoc/Writers/OpenDocument.hs
@@ -113,6 +113,9 @@ inTightList f = modify (\s -> s { stTight = True }) >> f >>= \r ->
setInDefinitionList :: Bool -> State WriterState ()
setInDefinitionList b = modify $ \s -> s { stInDefinition = b }
+setFirstPara :: State WriterState ()
+setFirstPara = modify $ \s -> s { stFirstPara = True }
+
inParagraphTags :: Doc -> State WriterState Doc
inParagraphTags d | isEmpty d = return empty
inParagraphTags d = do
@@ -146,8 +149,7 @@ inTextStyle d = do
return $ inTags False "text:span" [("text:style-name","T" ++ show tn)] d
inHeaderTags :: Int -> Doc -> State WriterState Doc
-inHeaderTags i d = do
- modify $ \st -> st { stFirstPara = True }
+inHeaderTags i d =
return $ inTags False "text:h" [ ("text:style-name", "Heading_20_" ++ show i)
, ("text:outline-level", show i)] d
@@ -285,16 +287,18 @@ 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
- | BlockQuote b <- bs = mkBlockQuote b
- | CodeBlock _ s <- bs = preformatted s
+ | Header i b <- bs = setFirstPara >>
+ (inHeaderTags i =<< inlinesToOpenDocument o b)
+ | BlockQuote b <- bs = setFirstPara >> mkBlockQuote b
+ | DefinitionList b <- bs = setFirstPara >> defList b
+ | BulletList b <- bs = setFirstPara >> bulletListToOpenDocument o b
+ | OrderedList a b <- bs = setFirstPara >> orderedList a b
+ | CodeBlock _ s <- bs = setFirstPara >> preformatted s
+ | Table c a w h r <- bs = setFirstPara >> table c a w h r
+ | HorizontalRule <- bs = setFirstPara >> return (selfClosingTag "text:p"
+ [ ("text:style-name", "Horizontal_20_Line") ])
| RawBlock _ _ <- bs = return empty
- | DefinitionList b <- bs = defList b
- | BulletList b <- bs = bulletListToOpenDocument o b
- | OrderedList a b <- bs = orderedList a b
- | Table c a w h r <- bs = table c a w h r
| Null <- bs = return empty
- | HorizontalRule <- bs = return $ selfClosingTag "text:p" [ ("text:style-name", "Horizontal_20_Line") ]
| otherwise = return empty
where
defList b = do setInDefinitionList True
diff --git a/tests/tables.opendocument b/tests/tables.opendocument
index e103dee12..ff304ef26 100644
--- a/tests/tables.opendocument
+++ b/tests/tables.opendocument
@@ -65,7 +65,8 @@
</table:table>
<text:p text:style-name="Caption">Demonstration of simple table
syntax.</text:p>
-<text:p text:style-name="Text_20_body">Simple table without caption:</text:p>
+<text:p text:style-name="First_20_paragraph">Simple table without
+caption:</text:p>
<table:table table:name="Table2" table:style-name="Table2">
<table:table-column table:style-name="Table2.A" />
<table:table-column table:style-name="Table2.B" />
@@ -130,7 +131,7 @@ syntax.</text:p>
</table:table-cell>
</table:table-row>
</table:table>
-<text:p text:style-name="Text_20_body">Simple table indented two
+<text:p text:style-name="First_20_paragraph">Simple table indented two
spaces:</text:p>
<table:table table:name="Table3" table:style-name="Table3">
<table:table-column table:style-name="Table3.A" />
@@ -198,7 +199,8 @@ spaces:</text:p>
</table:table>
<text:p text:style-name="Caption">Demonstration of simple table
syntax.</text:p>
-<text:p text:style-name="Text_20_body">Multiline table with caption:</text:p>
+<text:p text:style-name="First_20_paragraph">Multiline table with
+caption:</text:p>
<table:table table:name="Table4" table:style-name="Table4">
<table:table-column table:style-name="Table4.A" />
<table:table-column table:style-name="Table4.B" />
@@ -253,7 +255,7 @@ syntax.</text:p>
</table:table>
<text:p text:style-name="Caption">Here's the caption. It may span multiple
lines.</text:p>
-<text:p text:style-name="Text_20_body">Multiline table without
+<text:p text:style-name="First_20_paragraph">Multiline table without
caption:</text:p>
<table:table table:name="Table5" table:style-name="Table5">
<table:table-column table:style-name="Table5.A" />
@@ -307,7 +309,8 @@ caption:</text:p>
</table:table-cell>
</table:table-row>
</table:table>
-<text:p text:style-name="Text_20_body">Table without column headers:</text:p>
+<text:p text:style-name="First_20_paragraph">Table without column
+headers:</text:p>
<table:table table:name="Table6" table:style-name="Table6">
<table:table-column table:style-name="Table6.A" />
<table:table-column table:style-name="Table6.B" />
@@ -356,7 +359,7 @@ caption:</text:p>
</table:table-cell>
</table:table-row>
</table:table>
-<text:p text:style-name="Text_20_body">Multiline table without column
+<text:p text:style-name="First_20_paragraph">Multiline table without column
headers:</text:p>
<table:table table:name="Table7" table:style-name="Table7">
<table:table-column table:style-name="Table7.A" />
diff --git a/tests/writer.opendocument b/tests/writer.opendocument
index 6a9c18c1f..03ee62af4 100644
--- a/tests/writer.opendocument
+++ b/tests/writer.opendocument
@@ -910,8 +910,8 @@ short.</text:p>
<text:p text:style-name="P2">Nested block quotes:</text:p>
<text:p text:style-name="P7">nested</text:p>
<text:p text:style-name="P8">nested</text:p>
-<text:p text:style-name="Text_20_body">This should not be a block quote: 2
-&gt; 1.</text:p>
+<text:p text:style-name="First_20_paragraph">This should not be a block quote:
+2 &gt; 1.</text:p>
<text:p text:style-name="Text_20_body">And a following paragraph.</text:p>
<text:p text:style-name="Horizontal_20_Line" />
<text:h text:style-name="Heading_20_1" text:outline-level="1">Code
@@ -924,7 +924,7 @@ Blocks</text:h>
<text:p text:style-name="P13">}</text:p>
<text:p text:style-name="P14"></text:p>
<text:p text:style-name="P15">this code block is indented by one tab</text:p>
-<text:p text:style-name="Text_20_body">And:</text:p>
+<text:p text:style-name="First_20_paragraph">And:</text:p>
<text:p text:style-name="P16"><text:s text:c="4" />this code block is indented by two tabs</text:p>
<text:p text:style-name="P17"></text:p>
<text:p text:style-name="P18">These should not be escaped: <text:s text:c="1" />\$ \\ \&gt; \[ \{</text:p>
@@ -943,7 +943,7 @@ Blocks</text:h>
<text:p text:style-name="P19">asterisk 3</text:p>
</text:list-item>
</text:list>
-<text:p text:style-name="Text_20_body">Asterisks loose:</text:p>
+<text:p text:style-name="First_20_paragraph">Asterisks loose:</text:p>
<text:list text:style-name="L3">
<text:list-item>
<text:p text:style-name="P20">asterisk 1</text:p>
@@ -955,7 +955,7 @@ Blocks</text:h>
<text:p text:style-name="P20">asterisk 3</text:p>
</text:list-item>
</text:list>
-<text:p text:style-name="Text_20_body">Pluses tight:</text:p>
+<text:p text:style-name="First_20_paragraph">Pluses tight:</text:p>
<text:list text:style-name="L4">
<text:list-item>
<text:p text:style-name="P21">Plus 1</text:p>
@@ -967,7 +967,7 @@ Blocks</text:h>
<text:p text:style-name="P21">Plus 3</text:p>
</text:list-item>
</text:list>
-<text:p text:style-name="Text_20_body">Pluses loose:</text:p>
+<text:p text:style-name="First_20_paragraph">Pluses loose:</text:p>
<text:list text:style-name="L5">
<text:list-item>
<text:p text:style-name="P22">Plus 1</text:p>
@@ -979,7 +979,7 @@ Blocks</text:h>
<text:p text:style-name="P22">Plus 3</text:p>
</text:list-item>
</text:list>
-<text:p text:style-name="Text_20_body">Minuses tight:</text:p>
+<text:p text:style-name="First_20_paragraph">Minuses tight:</text:p>
<text:list text:style-name="L6">
<text:list-item>
<text:p text:style-name="P23">Minus 1</text:p>
@@ -991,7 +991,7 @@ Blocks</text:h>
<text:p text:style-name="P23">Minus 3</text:p>
</text:list-item>
</text:list>
-<text:p text:style-name="Text_20_body">Minuses loose:</text:p>
+<text:p text:style-name="First_20_paragraph">Minuses loose:</text:p>
<text:list text:style-name="L7">
<text:list-item>
<text:p text:style-name="P24">Minus 1</text:p>
@@ -1016,7 +1016,7 @@ Blocks</text:h>
<text:p text:style-name="P25">Third</text:p>
</text:list-item>
</text:list>
-<text:p text:style-name="Text_20_body">and:</text:p>
+<text:p text:style-name="First_20_paragraph">and:</text:p>
<text:list text:style-name="L9">
<text:list-item>
<text:p text:style-name="P26">One</text:p>
@@ -1028,7 +1028,7 @@ Blocks</text:h>
<text:p text:style-name="P26">Three</text:p>
</text:list-item>
</text:list>
-<text:p text:style-name="Text_20_body">Loose using tabs:</text:p>
+<text:p text:style-name="First_20_paragraph">Loose using tabs:</text:p>
<text:list text:style-name="L10">
<text:list-item>
<text:p text:style-name="P27">First</text:p>
@@ -1040,7 +1040,7 @@ Blocks</text:h>
<text:p text:style-name="P27">Third</text:p>
</text:list-item>
</text:list>
-<text:p text:style-name="Text_20_body">and using spaces:</text:p>
+<text:p text:style-name="First_20_paragraph">and using spaces:</text:p>
<text:list text:style-name="L11">
<text:list-item>
<text:p text:style-name="P28">One</text:p>
@@ -1052,7 +1052,7 @@ Blocks</text:h>
<text:p text:style-name="P28">Three</text:p>
</text:list-item>
</text:list>
-<text:p text:style-name="Text_20_body">Multiple paragraphs:</text:p>
+<text:p text:style-name="First_20_paragraph">Multiple paragraphs:</text:p>
<text:list text:style-name="L12">
<text:list-item>
<text:p text:style-name="P29">Item 1, graf one.</text:p>
@@ -1103,7 +1103,7 @@ Blocks</text:h>
<text:p text:style-name="P33">Third</text:p>
</text:list-item>
</text:list>
-<text:p text:style-name="Text_20_body">Same thing but with
+<text:p text:style-name="First_20_paragraph">Same thing but with
paragraphs:</text:p>
<text:list text:style-name="L18">
<text:list-item>
@@ -1197,7 +1197,7 @@ markers</text:h>
</text:list>
</text:list-item>
</text:list>
-<text:p text:style-name="Text_20_body">Autonumbering:</text:p>
+<text:p text:style-name="First_20_paragraph">Autonumbering:</text:p>
<text:list text:style-name="L24">
<text:list-item>
<text:p text:style-name="P41">Autonumber.</text:p>
@@ -1211,7 +1211,8 @@ markers</text:h>
</text:list>
</text:list-item>
</text:list>
-<text:p text:style-name="Text_20_body">Should not be a list item:</text:p>
+<text:p text:style-name="First_20_paragraph">Should not be a list
+item:</text:p>
<text:p text:style-name="Text_20_body">M.A. 2007</text:p>
<text:p text:style-name="Text_20_body">B. Williams</text:p>
<text:p text:style-name="Horizontal_20_Line" />
@@ -1226,7 +1227,7 @@ fruit</text:p>
<text:p text:style-name="Definition_20_Term_20_Tight">banana</text:p>
<text:p text:style-name="Definition_20_Definition_20_Tight">yellow
fruit</text:p>
-<text:p text:style-name="Text_20_body">Tight using tabs:</text:p>
+<text:p text:style-name="First_20_paragraph">Tight using tabs:</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>
@@ -1235,14 +1236,15 @@ fruit</text:p>
<text:p text:style-name="Definition_20_Term_20_Tight">banana</text:p>
<text:p text:style-name="Definition_20_Definition_20_Tight">yellow
fruit</text:p>
-<text:p text:style-name="Text_20_body">Loose:</text:p>
+<text:p text:style-name="First_20_paragraph">Loose:</text:p>
<text:p text:style-name="Definition_20_Term">apple</text:p>
<text:p text:style-name="Definition_20_Definition">red fruit</text:p>
<text:p text:style-name="Definition_20_Term">orange</text:p>
<text:p text:style-name="Definition_20_Definition">orange fruit</text:p>
<text:p text:style-name="Definition_20_Term">banana</text:p>
<text:p text:style-name="Definition_20_Definition">yellow fruit</text:p>
-<text:p text:style-name="Text_20_body">Multiple blocks with italics:</text:p>
+<text:p text:style-name="First_20_paragraph">Multiple blocks with
+italics:</text:p>
<text:p text:style-name="Definition_20_Term"><text:span text:style-name="T3">apple</text:span></text:p>
<text:p text:style-name="Definition_20_Definition">red
fruit</text:p><text:p text:style-name="Definition_20_Definition">contains
@@ -1250,7 +1252,8 @@ seeds, crisp, pleasant to taste</text:p>
<text:p text:style-name="Definition_20_Term"><text:span text:style-name="T4">orange</text:span></text:p>
<text:p text:style-name="Definition_20_Definition">orange fruit</text:p><text:p text:style-name="P42">{ orange code block }</text:p><text:p text:style-name="P43">orange
block quote</text:p>
-<text:p text:style-name="Text_20_body">Multiple definitions, tight:</text:p>
+<text:p text:style-name="First_20_paragraph">Multiple definitions,
+tight:</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_Definition_20_Tight">computer</text:p>
@@ -1258,15 +1261,16 @@ block quote</text:p>
<text:p text:style-name="Definition_20_Definition_20_Tight">orange
fruit</text:p>
<text:p text:style-name="Definition_20_Definition_20_Tight">bank</text:p>
-<text:p text:style-name="Text_20_body">Multiple definitions, loose:</text:p>
+<text:p text:style-name="First_20_paragraph">Multiple definitions,
+loose:</text:p>
<text:p text:style-name="Definition_20_Term">apple</text:p>
<text:p text:style-name="Definition_20_Definition">red fruit</text:p>
<text:p text:style-name="Definition_20_Definition">computer</text:p>
<text:p text:style-name="Definition_20_Term">orange</text:p>
<text:p text:style-name="Definition_20_Definition">orange fruit</text:p>
<text:p text:style-name="Definition_20_Definition">bank</text:p>
-<text:p text:style-name="Text_20_body">Blank line after term, indented marker,
-alternate markers:</text:p>
+<text:p text:style-name="First_20_paragraph">Blank line after term, indented
+marker, alternate markers:</text:p>
<text:p text:style-name="Definition_20_Term">apple</text:p>
<text:p text:style-name="Definition_20_Definition">red fruit</text:p>
<text:p text:style-name="Definition_20_Definition">computer</text:p>
@@ -1302,20 +1306,20 @@ though:</text:p>
<text:p text:style-name="P45">&lt;div&gt;</text:p>
<text:p text:style-name="P46"><text:s text:c="4" />foo</text:p>
<text:p text:style-name="P47">&lt;/div&gt;</text:p>
-<text:p text:style-name="Text_20_body">As should this:</text:p>
+<text:p text:style-name="First_20_paragraph">As should this:</text:p>
<text:p text:style-name="P48">&lt;div&gt;foo&lt;/div&gt;</text:p>
-<text:p text:style-name="Text_20_body">Now, nested:</text:p>
+<text:p text:style-name="First_20_paragraph">Now, nested:</text:p>
<text:p text:style-name="Text_20_body">foo</text:p>
<text:p text:style-name="Text_20_body">This should just be an HTML
comment:</text:p>
<text:p text:style-name="Text_20_body">Multiline:</text:p>
<text:p text:style-name="Text_20_body">Code block:</text:p>
<text:p text:style-name="P49">&lt;!-- Comment --&gt;</text:p>
-<text:p text:style-name="Text_20_body">Just plain comment, with trailing
+<text:p text:style-name="First_20_paragraph">Just plain comment, with trailing
spaces on the line:</text:p>
<text:p text:style-name="Text_20_body">Code:</text:p>
<text:p text:style-name="P50">&lt;hr /&gt;</text:p>
-<text:p text:style-name="Text_20_body">Hr&#8217;s:</text:p>
+<text:p text:style-name="First_20_paragraph">Hr&#8217;s:</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>
@@ -1439,7 +1443,8 @@ math:</text:p>
23$.</text:p>
</text:list-item>
</text:list>
-<text:p text:style-name="Text_20_body">Here&#8217;s a LaTeX table:</text:p>
+<text:p text:style-name="First_20_paragraph">Here&#8217;s a LaTeX
+table:</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>
@@ -1461,8 +1466,8 @@ Characters</text:h>
<text:p text:style-name="P53">copyright: ©</text:p>
</text:list-item>
</text:list>
-<text:p text:style-name="Text_20_body">AT&amp;T has an ampersand in their
-name.</text:p>
+<text:p text:style-name="First_20_paragraph">AT&amp;T has an ampersand in
+their name.</text:p>
<text:p text:style-name="Text_20_body">AT&amp;T is another way to write
it.</text:p>
<text:p text:style-name="Text_20_body">This &amp; that.</text:p>
@@ -1523,7 +1528,7 @@ by itself should be a link.</text:p>
<text:a xlink:type="simple" xlink:href="/url" office:name=""><text:span text:style-name="Definition">thrice</text:span></text:a>.</text:p>
<text:p text:style-name="Text_20_body">This should [not][] be a link.</text:p>
<text:p text:style-name="P54">[not]: /url</text:p>
-<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="Title with &quot;quotes&quot; inside"><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="Title with &quot;quote&quot; inside"><text:span text:style-name="Definition">biz</text:span></text:a>.</text:p>
@@ -1555,11 +1560,11 @@ link in pointy braces</text:span></text:a>.</text:p>
<text:p text:style-name="P55">It should.</text:p>
</text:list-item>
</text:list>
-<text:p text:style-name="Text_20_body">An e-mail address:
+<text:p text:style-name="First_20_paragraph">An e-mail address:
<text:a xlink:type="simple" xlink:href="mailto:nobody@nowhere.net" office:name=""><text:span text:style-name="Definition"><text:span text:style-name="Teletype">nobody@nowhere.net</text:span></text:span></text:a></text:p>
<text:p text:style-name="P56">Blockquoted:
<text:a xlink:type="simple" xlink:href="http://example.com/" office:name=""><text:span text:style-name="Definition"><text:span text:style-name="Teletype">http://example.com/</text:span></text:span></text:a></text:p>
-<text:p text:style-name="Text_20_body">Auto-links should not occur here:
+<text:p text:style-name="First_20_paragraph">Auto-links should not occur here:
<text:span text:style-name="Teletype">&lt;http://example.com/&gt;</text:span></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" />
@@ -1602,8 +1607,8 @@ quote.</text:p></text:note-body></text:note></text:p>
list.</text:p></text:note-body></text:note></text:p>
</text:list-item>
</text:list>
-<text:p text:style-name="Text_20_body">This paragraph should not be part of
-the note, as it is not indented.</text:p>
+<text:p text:style-name="First_20_paragraph">This paragraph should not be part
+of the note, as it is not indented.</text:p>
</office:text>
</office:body>
</office:document-content>