git.iko.soy/typeable/pandoc
on master help sign in
OpenDocument: Use special style for 1st para after heading.

"First paragraph" as opposed to "Text body." This allows users to specify e.g. that only paragraphs after the first paragraph of a section are to be indented. Thanks to Andrea Rossato for the patch. Closes github Issue #20.

commite24ce1c11da99b69c14f094ef04ed00d75c79a37 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 12 Mar 2011, 13:36 (16 years ago) parent08797d1
3 files changed+46−35
reference.odt src/Text/Pandoc/Writers/OpenDocument.hs+21−12 tests/writer.opendocument+25−23
reference.odt

Binary file not shown.

src/Text/Pandoc/Writers/OpenDocument.hs+21−12
@@ -62,6 +62,7 @@ data WriterState =
6262 , stIndentPara :: Int
6363 , stInDefinition :: Bool
6464 , stTight :: Bool
65+ , stFirstPara :: Bool
6566 }
6667
6768defaultWriterState :: WriterState
@@ -75,6 +76,7 @@ defaultWriterState =
7576 , stIndentPara = 0
7677 , stInDefinition = False
7778 , stTight = False
79+ , stFirstPara = False
7880 }
7981
8082when :: Bool -> Doc -> Doc
@@ -111,10 +113,15 @@ inTightList f = modify (\s -> s { stTight = True }) >> f >>= \r ->
111113setInDefinitionList :: Bool -> State WriterState ()
112114setInDefinitionList b = modify $ \s -> s { stInDefinition = b }
113115
114−inParagraphTags :: Doc -> Doc
115−inParagraphTags d | isEmpty d = empty
116−inParagraphTags d =
117− inTags False "text:p" [("text:style-name", "Text_20_body")] d
116+inParagraphTags :: Doc -> State WriterState Doc
117+inParagraphTags d | isEmpty d = return empty
118+inParagraphTags d = do
119+ b <- gets stFirstPara
120+ a <- if b
121+ then do modify $ \st -> st { stFirstPara = False }
122+ return $ [("text:style-name", "First_20_paragraph")]
123+ else return [("text:style-name", "Text_20_body")]
124+ return $ inTags False "text:p" a d
118125
119126inParagraphTagsWithStyle :: String -> Doc -> Doc
120127inParagraphTagsWithStyle sty = inTags False "text:p" [("text:style-name", sty)]
@@ -138,9 +145,11 @@ inTextStyle d = do
138145 $ selfClosingTag "style:text-properties" (concatMap snd $ Map.toList at)
139146 return $ inTags False "text:span" [("text:style-name","T" ++ show tn)] d
140147
141−inHeaderTags :: Int -> Doc -> Doc
142−inHeaderTags i = inTags False "text:h" [ ("text:style-name", "Heading_20_" ++ show i)
143− , ("text:outline-level", show i)]
148+inHeaderTags :: Int -> Doc -> State WriterState Doc
149+inHeaderTags i d = do
150+ modify $ \st -> st { stFirstPara = True }
151+ return $ inTags False "text:h" [ ("text:style-name", "Heading_20_" ++ show i)
152+ , ("text:outline-level", show i)] d
144153
145154inQuotes :: QuoteType -> Doc -> Doc
146155inQuotes SingleQuote s = text "&#8216;" <> s <> text "&#8217;"
@@ -164,7 +173,7 @@ writeOpenDocument :: WriterOptions -> Pandoc -> String
164173writeOpenDocument opts (Pandoc (Meta title authors date) blocks) =
165174 let ((doc, title', authors', date'),s) = flip runState
166175 defaultWriterState $ do
167− title'' <- inlinesToOpenDocument opts title
176+ title'' <- inlinesToOpenDocument opts title
168177 authors'' <- mapM (inlinesToOpenDocument opts) authors
169178 date'' <- inlinesToOpenDocument opts date
170179 doc'' <- blocksToOpenDocument opts blocks
@@ -274,9 +283,9 @@ blocksToOpenDocument o b = vcat <$> mapM (blockToOpenDocument o) b
274283-- | Convert a Pandoc block element to OpenDocument.
275284blockToOpenDocument :: WriterOptions -> Block -> State WriterState Doc
276285blockToOpenDocument o bs
277− | Plain b <- bs = inParagraphTags <$> inlinesToOpenDocument o b
278− | Para b <- bs = inParagraphTags <$> inlinesToOpenDocument o b
279− | Header i b <- bs = inHeaderTags i <$> inlinesToOpenDocument o b
286+ | Plain b <- bs = inParagraphTags =<< inlinesToOpenDocument o b
287+ | Para b <- bs = inParagraphTags =<< inlinesToOpenDocument o b
288+ | Header i b <- bs = inHeaderTags i =<< inlinesToOpenDocument o b
280289 | BlockQuote b <- bs = mkBlockQuote b
281290 | CodeBlock _ s <- bs = preformatted s
282291 | RawBlock _ _ <- bs = return empty
@@ -388,7 +397,7 @@ inlineToOpenDocument o ils
388397 let footNote t = inTags False "text:note"
389398 [ ("text:id" , "ftn" ++ show n)
390399 , ("text:note-class", "footnote" )] $
391− inTagsSimple "text:note-citation" (text . show $ n + 1) <>
400+ inTagsSimple "text:note-citation" (text . show $ n + 1) <>
392401 inTagsSimple "text:note-body" t
393402 nn <- footNote <$> withParagraphStyle o "Footnote" l
394403 addNote nn
tests/writer.opendocument+25−23
@@ -874,12 +874,12 @@ link</text:span></text:a></text:h>
874874<text:h text:style-name="Heading_20_2" text:outline-level="2">Level 2 with
875875<text:span text:style-name="T2">emphasis</text:span></text:h>
876876<text:h text:style-name="Heading_20_3" text:outline-level="3">Level 3</text:h>
877−<text:p text:style-name="Text_20_body">with no blank line</text:p>
877+<text:p text:style-name="First_20_paragraph">with no blank line</text:p>
878878<text:h text:style-name="Heading_20_2" text:outline-level="2">Level 2</text:h>
879−<text:p text:style-name="Text_20_body">with no blank line</text:p>
879+<text:p text:style-name="First_20_paragraph">with no blank line</text:p>
880880<text:p text:style-name="Horizontal_20_Line" />
881881<text:h text:style-name="Heading_20_1" text:outline-level="1">Paragraphs</text:h>
882−<text:p text:style-name="Text_20_body">Here&#8217;s a regular
882+<text:p text:style-name="First_20_paragraph">Here&#8217;s a regular
883883paragraph.</text:p>
884884<text:p text:style-name="Text_20_body">In Markdown 1.0.0 and earlier. Version
8858858. 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>
891891<text:p text:style-name="Horizontal_20_Line" />
892892<text:h text:style-name="Heading_20_1" text:outline-level="1">Block
893893Quotes</text:h>
894−<text:p text:style-name="Text_20_body">E-mail style:</text:p>
894+<text:p text:style-name="First_20_paragraph">E-mail style:</text:p>
895895<text:p text:style-name="P1">This is a block quote. It is pretty
896896short.</text:p>
897897<text:p text:style-name="P2">Code in a block quote:</text:p>
@@ -916,7 +916,7 @@ short.</text:p>
916916<text:p text:style-name="Horizontal_20_Line" />
917917<text:h text:style-name="Heading_20_1" text:outline-level="1">Code
918918Blocks</text:h>
919−<text:p text:style-name="Text_20_body">Code:</text:p>
919+<text:p text:style-name="First_20_paragraph">Code:</text:p>
920920<text:p text:style-name="P9">---- (should be four hyphens)</text:p>
921921<text:p text:style-name="P10"></text:p>
922922<text:p text:style-name="P11">sub status {</text:p>
@@ -931,7 +931,7 @@ Blocks</text:h>
931931<text:p text:style-name="Horizontal_20_Line" />
932932<text:h text:style-name="Heading_20_1" text:outline-level="1">Lists</text:h>
933933<text:h text:style-name="Heading_20_2" text:outline-level="2">Unordered</text:h>
934−<text:p text:style-name="Text_20_body">Asterisks tight:</text:p>
934+<text:p text:style-name="First_20_paragraph">Asterisks tight:</text:p>
935935<text:list text:style-name="L2">
936936 <text:list-item>
937937 <text:p text:style-name="P19">asterisk 1</text:p>
@@ -1004,7 +1004,7 @@ Blocks</text:h>
10041004 </text:list-item>
10051005</text:list>
10061006<text:h text:style-name="Heading_20_2" text:outline-level="2">Ordered</text:h>
1007−<text:p text:style-name="Text_20_body">Tight:</text:p>
1007+<text:p text:style-name="First_20_paragraph">Tight:</text:p>
10081008<text:list text:style-name="L8">
10091009 <text:list-item>
10101010 <text:p text:style-name="P25">First</text:p>
@@ -1080,7 +1080,7 @@ Blocks</text:h>
10801080 </text:list>
10811081 </text:list-item>
10821082</text:list>
1083−<text:p text:style-name="Text_20_body">Here&#8217;s another:</text:p>
1083+<text:p text:style-name="First_20_paragraph">Here&#8217;s another:</text:p>
10841084<text:list text:style-name="L16">
10851085 <text:list-item>
10861086 <text:p text:style-name="P33">First</text:p>
@@ -1176,7 +1176,7 @@ markers</text:h>
11761176 </text:list>
11771177 </text:list-item>
11781178</text:list>
1179−<text:p text:style-name="Text_20_body">Nesting:</text:p>
1179+<text:p text:style-name="First_20_paragraph">Nesting:</text:p>
11801180<text:list text:style-name="L23">
11811181 <text:list-item>
11821182 <text:p text:style-name="P40">Upper Alpha</text:p>
@@ -1217,7 +1217,7 @@ markers</text:h>
12171217<text:p text:style-name="Horizontal_20_Line" />
12181218<text:h text:style-name="Heading_20_1" text:outline-level="1">Definition
12191219Lists</text:h>
1220−<text:p text:style-name="Text_20_body">Tight using spaces:</text:p>
1220+<text:p text:style-name="First_20_paragraph">Tight using spaces:</text:p>
12211221<text:p text:style-name="Definition_20_Term_20_Tight">apple</text:p>
12221222<text:p text:style-name="Definition_20_Definition_20_Tight">red fruit</text:p>
12231223<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">
12821282</text:list>
12831283<text:h text:style-name="Heading_20_1" text:outline-level="1">HTML
12841284Blocks</text:h>
1285−<text:p text:style-name="Text_20_body">Simple block on one line:</text:p>
1285+<text:p text:style-name="First_20_paragraph">Simple block on one
1286+line:</text:p>
12861287<text:p text:style-name="Text_20_body">foo</text:p>
12871288<text:p text:style-name="Text_20_body">And nested without
12881289indentation:</text:p>
@@ -1318,7 +1319,7 @@ spaces on the line:</text:p>
13181319<text:p text:style-name="Horizontal_20_Line" />
13191320<text:h text:style-name="Heading_20_1" text:outline-level="1">Inline
13201321Markup</text:h>
1321−<text:p text:style-name="Text_20_body">This is
1322+<text:p text:style-name="First_20_paragraph">This is
13221323<text:span text:style-name="T7">emphasized</text:span>, and so
13231324<text:span text:style-name="T8">is</text:span><text:span text:style-name="T9">
13241325</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>
13651366<text:p text:style-name="Horizontal_20_Line" />
13661367<text:h text:style-name="Heading_20_1" text:outline-level="1">Smart quotes,
13671368ellipses, dashes</text:h>
1368−<text:p text:style-name="Text_20_body">&#8220;Hello,&#8221; said the spider.
1369−&#8220;&#8216;Shelob&#8217; is my name.&#8221;</text:p>
1369+<text:p text:style-name="First_20_paragraph">&#8220;Hello,&#8221; said the
1370+spider. &#8220;&#8216;Shelob&#8217; is my name.&#8221;</text:p>
13701371<text:p text:style-name="Text_20_body">&#8216;A&#8217;, &#8216;B&#8217;, and
13711372&#8216;C&#8217; are letters.</text:p>
13721373<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>
14131414 α + ω × <text:span text:style-name="T61">x</text:span><text:span text:style-name="T62">2</text:span>.</text:p>
14141415 </text:list-item>
14151416</text:list>
1416−<text:p text:style-name="Text_20_body">These shouldn&#8217;t be math:</text:p>
1417+<text:p text:style-name="First_20_paragraph">These shouldn&#8217;t be
1418+math:</text:p>
14171419<text:list text:style-name="L27">
14181420 <text:list-item>
14191421 <text:p text:style-name="P52">To get the famous equation, write
@@ -1441,7 +1443,7 @@ three&#8212;four &#8212; five.</text:p>
14411443<text:p text:style-name="Horizontal_20_Line" />
14421444<text:h text:style-name="Heading_20_1" text:outline-level="1">Special
14431445Characters</text:h>
1444−<text:p text:style-name="Text_20_body">Here is some unicode:</text:p>
1446+<text:p text:style-name="First_20_paragraph">Here is some unicode:</text:p>
14451447<text:list text:style-name="L28">
14461448 <text:list-item>
14471449 <text:p text:style-name="P53">I hat: Î</text:p>
@@ -1485,7 +1487,7 @@ it.</text:p>
14851487<text:p text:style-name="Horizontal_20_Line" />
14861488<text:h text:style-name="Heading_20_1" text:outline-level="1">Links</text:h>
14871489<text:h text:style-name="Heading_20_2" text:outline-level="2">Explicit</text:h>
1488−<text:p text:style-name="Text_20_body">Just a
1490+<text:p text:style-name="First_20_paragraph">Just a
14891491<text:a xlink:type="simple" xlink:href="/url/" office:name=""><text:span text:style-name="Definition">URL</text:span></text:a>.</text:p>
14901492<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
14911493and title</text:span></text:a>.</text:p>
@@ -1502,7 +1504,7 @@ and title</text:span></text:a></text:p>
15021504link</text:span></text:a></text:p>
15031505<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>
15041506<text:h text:style-name="Heading_20_2" text:outline-level="2">Reference</text:h>
1505−<text:p text:style-name="Text_20_body">Foo
1507+<text:p text:style-name="First_20_paragraph">Foo
15061508<text:a xlink:type="simple" xlink:href="/url/" office:name=""><text:span text:style-name="Definition">bar</text:span></text:a>.</text:p>
15071509<text:p text:style-name="Text_20_body">Foo
15081510<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>
15271529<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>
15281530<text:h text:style-name="Heading_20_2" text:outline-level="2">With
15291531ampersands</text:h>
1530−<text:p text:style-name="Text_20_body">Here&#8217;s a
1532+<text:p text:style-name="First_20_paragraph">Here&#8217;s a
15311533<text:a xlink:type="simple" xlink:href="http://example.com/?foo=1&amp;bar=2" office:name=""><text:span text:style-name="Definition">link
15321534with an ampersand in the URL</text:span></text:a>.</text:p>
15331535<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>
15401542<text:a xlink:type="simple" xlink:href="/script?foo=1&amp;bar=2" office:name=""><text:span text:style-name="Definition">inline
15411543link in pointy braces</text:span></text:a>.</text:p>
15421544<text:h text:style-name="Heading_20_2" text:outline-level="2">Autolinks</text:h>
1543−<text:p text:style-name="Text_20_body">With an ampersand:
1545+<text:p text:style-name="First_20_paragraph">With an ampersand:
15441546<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>
15451547<text:list text:style-name="L29">
15461548 <text:list-item>
@@ -1562,15 +1564,15 @@ link in pointy braces</text:span></text:a>.</text:p>
15621564<text:p text:style-name="P57">or here: &lt;http://example.com/&gt;</text:p>
15631565<text:p text:style-name="Horizontal_20_Line" />
15641566<text:h text:style-name="Heading_20_1" text:outline-level="1">Images</text:h>
1565−<text:p text:style-name="Text_20_body">From &#8220;Voyage dans la Lune&#8221;
1566−by Georges Melies (1902):</text:p>
1567+<text:p text:style-name="First_20_paragraph">From &#8220;Voyage dans la
1568+Lune&#8221; by Georges Melies (1902):</text:p>
15671569<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>
15681570<text:p text:style-name="Text_20_body">Here is a movie
15691571<draw:frame><draw:image xlink:href="movie.jpg" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad" /></draw:frame>
15701572icon.</text:p>
15711573<text:p text:style-name="Horizontal_20_Line" />
15721574<text:h text:style-name="Heading_20_1" text:outline-level="1">Footnotes</text:h>
1573−<text:p text:style-name="Text_20_body">Here is a footnote
1575+<text:p text:style-name="First_20_paragraph">Here is a footnote
15741576reference,<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
15751577is the footnote. It can go anywhere after the footnote reference. It need not
15761578be placed at the end of the document.</text:p></text:note-body></text:note>