git.iko.soy/typeable/pandoc
on master help sign in
Use wrappers around Doc elements to ensure proper spacing in ConTeXt writer.

Each block element is wrapped with either Pad or Reg. Pad'ed elements are guaranteed to have a blank line in between. Updated ConTeXt tests. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1158 788f1e2b-df1e-0410-8736-df70ead52e1b

commit5e65598b9e7dd980063312c4375441f31b9d9512 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateSat 29 Dec 2007, 09:31 (19 years ago) parentf74dda2
3 files changed+47−81
Text/Pandoc/Writers/ConTeXt.hs+29−21 tests/tables.context−1 tests/writer.context+18−59
Text/Pandoc/Writers/ConTeXt.hs+29−21
@@ -41,6 +41,8 @@ data WriterState =
4141 , stOptions :: WriterOptions -- writer options
4242 }
4343
44+data BlockWrapper = Pad Doc | Reg Doc
45+
4446orderedListStyles = cycle ["[n]","[a]", "[r]", "[g]"]
4547
4648-- | Convert Pandoc to ConTeXt.
@@ -123,28 +125,28 @@ stringToConTeXt = concatMap escapeCharForConTeXt
123125
124126-- | Convert Pandoc block element to ConTeXt.
125127blockToConTeXt :: Block
126− -> State WriterState Doc
127−blockToConTeXt Null = return empty
128+ -> State WriterState BlockWrapper
129+blockToConTeXt Null = return $ Reg empty
128130blockToConTeXt (Plain lst) = do
129131 st <- get
130132 let options = stOptions st
131133 contents <- wrapTeXIfNeeded options False inlineListToConTeXt lst
132− return contents
134+ return $ Reg contents
133135blockToConTeXt (Para lst) = do
134136 st <- get
135137 let options = stOptions st
136138 contents <- wrapTeXIfNeeded options False inlineListToConTeXt lst
137− return $ contents <> char '\n'
139+ return $ Pad contents
138140blockToConTeXt (BlockQuote lst) = do
139141 contents <- blockListToConTeXt lst
140− return $ text "\\startblockquote\n" $$ contents $$ text "\\stopblockquote"
142+ return $ Pad $ text "\\startblockquote" $$ contents $$ text "\\stopblockquote"
141143blockToConTeXt (CodeBlock str) =
142− return $ text $ "\\starttyping\n" ++ str ++ "\n\\stoptyping\n" -- \n needed
143− -- because \stoptyping can't have anything after it
144−blockToConTeXt (RawHtml str) = return empty
144+ return $ Reg $ text $ "\\starttyping\n" ++ str ++ "\n\\stoptyping\n"
145+ -- \n because \stoptyping can't have anything after it, inc. }
146+blockToConTeXt (RawHtml str) = return $ Reg empty
145147blockToConTeXt (BulletList lst) = do
146148 contents <- mapM listItemToConTeXt lst
147− return $ text "\\startitemize" $$ vcat contents $$ text "\\stopitemize\n"
149+ return $ Pad $ text "\\startitemize" $$ vcat contents $$ text "\\stopitemize"
148150blockToConTeXt (OrderedList (start, style, delim) lst) = do
149151 st <- get
150152 let level = stOrderedListLevel st
@@ -175,20 +177,20 @@ blockToConTeXt (OrderedList (start, style, delim) lst) = do
175177 LowerAlpha -> "[a]"
176178 UpperAlpha -> "[A]"
177179 let specs = style' ++ specs2
178− return $ text ("\\startitemize" ++ specs) $$ vcat contents $$
179− text "\\stopitemize\n"
180+ return $ Pad $ text ("\\startitemize" ++ specs) $$ vcat contents $$
181+ text "\\stopitemize"
180182blockToConTeXt (DefinitionList lst) =
181− mapM defListItemToConTeXt lst >>= return . (<> char '\n') . vcat
182−blockToConTeXt HorizontalRule = return $ text "\\thinrule\n"
183+ mapM defListItemToConTeXt lst >>= return . Pad . wrappedBlocksToDoc
184+blockToConTeXt HorizontalRule = return $ Pad $ text "\\thinrule"
183185blockToConTeXt (Header level lst) = do
184186 contents <- inlineListToConTeXt lst
185187 st <- get
186188 let opts = stOptions st
187189 let base = if writerNumberSections opts then "section" else "subject"
188− return $ if level >= 1 && level <= 5
189− then char '\\' <> text (concat (replicate (level - 1) "sub")) <>
190− text base <> char '{' <> contents <> char '}' <> char '\n'
191− else contents <> char '\n'
190+ return $ Pad $ if level >= 1 && level <= 5
191+ then char '\\' <> text (concat (replicate (level - 1) "sub")) <>
192+ text base <> char '{' <> contents <> char '}'
193+ else contents
192194blockToConTeXt (Table caption aligns widths heads rows) = do
193195 let colWidths = map printDecimal widths
194196 let colDescriptor colWidth alignment = (case alignment of
@@ -203,10 +205,10 @@ blockToConTeXt (Table caption aligns widths heads rows) = do
203205 captionText <- inlineListToConTeXt caption
204206 let captionText' = if null caption then text "none" else captionText
205207 rows' <- mapM tableRowToConTeXt rows
206− return $ text "\\placetable[here]{" <> captionText' <> char '}' $$
208+ return $ Pad $ text "\\placetable[here]{" <> captionText' <> char '}' $$
207209 text "\\starttable[" <> text colDescriptors <> char ']' $$
208210 text "\\HL" $$ headers $$ text "\\HL" $$
209− vcat rows' $$ text "\\HL\n\\stoptable\n"
211+ vcat rows' $$ text "\\HL\n\\stoptable"
210212
211213printDecimal :: Float -> String
212214printDecimal = printf "%.2f"
@@ -225,11 +227,17 @@ orderedListItemToConTeXt marker list = blockListToConTeXt list >>=
225227defListItemToConTeXt (term, def) = do
226228 term' <- inlineListToConTeXt term
227229 def' <- blockListToConTeXt def
228− return $ text "\\startdescr{" <> term' <> char '}' $$ def' $$ text "\\stopdescr"
230+ return $ Pad $ text "\\startdescr{" <> term' <> char '}' $$ def' $$ text "\\stopdescr"
231+
232+wrappedBlocksToDoc :: [BlockWrapper] -> Doc
233+wrappedBlocksToDoc = foldr addBlock empty
234+ where addBlock (Pad d) accum | isEmpty accum = d
235+ addBlock (Pad d) accum = d $$ text "" $$ accum
236+ addBlock (Reg d) accum = d $$ accum
229237
230238-- | Convert list of block elements to ConTeXt.
231239blockListToConTeXt :: [Block] -> State WriterState Doc
232−blockListToConTeXt lst = mapM blockToConTeXt lst >>= return . vcat
240+blockListToConTeXt lst = mapM blockToConTeXt lst >>= return . wrappedBlocksToDoc
233241
234242-- | Convert list of inline elements to ConTeXt.
235243inlineListToConTeXt :: [Inline] -- ^ Inlines to convert
tests/tables.context−1
@@ -132,4 +132,3 @@ Multiline table without caption:
132132\NC\AR
133133\HL
134134\stoptable
135−
tests/writer.context+18−59
@@ -121,12 +121,10 @@ here.
121121E-mail style:
122122
123123\startblockquote
124−
125124This is a block quote. It is pretty short.
126−
127125\stopblockquote
128−\startblockquote
129126
127+\startblockquote
130128Code in a block quote:
131129
132130\starttyping
@@ -147,16 +145,14 @@ A list:
147145Nested block quotes:
148146
149147\startblockquote
150−
151148nested
152−
153149\stopblockquote
154−\startblockquote
155150
151+\startblockquote
156152nested
157−
158153\stopblockquote
159154\stopblockquote
155+
160156This should not be a block quote: 2 \lettermore{} 1.
161157
162158And a following paragraph.
@@ -207,13 +203,10 @@ Asterisks loose:
207203\startitemize
208204\item
209205 asterisk 1
210−
211206\item
212207 asterisk 2
213−
214208\item
215209 asterisk 3
216−
217210\stopitemize
218211
219212Pluses tight:
@@ -232,13 +225,10 @@ Pluses loose:
232225\startitemize
233226\item
234227 Plus 1
235−
236228\item
237229 Plus 2
238−
239230\item
240231 Plus 3
241−
242232\stopitemize
243233
244234Minuses tight:
@@ -257,13 +247,10 @@ Minuses loose:
257247\startitemize
258248\item
259249 Minus 1
260−
261250\item
262251 Minus 2
263−
264252\item
265253 Minus 3
266−
267254\stopitemize
268255
269256\subsubject{Ordered}
@@ -295,13 +282,10 @@ Loose using tabs:
295282\startitemize[n][stopper=.]
296283\item
297284 First
298−
299285\item
300286 Second
301−
302287\item
303288 Third
304−
305289\stopitemize
306290
307291and using spaces:
@@ -309,13 +293,10 @@ and using spaces:
309293\startitemize[n][stopper=.]
310294\item
311295 One
312−
313296\item
314297 Two
315−
316298\item
317299 Three
318−
319300\stopitemize
320301
321302Multiple paragraphs:
@@ -323,16 +304,13 @@ Multiple paragraphs:
323304\startitemize[n][stopper=.]
324305\item
325306 Item 1, graf one.
326−
307+
327308 Item 1. graf two. The quick brown fox jumped over the lazy dog's
328309 back.
329−
330310\item
331311 Item 2.
332−
333312\item
334313 Item 3.
335−
336314\stopitemize
337315
338316\subsubject{Nested}
@@ -347,9 +325,7 @@ Multiple paragraphs:
347325 \item
348326 Tab
349327 \stopitemize
350−
351328 \stopitemize
352−
353329\stopitemize
354330
355331Here's another:
@@ -367,7 +343,6 @@ Here's another:
367343 \item
368344 Foe
369345 \stopitemize
370−
371346\item
372347 Third
373348\stopitemize
@@ -377,10 +352,9 @@ Same thing but with paragraphs:
377352\startitemize[n][stopper=.]
378353\item
379354 First
380−
381355\item
382356 Second:
383−
357+
384358 \startitemize
385359 \item
386360 Fee
@@ -389,10 +363,8 @@ Same thing but with paragraphs:
389363 \item
390364 Foe
391365 \stopitemize
392−
393366\item
394367 Third
395−
396368\stopitemize
397369
398370\subsubject{Tabs and spaces}
@@ -400,19 +372,15 @@ Same thing but with paragraphs:
400372\startitemize
401373\item
402374 this is a list item indented with tabs
403−
404375\item
405376 this is a list item indented with spaces
406−
377+
407378 \startitemize
408379 \item
409380 this is an example list item indented with tabs
410−
411381 \item
412382 this is an example list item indented with spaces
413−
414383 \stopitemize
415−
416384\stopitemize
417385
418386\subsubject{Fancy list markers}
@@ -422,9 +390,9 @@ Same thing but with paragraphs:
422390 begins with 2
423391\item
424392 and now 3
425−
393+
426394 with a continuation
427−
395+
428396 \startitemize[r][start=4,stopper=.,width=2.0em]
429397 \item
430398 sublist with roman numerals, starting with 4
@@ -436,9 +404,7 @@ Same thing but with paragraphs:
436404 \item
437405 a subsublist
438406 \stopitemize
439−
440407 \stopitemize
441−
442408\stopitemize
443409
444410Nesting:
@@ -456,11 +422,8 @@ Nesting:
456422 \item
457423 Lower alpha with paren
458424 \stopitemize
459−
460425 \stopitemize
461−
462426 \stopitemize
463−
464427\stopitemize
465428
466429Autonumbering:
@@ -474,7 +437,6 @@ Autonumbering:
474437 \item
475438 Nested.
476439 \stopitemize
477−
478440\stopitemize
479441
480442Should not be a list item:
@@ -492,9 +454,11 @@ Tight using spaces:
492454\startdescr{apple}
493455red fruit
494456\stopdescr
457+
495458\startdescr{orange}
496459orange fruit
497460\stopdescr
461+
498462\startdescr{banana}
499463yellow fruit
500464\stopdescr
@@ -504,9 +468,11 @@ Tight using tabs:
504468\startdescr{apple}
505469red fruit
506470\stopdescr
471+
507472\startdescr{orange}
508473orange fruit
509474\stopdescr
475+
510476\startdescr{banana}
511477yellow fruit
512478\stopdescr
@@ -515,15 +481,14 @@ Loose:
515481
516482\startdescr{apple}
517483red fruit
518−
519484\stopdescr
485+
520486\startdescr{orange}
521487orange fruit
522−
523488\stopdescr
489+
524490\startdescr{banana}
525491yellow fruit
526−
527492\stopdescr
528493
529494Multiple blocks with italics:
@@ -532,8 +497,8 @@ Multiple blocks with italics:
532497red fruit
533498
534499contains seeds, crisp, pleasant to taste
535−
536500\stopdescr
501+
537502\startdescr{{\em orange}}
538503orange fruit
539504
@@ -542,9 +507,7 @@ orange fruit
542507\stoptyping
543508
544509\startblockquote
545−
546510orange block quote
547−
548511\stopblockquote
549512\stopdescr
550513
@@ -777,8 +740,7 @@ Here's a
777740Here's a link with an amersand in the link text:
778741\useURL[24][http://att.com/][][AT\&T]\from[24].
779742
780−Here's an
781−\useURL[25][/script?foo=1&bar=2][][inline link]\from[25].
743+Here's an \useURL[25][/script?foo=1&bar=2][][inline link]\from[25].
782744
783745Here's an
784746\useURL[26][/script?foo=1&bar=2][][inline link in pointy braces]\from[26].
@@ -801,11 +763,10 @@ An e-mail address:
801763\useURL[29][mailto:nobody@nowhere.net][][nobody@nowhere.net]\from[29]
802764
803765\startblockquote
804−
805766Blockquoted:
806767\useURL[30][http://example.com/][][http://example.com/]\from[30]
807−
808768\stopblockquote
769+
809770Auto-links should not occur here: \type{<http://example.com/>}
810771
811772\starttyping
@@ -857,11 +818,10 @@ a space.[\letterhat{}my note] Here is an inline note.
857818verbatim characters, as well as [bracketed text].}
858819
859820\startblockquote
860−
861821Notes can go in quotes.
862822\footnote{In quote.}
863−
864823\stopblockquote
824+
865825\startitemize[n][stopper=.]
866826\item
867827 And in list items.
@@ -870,6 +830,5 @@ Notes can go in quotes.
870830
871831This paragraph should not be part of the note, as it is not
872832indented.
873−
874833\stoptext
875834