git.iko.soy/typeable/pandoc
on master help sign in
Added new prettyprinting module.

* Added Text.Pandoc.Pretty. This is better suited for pandoc than the 'pretty' package. One advantage is that we now get proper wrapping; Emph [Inline] is no longer treated as a big unwrappable unit. Previously we only got breaks for spaces at the "outer level." We can also more easily avoid doubled blank lines. Performance is significantly better as well. * Removed Text.Pandoc.Blocks. Text.Pandoc.Pretty allows you to define blocks and concatenate them. * Modified markdown, RST, org readers to use Text.Pandoc.Pretty instead of Text.PrettyPrint.HughesPJ. * Text.Pandoc.Shared: Added writerColumns to WriterOptions. * Markdown, RST, Org writers now break text at writerColumns. * Added --columns command-line option, which sets stColumns and writerColumns. * Table parsing: If the size of the header > stColumns, use the header size as 100% for purposes of calculating relative widths of columns.

commit543aa28c3895d4dc7d3d659b652237efb41661b0 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 12 Dec 2010, 20:09 (16 years ago) parent2a075e9
24 files changed+1044−1068
README+5−2 pandoc.cabal+6−4 src/Text/Pandoc/Blocks.hs−146 src/Text/Pandoc/Parsing.hs+3−2 src/Text/Pandoc/Pretty.hs+395 src/Text/Pandoc/Shared.hs+3 src/Text/Pandoc/Writers/Markdown.hs+157−135 src/Text/Pandoc/Writers/Org.hs+69−79 src/Text/Pandoc/Writers/RST.hs+81−89 src/pandoc.hs+38−20 src/test-pandoc.hs+7−8 templates/org.template+2 tests/biblatex-citations.latex+3−7 tests/markdown-citations.chicago-author-date.txt+3−7 tests/markdown-citations.ieee.txt+3−7 tests/markdown-citations.mhra.txt+14−25 tests/markdown-citations.txt+5−9 tests/natbib-citations.latex+6−14 tests/tables.markdown+9−8 tests/tables.plain+9−8 tests/writer.markdown+37−80 tests/writer.org+85−197 tests/writer.plain+37−81 tests/writer.rst+67−140
README+5−2
@@ -177,7 +177,7 @@ Options
177177`-p`, `--preserve-tabs`
178178: Preserve tabs instead of converting them to spaces (the default).
179179
180−`--tab-stop=`*TABSTOP*
180+`--tab-stop=`*NUMBER*
181181: Specify the number of spaces per tab (default is 4).
182182
183183`--strict`
@@ -270,6 +270,9 @@ Options
270270: Disable text wrapping in output. By default, text is wrapped
271271 appropriately for the output format.
272272
273+`--columns`=*NUMBER*
274+: Specify length of lines in characters (for text wrapping).
275+
273276`--email-obfuscation=`*none|javascript|references*
274277: Specify a method for obfuscating `mailto:` links in HTML documents.
275278 *none* leaves `mailto:` links as they are. *javascript* obfuscates
@@ -294,7 +297,7 @@ Options
294297 one) in the output document. This option has no effect on `man`,
295298 `docbook`, `slidy`, or `s5` output.
296299
297−`--base-header-level=`*LEVEL*
300+`--base-header-level=`*NUMBER*
298301: Specify the base level for headers (defaults to 1).
299302
300303`--template=`*FILE*
pandoc.cabal+6−4
@@ -87,7 +87,7 @@ Extra-Source-Files:
8787 tests/latex-reader.native,
8888 tests/markdown-reader-more.txt,
8989 tests/markdown-reader-more.native,
90− tests/textile-reader.textile,
90+ tests/textile-reader.textile,
9191 tests/rst-reader.native,
9292 tests/rst-reader.rst,
9393 tests/s5.basic.html,
@@ -175,7 +175,8 @@ Library
175175 random, extensible-exceptions,
176176 citeproc-hs >= 0.3 && < 0.4,
177177 pandoc-types == 1.7.*,
178− json >= 0.4 && < 0.5
178+ json >= 0.4 && < 0.5,
179+ dlist >= 0.4 && < 0.6
179180 if impl(ghc >= 6.10)
180181 Build-depends: base >= 4 && < 5, syb
181182 else
@@ -193,7 +194,7 @@ Library
193194 -- END DUPLICATED SECTION
194195
195196 Exposed-Modules: Text.Pandoc,
196− Text.Pandoc.Blocks,
197+ Text.Pandoc.Pretty,
197198 Text.Pandoc.CharacterReferences,
198199 Text.Pandoc.Shared,
199200 Text.Pandoc.Parsing,
@@ -247,7 +248,8 @@ Executable pandoc
247248 random, extensible-exceptions,
248249 citeproc-hs >= 0.3 && < 0.4,
249250 pandoc-types == 1.7.*,
250− json >= 0.4 && < 0.5
251+ json >= 0.4 && < 0.5,
252+ dlist >= 0.4 && < 0.6
251253 if impl(ghc >= 6.10)
252254 Build-depends: base >= 4 && < 5, syb
253255 else
src/Text/Pandoc/Blocks.hsdeleted−146
@@ -1,146 +0,0 @@
1−{-
2−Copyright (C) 2007 John MacFarlane <jgm@berkeley.edu>
3−
4−This program is free software; you can redistribute it and/or modify
5−it under the terms of the GNU General Public License as published by
6−the Free Software Foundation; either version 2 of the License, or
7−(at your option) any later version.
8−
9−This program is distributed in the hope that it will be useful,
10−but WITHOUT ANY WARRANTY; without even the implied warranty of
11−MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12−GNU General Public License for more details.
13−
14−You should have received a copy of the GNU General Public License
15−along with this program; if not, write to the Free Software
16−Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17−-}
18−
19−{- |
20− Module : Text.Pandoc.Blocks
21− Copyright : Copyright (C) 2007 John MacFarlane
22− License : GNU GPL, version 2 or above
23−
24− Maintainer : John MacFarlane <jgm@berkeley.edu>
25− Stability : alpha
26− Portability : portable
27−
28−Functions for the manipulation of fixed-width blocks of text.
29−These are used in the construction of plain-text tables.
30−-}
31−
32−module Text.Pandoc.Blocks
33− (
34− TextBlock (..),
35− docToBlock,
36− blockToDoc,
37− widthOfBlock,
38− heightOfBlock,
39− hcatBlocks,
40− hsepBlocks,
41− centerAlignBlock,
42− leftAlignBlock,
43− rightAlignBlock
44− )
45−where
46−import Text.PrettyPrint
47−import Data.List ( intersperse )
48−
49−-- | A fixed-width block of text. Parameters are width of block,
50−-- height of block, and list of lines.
51−data TextBlock = TextBlock Int Int [String]
52−instance Show TextBlock where
53− show x = show $ blockToDoc x
54−
55−-- | Break lines in a list of lines so that none are greater than
56−-- a given width.
57−breakLines :: Int -- ^ Maximum length of lines.
58− -> [String] -- ^ List of lines.
59− -> [String]
60−breakLines _ [] = []
61−breakLines width (l:ls) =
62− if length l > width
63− then (take width l):(breakLines width ((drop width l):ls))
64− else l:(breakLines width ls)
65−
66−-- | Convert a @Doc@ element into a @TextBlock@ with a specified width.
67−docToBlock :: Int -- ^ Width of text block.
68− -> Doc -- ^ @Doc@ to convert.
69− -> TextBlock
70−docToBlock width doc =
71− let rendered = renderStyle (style {lineLength = width,
72− ribbonsPerLine = 1}) doc
73− lns = breakLines width $ lines rendered
74− in TextBlock width (length lns) lns
75−
76−-- | Convert a @TextBlock@ to a @Doc@ element.
77−blockToDoc :: TextBlock -> Doc
78−blockToDoc (TextBlock _ _ lns) =
79− if null lns
80− then empty
81− else vcat $ map text lns
82−
83−-- | Returns width of a @TextBlock@ (number of columns).
84−widthOfBlock :: TextBlock -> Int
85−widthOfBlock (TextBlock width _ _) = width
86−
87−-- | Returns height of a @TextBlock@ (number of rows).
88−heightOfBlock :: TextBlock -> Int
89−heightOfBlock (TextBlock _ height _) = height
90−
91−-- | Pads a string out to a given width using spaces.
92−hPad :: Int -- ^ Desired width.
93− -> String -- ^ String to pad.
94− -> String
95−hPad width line =
96− let linelen = length line
97− in if linelen <= width
98− then line ++ replicate (width - linelen) ' '
99− else take width line
100−
101−-- | Concatenates a list of @TextBlock@s into a new @TextBlock@ in
102−-- which they appear side by side.
103−hcatBlocks :: [TextBlock] -> TextBlock
104−hcatBlocks [] = TextBlock 0 0 []
105−hcatBlocks [x] = x -- This is not redundant! We don't want last item hPad'd.
106−hcatBlocks ((TextBlock width1 height1 lns1):xs) =
107− let (TextBlock width2 height2 lns2) = hcatBlocks xs
108− height = max height1 height2
109− width = width1 + width2
110− lns1' = map (hPad width1) $ lns1 ++ replicate (height - height1) ""
111− lns2' = lns2 ++ replicate (height - height2) ""
112− lns = zipWith (++) lns1' lns2'
113− in TextBlock width height lns
114−
115−-- | Like @hcatBlocks@, but inserts space between the @TextBlock@s.
116−hsepBlocks :: [TextBlock] -> TextBlock
117−hsepBlocks = hcatBlocks . (intersperse (TextBlock 1 1 [" "]))
118−
119−isWhitespace :: Char -> Bool
120−isWhitespace x = x `elem` " \t"
121−
122−-- | Left-aligns the contents of a @TextBlock@ within the block.
123−leftAlignBlock :: TextBlock -> TextBlock
124−leftAlignBlock (TextBlock width height lns) =
125− TextBlock width height $ map (dropWhile isWhitespace) lns
126−
127−-- | Right-aligns the contents of a @TextBlock@ within the block.
128−rightAlignBlock :: TextBlock -> TextBlock
129−rightAlignBlock (TextBlock width height lns) =
130− let rightAlignLine ln =
131− let (spaces, rest) = span isWhitespace $ reverse $ hPad width ln
132− in reverse (rest ++ spaces)
133− in TextBlock width height $ map rightAlignLine lns
134−
135−-- | Centers the contents of a @TextBlock@ within the block.
136−centerAlignBlock :: TextBlock -> TextBlock
137−centerAlignBlock (TextBlock width height lns) =
138− let centerAlignLine ln =
139− let ln' = hPad width ln
140− (startSpaces, rest) = span isWhitespace ln'
141− endSpaces = takeWhile isWhitespace (reverse ln')
142− numSpaces = length (startSpaces ++ endSpaces)
143− startSpaces' = replicate (quot numSpaces 2) ' '
144− in startSpaces' ++ rest
145− in TextBlock width height $ map centerAlignLine lns
146−
src/Text/Pandoc/Parsing.hs+3−2
@@ -453,8 +453,9 @@ widthsFromIndices :: Int -- Number of columns on terminal
453453 -> [Int] -- Indices
454454 -> [Double] -- Fractional relative sizes of columns
455455widthsFromIndices _ [] = []
456−widthsFromIndices numColumns indices =
457− let lengths' = zipWith (-) indices (0:indices)
456+widthsFromIndices numColumns' indices =
457+ let numColumns = max numColumns' (if null indices then 0 else last indices)
458+ lengths' = zipWith (-) indices (0:indices)
458459 lengths = reverse $
459460 case reverse lengths' of
460461 [] -> []
src/Text/Pandoc/Pretty.hsnew file+395
@@ -0,0 +1,395 @@
1+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
2+{-
3+Copyright (C) 2010 John MacFarlane <jgm@berkeley.edu>
4+
5+This program is free software; you can redistribute it and/or modify
6+it under the terms of the GNU General Public License as published by
7+the Free Software Foundation; either version 2 of the License, or
8+(at your option) any later version.
9+
10+This program is distributed in the hope that it will be useful,
11+but WITHOUT ANY WARRANTY; without even the implied warranty of
12+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+GNU General Public License for more details.
14+
15+You should have received a copy of the GNU General Public License
16+along with this program; if not, write to the Free Software
17+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111(-1)307 USA
18+-}
19+
20+{- |
21+ Module : Text.Pandoc.Pretty
22+ Copyright : Copyright (C) 2010 John MacFarlane
23+ License : GNU GPL, version 2 or above
24+
25+ Maintainer : John MacFarlane <jgm@berkeley.edu>
26+ Stability : alpha
27+ Portability : portable
28+
29+A prettyprinting library for the production of text documents,
30+including wrapped text, indentated blocks, and tables.
31+-}
32+
33+module Text.Pandoc.Pretty (
34+ Doc
35+ , render
36+ , cr
37+ , blankline
38+ , space
39+ , text
40+ , char
41+ , prefixed
42+ , flush
43+ , nest
44+ , hang
45+ , nowrap
46+ , offset
47+ , height
48+ , lblock
49+ , cblock
50+ , rblock
51+ , (<>)
52+ , (<+>)
53+ , ($$)
54+ , ($+$)
55+ , isEmpty
56+ , empty
57+ , cat
58+ , hcat
59+ , hsep
60+ , vcat
61+ , vsep
62+ )
63+
64+where
65+import Data.DList (DList, fromList, toList, cons, singleton)
66+import Data.List (intercalate)
67+import Data.Monoid
68+import Data.String
69+import Control.Monad.State
70+import Data.Char (isSpace)
71+
72+data Monoid a =>
73+ RenderState a = RenderState{
74+ output :: [a] -- ^ In reverse order
75+ , prefix :: String
76+ , usePrefix :: Bool
77+ , lineLength :: Maybe Int -- ^ 'Nothing' means no wrapping
78+ , column :: Int
79+ , newlines :: Int -- ^ Number of preceding newlines
80+ }
81+
82+type DocState a = State (RenderState a) ()
83+
84+data D = Text Int String
85+ | Block Int [String]
86+ | Prefixed String Doc
87+ | Flush Doc
88+ | BreakingSpace
89+ | CarriageReturn
90+ | NewLine
91+ | BlankLine
92+ deriving (Show)
93+
94+newtype Doc = Doc { unDoc :: DList D }
95+ deriving (Monoid)
96+
97+instance Show Doc where
98+ show = render Nothing
99+
100+instance IsString Doc where
101+ fromString = text
102+
103+-- | True if the document is empty.
104+isEmpty :: Doc -> Bool
105+isEmpty = null . toList . unDoc
106+
107+-- | The empty document.
108+empty :: Doc
109+empty = mempty
110+
111+-- | @a <> b@ is the result of concatenating @a@ with @b@.
112+(<>) :: Doc -> Doc -> Doc
113+(<>) = mappend
114+
115+-- | Concatenate a list of 'Doc's.
116+cat :: [Doc] -> Doc
117+cat = mconcat
118+
119+-- | Same as 'cat'.
120+hcat :: [Doc] -> Doc
121+hcat = mconcat
122+
123+-- | Concatenate a list of 'Doc's, putting breakable spaces
124+-- between them.
125+(<+>) :: Doc -> Doc -> Doc
126+(<+>) x y = if isEmpty x
127+ then y
128+ else if isEmpty y
129+ then x
130+ else x <> space <> y
131+
132+-- | Same as 'cat', but putting breakable spaces between the
133+-- 'Doc's.
134+hsep :: [Doc] -> Doc
135+hsep = foldr (<+>) empty
136+
137+-- | @a $$ b@ puts @a@ above @b@.
138+($$) :: Doc -> Doc -> Doc
139+($$) x y = if isEmpty x
140+ then y
141+ else if isEmpty y
142+ then x
143+ else x <> cr <> y
144+
145+-- | @a $$ b@ puts @a@ above @b@, with a blank line between.
146+($+$) :: Doc -> Doc -> Doc
147+($+$) x y = if isEmpty x
148+ then y
149+ else if isEmpty y
150+ then x
151+ else x <> blankline <> y
152+
153+-- | List version of '$$'.
154+vcat :: [Doc] -> Doc
155+vcat = foldr ($$) empty
156+
157+-- | List version of '$+$'.
158+vsep :: [Doc] -> Doc
159+vsep = foldr ($+$) empty
160+
161+outp :: (IsString a, Monoid a)
162+ => Int -> String -> DocState a
163+outp off s | off <= 0 = do
164+ st' <- get
165+ let rawpref = prefix st'
166+ when (column st' == 0 && usePrefix st' && not (null rawpref)) $ do
167+ let pref = reverse $ dropWhile isSpace $ reverse rawpref
168+ modify $ \st -> st{ output = fromString pref : output st
169+ , column = column st + length pref }
170+ when (off < 0) $ do
171+ modify $ \st -> st { output = fromString s : output st
172+ , column = 0
173+ , newlines = newlines st + 1 }
174+outp off s = do
175+ st' <- get
176+ let pref = prefix st'
177+ when (column st' == 0 && usePrefix st' && not (null pref)) $ do
178+ modify $ \st -> st{ output = fromString pref : output st
179+ , column = column st + length pref }
180+ modify $ \st -> st{ output = fromString s : output st
181+ , column = column st + off
182+ , newlines = 0 }
183+
184+-- | Renders a 'Doc'. @render (Just n)@ will use
185+-- a line length of @n@ to reflow text on breakable spaces.
186+-- @render Nothing@ will not reflow text.
187+render :: (Monoid a, IsString a)
188+ => Maybe Int -> Doc -> a
189+render linelen doc = fromString . mconcat . reverse . output $
190+ execState (renderDoc doc) startingState
191+ where startingState = RenderState{
192+ output = mempty
193+ , prefix = ""
194+ , usePrefix = True
195+ , lineLength = linelen
196+ , column = 0
197+ , newlines = 2 }
198+
199+renderDoc :: (IsString a, Monoid a)
200+ => Doc -> DocState a
201+renderDoc = renderList . toList . unDoc
202+
203+renderList :: (IsString a, Monoid a)
204+ => [D] -> DocState a
205+renderList [] = return ()
206+renderList (Text off s : xs) = do
207+ outp off s
208+ renderList xs
209+
210+renderList (Prefixed pref d : xs) = do
211+ st <- get
212+ let oldPref = prefix st
213+ put st{ prefix = prefix st ++ pref }
214+ renderDoc d
215+ modify $ \s -> s{ prefix = oldPref }
216+ renderList xs
217+
218+renderList (Flush d : xs) = do
219+ st <- get
220+ let oldUsePrefix = usePrefix st
221+ put st{ usePrefix = False }
222+ renderDoc d
223+ modify $ \s -> s{ usePrefix = oldUsePrefix }
224+ renderList xs
225+
226+renderList (BlankLine : xs) = do
227+ st <- get
228+ case output st of
229+ _ | newlines st > 1 || null xs -> return ()
230+ _ | column st == 0 -> do
231+ outp (-1) "\n"
232+ _ -> do
233+ outp (-1) "\n"
234+ outp (-1) "\n"
235+ renderList xs
236+
237+renderList (CarriageReturn : xs) = do
238+ st <- get
239+ if newlines st > 0 || null xs
240+ then renderList xs
241+ else do
242+ outp (-1) "\n"
243+ renderList xs
244+
245+renderList (NewLine : xs) = do
246+ outp (-1) "\n"
247+ renderList xs
248+
249+renderList (BreakingSpace : xs) = do
250+ let isText (Text _ _) = True
251+ isText (Block _ _) = True
252+ isText _ = False
253+ let isBreakingSpace BreakingSpace = True
254+ isBreakingSpace _ = False
255+ let xs' = dropWhile isBreakingSpace xs
256+ let next = takeWhile isText xs'
257+ st <- get
258+ let off = sum $ map offsetOf next
259+ case lineLength st of
260+ Just l | column st + 1 + off > l -> do
261+ outp (-1) "\n"
262+ renderList xs'
263+ _ -> do
264+ outp 1 " "
265+ renderList xs'
266+
267+renderList (b1@Block{} : b2@Block{} : xs) =
268+ renderList (mergeBlocks False b1 b2 : xs)
269+
270+renderList (b1@Block{} : BreakingSpace : b2@Block{} : xs) =
271+ renderList (mergeBlocks True b1 b2 : xs)
272+
273+renderList (Block width lns : xs) = do
274+ st <- get
275+ let oldPref = prefix st
276+ case column st - length oldPref of
277+ n | n > 0 -> modify $ \s -> s{ prefix = oldPref ++ replicate n ' ' }
278+ _ -> return ()
279+ renderDoc $ blockToDoc width lns
280+ modify $ \s -> s{ prefix = oldPref }
281+ renderList xs
282+
283+mergeBlocks :: Bool -> D -> D -> D
284+mergeBlocks addSpace (Block w1 lns1) (Block w2 lns2) =
285+ Block (w1 + w2 + if addSpace then 1 else 0) $
286+ zipWith (\l1 l2 -> pad w1 l1 ++ l2) (lns1 ++ empties) (map sp lns2 ++ empties)
287+ where empties = replicate (abs $ length lns1 - length lns2) ""
288+ pad n s = s ++ replicate (n - length s) ' '
289+ sp "" = ""
290+ sp xs = if addSpace then (' ' : xs) else xs
291+mergeBlocks _ _ _ = error "mergeBlocks tried on non-Block!"
292+
293+blockToDoc :: Int -> [String] -> Doc
294+blockToDoc _ lns = text $ intercalate "\n" lns
295+
296+offsetOf :: D -> Int
297+offsetOf (Text o _) = o
298+offsetOf (Block w _) = w
299+offsetOf BreakingSpace = 1
300+offsetOf _ = 0
301+
302+-- | A literal string.
303+text :: String -> Doc
304+text = Doc . toChunks
305+ where toChunks :: String -> DList D
306+ toChunks [] = mempty
307+ toChunks s = case break (=='\n') s of
308+ ([], _:ys) -> NewLine `cons` toChunks ys
309+ (xs, _:ys) -> Text (length xs) xs `cons`
310+ NewLine `cons` toChunks ys
311+ (xs, []) -> singleton $ Text (length xs) xs
312+
313+-- | A character.
314+char :: Char -> Doc
315+char c = text [c]
316+
317+-- | A breaking (reflowable) space.
318+space :: Doc
319+space = Doc $ singleton BreakingSpace
320+
321+-- | A carriage return. Does nothing if we're at the beginning of
322+-- a line; otherwise inserts a newline.
323+cr :: Doc
324+cr = Doc $ singleton CarriageReturn
325+
326+-- | Inserts a blank line unless one exists already.
327+-- (@blankline <> blankline@ has the same effect as @blankline@.
328+-- If you want multiple blank lines, use @text "\\n\\n"@.
329+blankline :: Doc
330+blankline = Doc $ singleton BlankLine
331+
332+-- | Uses the specified string as a prefix for every line of
333+-- the enclosed document (except the first, if not at the beginning
334+-- of the line).
335+prefixed :: String -> Doc -> Doc
336+prefixed pref doc = Doc $ singleton $ Prefixed pref doc
337+
338+-- | Makes a 'Doc' flush against the left margin.
339+flush :: Doc -> Doc
340+flush doc = Doc $ singleton $ Flush doc
341+
342+-- | Indents a 'Doc' by the specified number of spaces.
343+nest :: Int -> Doc -> Doc
344+nest ind = prefixed (replicate ind ' ')
345+
346+-- | A hanging indent. @hang ind start doc@ prints @start@,
347+-- then @doc@, leaving an indent of @ind@ spaces on every
348+-- line but the first.
349+hang :: Int -> Doc -> Doc -> Doc
350+hang ind start doc = start <> nest ind doc
351+
352+-- | Makes a 'Doc' non-reflowable.
353+nowrap :: Doc -> Doc
354+nowrap doc = Doc $ fromList $ map replaceSpace $ toList $ unDoc doc
355+ where replaceSpace BreakingSpace = Text 1 " "
356+ replaceSpace x = x
357+
358+-- | Returns the width of a 'Doc'.
359+offset :: Doc -> Int
360+offset d = case map length . lines . render Nothing $ d of
361+ [] -> 0
362+ os -> maximum os
363+
364+block :: (String -> String) -> Int -> Doc -> Doc
365+block filler width = Doc . singleton . Block width .
366+ map filler . chop width . render (Just width)
367+
368+-- | @lblock n d@ is a block of width @n@ characters, with
369+-- text derived from @d@ and aligned to the left.
370+lblock :: Int -> Doc -> Doc
371+lblock = block id
372+
373+-- | Like 'lblock' but aligned to the right.
374+rblock :: Int -> Doc -> Doc
375+rblock w = block (\s -> replicate (w - length s) ' ' ++ s) w
376+
377+-- | Like 'lblock' but aligned centered.
378+cblock :: Int -> Doc -> Doc
379+cblock w = block (\s -> replicate ((w - length s) `div` 2) ' ' ++ s) w
380+
381+-- | Returns the height of a block or other 'Doc'.
382+height :: Doc -> Int
383+height = length . lines . render Nothing
384+
385+chop :: Int -> String -> [String]
386+chop _ [] = []
387+chop n cs = case break (=='\n') cs of
388+ (xs, ys) -> if len <= n
389+ then case ys of
390+ [] -> [xs]
391+ (_:[]) -> [xs, ""]
392+ (_:zs) -> xs : chop n zs
393+ else take n xs : chop n (drop n xs ++ ys)
394+ where len = length xs
395+
src/Text/Pandoc/Shared.hs+3
@@ -398,6 +398,7 @@ stringify = queryWith go
398398 go Space = " "
399399 go (Str x) = x
400400 go (Code x) = x
401+ go (Math _ x) = x
401402 go _ = ""
402403
403404-- | Change final list item from @Para@ to @Plain@ if the list contains
@@ -560,6 +561,7 @@ data WriterOptions = WriterOptions
560561 , writerStrictMarkdown :: Bool -- ^ Use strict markdown syntax
561562 , writerReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
562563 , writerWrapText :: Bool -- ^ Wrap text to line length
564+ , writerColumns :: Int -- ^ Characters in a line (for text wrapping)
563565 , writerLiterateHaskell :: Bool -- ^ Write as literate haskell
564566 , writerEmailObfuscation :: ObfuscationMethod -- ^ How to obfuscate emails
565567 , writerIdentifierPrefix :: String -- ^ Prefix for section & note ids in HTML
@@ -588,6 +590,7 @@ defaultWriterOptions =
588590 , writerStrictMarkdown = False
589591 , writerReferenceLinks = False
590592 , writerWrapText = True
593+ , writerColumns = 72
591594 , writerLiterateHaskell = False
592595 , writerEmailObfuscation = JavascriptObfuscation
593596 , writerIdentifierPrefix = ""
src/Text/Pandoc/Writers/Markdown.hs+157−135
@@ -1,3 +1,4 @@
1+{-# LANGUAGE OverloadedStrings #-}
12{-
23Copyright (C) 2006-2010 John MacFarlane <jgm@berkeley.edu>
34
@@ -33,11 +34,10 @@ module Text.Pandoc.Writers.Markdown (writeMarkdown, writePlain) where
3334import Text.Pandoc.Definition
3435import Text.Pandoc.Templates (renderTemplate)
3536import Text.Pandoc.Shared
36−import Text.Pandoc.Parsing
37−import Text.Pandoc.Blocks
37+import Text.Pandoc.Parsing hiding (blankline)
3838import Text.ParserCombinators.Parsec ( runParser, GenParser )
3939import Data.List ( group, isPrefixOf, find, intersperse, transpose )
40−import Text.PrettyPrint.HughesPJ hiding ( Str )
40+import Text.Pandoc.Pretty
4141import Control.Monad.State
4242
4343type Notes = [[Block]]
@@ -64,22 +64,21 @@ writePlain opts document =
6464
6565plainify :: Pandoc -> Pandoc
6666plainify = processWith go
67− where go :: [Inline] -> [Inline]
68− go (Emph xs : ys) = go xs ++ go ys
69− go (Strong xs : ys) = go xs ++ go ys
70− go (Strikeout xs : ys) = go xs ++ go ys
71− go (Superscript xs : ys) = go xs ++ go ys
72− go (Subscript xs : ys) = go xs ++ go ys
73− go (SmallCaps xs : ys) = go xs ++ go ys
74− go (Code s : ys) = Str s : go ys
75− go (Math _ s : ys) = Str s : go ys
76− go (TeX _ : ys) = Str "" : go ys
77− go (HtmlInline _ : ys) = Str "" : go ys
78− go (Link xs _ : ys) = go xs ++ go ys
79− go (Image _ _ : ys) = go ys
80− go (Cite _ cits : ys) = go cits ++ go ys
81− go (x : ys) = x : go ys
82− go [] = []
67+ where go :: Inline -> Inline
68+ go (Emph xs) = SmallCaps xs
69+ go (Strong xs) = SmallCaps xs
70+ go (Strikeout xs) = SmallCaps xs
71+ go (Superscript xs) = SmallCaps xs
72+ go (Subscript xs) = SmallCaps xs
73+ go (SmallCaps xs) = SmallCaps xs
74+ go (Code s) = Str s
75+ go (Math _ s) = Str s
76+ go (TeX _) = Str ""
77+ go (HtmlInline _) = Str ""
78+ go (Link xs _) = SmallCaps xs
79+ go (Image xs _) = SmallCaps $ [Str "["] ++ xs ++ [Str "]"]
80+ go (Cite _ cits) = SmallCaps cits
81+ go x = x
8382
8483-- | Return markdown representation of document.
8584pandocToMarkdown :: WriterOptions -> Pandoc -> State WriterState String
@@ -97,15 +96,19 @@ pandocToMarkdown opts (Pandoc (Meta title authors date) blocks) = do
9796 notes' <- notesToMarkdown opts (reverse $ stNotes st)
9897 st' <- get -- note that the notes may contain refs
9998 refs' <- refsToMarkdown opts (reverse $ stRefs st')
100− let main = render $ foldl ($+$) empty $ [body, notes', refs']
99+ let colwidth = if writerWrapText opts
100+ then Just $ writerColumns opts
101+ else Nothing
102+ let main = render colwidth $ body <>
103+ blankline <> notes' <> blankline <> refs'
101104 let context = writerVariables opts ++
102− [ ("toc", render toc)
105+ [ ("toc", render colwidth toc)
103106 , ("body", main)
104− , ("title", render title')
105− , ("date", render date')
107+ , ("title", render colwidth title')
108+ , ("date", render colwidth date')
106109 ] ++
107110 [ ("titleblock", "yes") | titleblock ] ++
108− [ ("author", render a) | a <- authors' ]
111+ [ ("author", render colwidth a) | a <- authors' ]
109112 if writerStandalone opts
110113 then return $ renderTemplate context $ writerTemplate opts
111114 else return main
@@ -113,29 +116,36 @@ pandocToMarkdown opts (Pandoc (Meta title authors date) blocks) = do
113116-- | Return markdown representation of reference key table.
114117refsToMarkdown :: WriterOptions -> Refs -> State WriterState Doc
115118refsToMarkdown opts refs = mapM (keyToMarkdown opts) refs >>= return . vcat
116−
119+
117120-- | Return markdown representation of a reference key.
118121keyToMarkdown :: WriterOptions
119122 -> ([Inline], (String, String))
120123 -> State WriterState Doc
121124keyToMarkdown opts (label, (src, tit)) = do
122125 label' <- inlineListToMarkdown opts label
123− let tit' = if null tit then empty else text $ " \"" ++ tit ++ "\""
124− return $ text " " <> char '[' <> label' <> char ']' <> text ": " <>
125− text src <> tit'
126+ let tit' = if null tit
127+ then empty
128+ else space <> "\"" <> text tit <> "\""
129+ return $ nest 2 $ hang 2
130+ ("[" <> label' <> "]:" <> space) (text src <> tit')
126131
127132-- | Return markdown representation of notes.
128133notesToMarkdown :: WriterOptions -> [[Block]] -> State WriterState Doc
129134notesToMarkdown opts notes =
130− mapM (\(num, note) -> noteToMarkdown opts num note) (zip [1..] notes) >>=
131− return . vcat
135+ mapM (\(num, note) -> noteToMarkdown opts num note) (zip [1..] notes) >>=
136+ return . vsep
132137
133138-- | Return markdown representation of a note.
134139noteToMarkdown :: WriterOptions -> Int -> [Block] -> State WriterState Doc
135140noteToMarkdown opts num blocks = do
136141 contents <- blockListToMarkdown opts blocks
137− let marker = text "[^" <> text (show num) <> text "]:"
138− return $ hang' marker (writerTabStop opts) contents
142+ let num' = text $ show num
143+ let marker = text "[^" <> num' <> text "]:"
144+ let markerSize = 4 + offset num'
145+ let spacer = case writerTabStop opts - markerSize of
146+ n | n > 0 -> text $ replicate n ' '
147+ _ -> text " "
148+ return $ hang (writerTabStop opts) (marker <> spacer) contents
139149
140150-- | Escape special characters for Markdown.
141151escapeString :: String -> String
@@ -170,134 +180,131 @@ olMarker = do (start, style', delim) <- anyOrderedListMarker
170180
171181-- | True if string begins with an ordered list marker
172182beginsWithOrderedListMarker :: String -> Bool
173−beginsWithOrderedListMarker str =
174− case runParser olMarker defaultParserState "para start" str of
175− Left _ -> False
183+beginsWithOrderedListMarker str =
184+ case runParser olMarker defaultParserState "para start" (take 10 str) of
185+ Left _ -> False
176186 Right _ -> True
177187
178−wrappedMarkdown :: WriterOptions -> [Inline] -> State WriterState Doc
179−wrappedMarkdown opts inlines = do
180− let chunks = splitBy LineBreak inlines
181− let chunks' = if null chunks
182− then []
183− else (map (++ [Str " "]) $ init chunks) ++ [last chunks]
184− lns <- mapM (wrapIfNeeded opts (inlineListToMarkdown opts)) chunks'
185− return $ vcat lns
186−
187188-- | Convert Pandoc block element to markdown.
188189blockToMarkdown :: WriterOptions -- ^ Options
189190 -> Block -- ^ Block element
190191 -> State WriterState Doc
191192blockToMarkdown _ Null = return empty
192−blockToMarkdown opts (Plain inlines) =
193− wrappedMarkdown opts inlines
193+blockToMarkdown opts (Plain inlines) = do
194+ contents <- inlineListToMarkdown opts inlines
195+ return $ contents <> cr
194196blockToMarkdown opts (Para inlines) = do
195− contents <- wrappedMarkdown opts inlines
197+ contents <- inlineListToMarkdown opts inlines
196198 -- escape if para starts with ordered list marker
197− let esc = if (not (writerStrictMarkdown opts)) &&
198− beginsWithOrderedListMarker (render contents)
199− then char '\\'
200− else empty
201− return $ esc <> contents <> text "\n"
199+ st <- get
200+ let esc = if (not (writerStrictMarkdown opts)) &&
201+ not (stPlain st) &&
202+ beginsWithOrderedListMarker (render Nothing contents)
203+ then text "\\"
204+ else empty
205+ return $ esc <> contents <> blankline
202206blockToMarkdown _ (RawHtml str) = do
203207 st <- get
204208 if stPlain st
205209 then return empty
206− else return $ text str
207−blockToMarkdown _ HorizontalRule = return $ text "\n* * * * *\n"
210+ else return $ text str <> text "\n"
211+blockToMarkdown _ HorizontalRule =
212+ return $ blankline <> text "* * * * *" <> blankline
208213blockToMarkdown opts (Header level inlines) = do
209214 contents <- inlineListToMarkdown opts inlines
210215 st <- get
211216 -- use setext style headers if in literate haskell mode.
212217 -- ghc interprets '#' characters in column 1 as line number specifiers.
213218 if writerLiterateHaskell opts || stPlain st
214− then let len = length $ render contents
215− in return $ contents <> text "\n" <>
216− case level of
217− 1 -> text $ replicate len '=' ++ "\n"
218− 2 -> text $ replicate len '-' ++ "\n"
219− _ -> empty
220− else return $ text ((replicate level '#') ++ " ") <> contents <> text "\n"
221−blockToMarkdown opts (CodeBlock (_,classes,_) str) | "haskell" `elem` classes &&
222− "literate" `elem` classes &&
223− writerLiterateHaskell opts =
224− return $ (vcat $ map (text "> " <>) $ map text (lines str)) <> text "\n"
219+ then let len = offset contents
220+ in return $ contents <> cr <>
221+ (case level of
222+ 1 -> text $ replicate len '='
223+ 2 -> text $ replicate len '-'
224+ _ -> empty) <> blankline
225+ else return $
226+ text ((replicate level '#') ++ " ") <> contents <> blankline
227+blockToMarkdown opts (CodeBlock (_,classes,_) str)
228+ | "haskell" `elem` classes && "literate" `elem` classes &&
229+ writerLiterateHaskell opts =
230+ return $ prefixed "> " (text str) <> blankline
225231blockToMarkdown opts (CodeBlock _ str) = return $
226− (nest (writerTabStop opts) $ vcat $ map text (lines str)) <> text "\n"
232+ nest (writerTabStop opts) (text str) <> blankline
227233blockToMarkdown opts (BlockQuote blocks) = do
228234 st <- get
229235 -- if we're writing literate haskell, put a space before the bird tracks
230236 -- so they won't be interpreted as lhs...
231237 let leader = if writerLiterateHaskell opts
232− then text . (" > " ++)
238+ then " > "
233239 else if stPlain st
234− then text . (" " ++)
235− else text . ("> " ++)
240+ then " "
241+ else "> "
236242 contents <- blockListToMarkdown opts blocks
237− return $ (vcat $ map leader $ lines $ render contents) <>
238− text "\n"
243+ return $ (prefixed leader contents) <> blankline
239244blockToMarkdown opts (Table caption aligns widths headers rows) = do
240245 caption' <- inlineListToMarkdown opts caption
241246 let caption'' = if null caption
242247 then empty
243− else text "" $+$ (text ": " <> caption')
248+ else blankline <> ": " <> caption' <> blankline
244249 headers' <- mapM (blockListToMarkdown opts) headers
245250 let alignHeader alignment = case alignment of
246− AlignLeft -> leftAlignBlock
247− AlignCenter -> centerAlignBlock
248− AlignRight -> rightAlignBlock
249− AlignDefault -> leftAlignBlock
251+ AlignLeft -> lblock
252+ AlignCenter -> cblock
253+ AlignRight -> rblock
254+ AlignDefault -> lblock
250255 rawRows <- mapM (mapM (blockListToMarkdown opts)) rows
251256 let isSimple = all (==0) widths
252− let numChars = maximum . map (length . render)
257+ let numChars = maximum . map offset
253258 let widthsInChars =
254259 if isSimple
255260 then map ((+2) . numChars) $ transpose (headers' : rawRows)
256− else map (floor . (78 *)) widths
257− let makeRow = hsepBlocks . (zipWith alignHeader aligns) .
258− (zipWith docToBlock widthsInChars)
261+ else map (floor . (fromIntegral (writerColumns opts) *)) widths
262+ let makeRow = hcat . intersperse (lblock 1 (text " ")) .
263+ (zipWith3 alignHeader aligns widthsInChars)
259264 let rows' = map makeRow rawRows
260265 let head' = makeRow headers'
261− let maxRowHeight = maximum $ map heightOfBlock (head':rows')
262− let underline = hsep $
263− map (\width -> text $ replicate width '-') widthsInChars
266+ let maxRowHeight = maximum $ map height (head':rows')
267+ let underline = cat $ intersperse (text " ") $
268+ map (\width -> text (replicate width '-')) widthsInChars
264269 let border = if maxRowHeight > 1
265− then text $ replicate (sum widthsInChars + (length widthsInChars - 1)) '-'
270+ then text (replicate (sum widthsInChars +
271+ length widthsInChars - 1) '-')
266272 else if all null headers
267273 then underline
268274 else empty
269275 let head'' = if all null headers
270276 then empty
271− else border $+$ blockToDoc head'
272− let spacer = if maxRowHeight > 1
273− then text ""
274− else empty
275− let body = vcat $ intersperse spacer $ map blockToDoc rows'
277+ else border <> cr <> head'
278+ let body = if maxRowHeight > 1
279+ then vsep rows'
280+ else vcat rows'
276281 let bottom = if all null headers
277282 then underline
278283 else border
279− return $ (nest 2 $ head'' $+$ underline $+$ body $+$
280− bottom $+$ caption'') <> text "\n"
284+ return $ nest 2 $ head'' $$ underline $$ body $$
285+ bottom $$ blankline $$ caption'' $$ blankline
281286blockToMarkdown opts (BulletList items) = do
282287 contents <- mapM (bulletListItemToMarkdown opts) items
283− return $ (vcat contents) <> text "\n"
288+ return $ cat contents <> blankline
284289blockToMarkdown opts (OrderedList attribs items) = do
285290 let markers = orderedListMarkers attribs
286291 let markers' = map (\m -> if length m < 3
287292 then m ++ replicate (3 - length m) ' '
288− else m) markers
293+ else m) markers
289294 contents <- mapM (\(item, num) -> orderedListItemToMarkdown opts item num) $
290− zip markers' items
291− return $ (vcat contents) <> text "\n"
295+ zip markers' items
296+ return $ cat contents <> blankline
292297blockToMarkdown opts (DefinitionList items) = do
293298 contents <- mapM (definitionListItemToMarkdown opts) items
294− return $ (vcat contents) <> text "\n"
299+ return $ cat contents <> blankline
295300
296301-- | Convert bullet list item (list of blocks) to markdown.
297302bulletListItemToMarkdown :: WriterOptions -> [Block] -> State WriterState Doc
298303bulletListItemToMarkdown opts items = do
299304 contents <- blockListToMarkdown opts items
300− return $ hang' (text "- ") (writerTabStop opts) contents
305+ let sps = replicate (writerTabStop opts - 2) ' '
306+ let start = text ('-' : ' ' : sps)
307+ return $ hang (writerTabStop opts) start $ contents <> cr
301308
302309-- | Convert ordered list item (a list of blocks) to markdown.
303310orderedListItemToMarkdown :: WriterOptions -- ^ options
@@ -306,8 +313,11 @@ orderedListItemToMarkdown :: WriterOptions -- ^ options
306313 -> State WriterState Doc
307314orderedListItemToMarkdown opts marker items = do
308315 contents <- blockListToMarkdown opts items
309− return $ hsep [nest (min (3 - length marker) 0) (text marker),
310− nest (writerTabStop opts) contents]
316+ let sps = case length marker - writerTabStop opts of
317+ n | n > 0 -> text $ replicate n ' '
318+ _ -> text " "
319+ let start = text marker <> sps
320+ return $ hang (writerTabStop opts) start $ contents <> cr
311321
312322-- | Convert definition list item (label, list of blocks) to markdown.
313323definitionListItemToMarkdown :: WriterOptions
@@ -317,17 +327,20 @@ definitionListItemToMarkdown opts (label, defs) = do
317327 labelText <- inlineListToMarkdown opts label
318328 let tabStop = writerTabStop opts
319329 st <- get
320− let leader = if stPlain st then empty else text " ~"
321− contents <- liftM vcat $
322− mapM (liftM ((leader $$) . nest tabStop . vcat) . mapM (blockToMarkdown opts)) defs
323− return $ labelText $+$ contents
330+ let leader = if stPlain st then " " else " ~"
331+ let sps = case writerTabStop opts - 3 of
332+ n | n > 0 -> text $ replicate n ' '
333+ _ -> text " "
334+ defs' <- mapM (mapM (blockToMarkdown opts)) defs
335+ let contents = vcat $ map (\d -> hang tabStop (leader <> sps) $ vcat d <> cr) defs'
336+ return $ labelText <> cr <> contents <> cr
324337
325338-- | Convert list of Pandoc block elements to markdown.
326339blockListToMarkdown :: WriterOptions -- ^ Options
327340 -> [Block] -- ^ List of block elements
328341 -> State WriterState Doc
329342blockListToMarkdown opts blocks =
330− mapM (blockToMarkdown opts) blocks >>= return . vcat
343+ mapM (blockToMarkdown opts) blocks >>= return . cat
331344
332345-- | Get reference for target; if none exists, create unique one and return.
333346-- Prefer label if possible; otherwise, generate a unique key.
@@ -350,38 +363,43 @@ getReference label (src, tit) = do
350363-- | Convert list of Pandoc inline elements to markdown.
351364inlineListToMarkdown :: WriterOptions -> [Inline] -> State WriterState Doc
352365inlineListToMarkdown opts lst =
353− mapM (inlineToMarkdown opts) lst >>= return . hcat
366+ mapM (inlineToMarkdown opts) lst >>= return . cat
367+
368+escapeSpaces :: Inline -> Inline
369+escapeSpaces (Str s) = Str $ substitute " " "\\ " s
370+escapeSpaces Space = Str "\\ "
371+escapeSpaces x = x
354372
355373-- | Convert Pandoc inline element to markdown.
356374inlineToMarkdown :: WriterOptions -> Inline -> State WriterState Doc
357375inlineToMarkdown opts (Emph lst) = do
358376 contents <- inlineListToMarkdown opts lst
359− return $ char '*' <> contents <> char '*'
377+ return $ "*" <> contents <> "*"
360378inlineToMarkdown opts (Strong lst) = do
361379 contents <- inlineListToMarkdown opts lst
362− return $ text "**" <> contents <> text "**"
380+ return $ "**" <> contents <> "**"
363381inlineToMarkdown opts (Strikeout lst) = do
364382 contents <- inlineListToMarkdown opts lst
365− return $ text "~~" <> contents <> text "~~"
383+ return $ "~~" <> contents <> "~~"
366384inlineToMarkdown opts (Superscript lst) = do
367− contents <- inlineListToMarkdown opts lst
368− let contents' = text $ substitute " " "\\ " $ render contents
369− return $ char '^' <> contents' <> char '^'
385+ let lst' = processWith escapeSpaces lst
386+ contents <- inlineListToMarkdown opts lst'
387+ return $ "^" <> contents <> "^"
370388inlineToMarkdown opts (Subscript lst) = do
371− contents <- inlineListToMarkdown opts lst
372− let contents' = text $ substitute " " "\\ " $ render contents
373− return $ char '~' <> contents' <> char '~'
389+ let lst' = processWith escapeSpaces lst
390+ contents <- inlineListToMarkdown opts lst'
391+ return $ "~" <> contents <> "~"
374392inlineToMarkdown opts (SmallCaps lst) = inlineListToMarkdown opts lst
375393inlineToMarkdown opts (Quoted SingleQuote lst) = do
376394 contents <- inlineListToMarkdown opts lst
377− return $ char '‘' <> contents <> char '’'
395+ return $ "‘" <> contents <> "’"
378396inlineToMarkdown opts (Quoted DoubleQuote lst) = do
379397 contents <- inlineListToMarkdown opts lst
380− return $ char '“' <> contents <> char '”'
381−inlineToMarkdown _ EmDash = return $ char '\8212'
382−inlineToMarkdown _ EnDash = return $ char '\8211'
383−inlineToMarkdown _ Apostrophe = return $ char '\8217'
384−inlineToMarkdown _ Ellipses = return $ char '\8230'
398+ return $ "“" <> contents <> "”"
399+inlineToMarkdown _ EmDash = return "\8212"
400+inlineToMarkdown _ EnDash = return "\8211"
401+inlineToMarkdown _ Apostrophe = return "\8217"
402+inlineToMarkdown _ Ellipses = return "\8230"
385403inlineToMarkdown _ (Code str) =
386404 let tickGroups = filter (\s -> '`' `elem` s) $ group str
387405 longest = if null tickGroups
@@ -395,25 +413,27 @@ inlineToMarkdown _ (Str str) = do
395413 if stPlain st
396414 then return $ text str
397415 else return $ text $ escapeString str
398−inlineToMarkdown _ (Math InlineMath str) = return $ char '$' <> text str <> char '$'
399−inlineToMarkdown _ (Math DisplayMath str) = return $ text "$$" <> text str <> text "$$"
416+inlineToMarkdown _ (Math InlineMath str) =
417+ return $ "$" <> text str <> "$"
418+inlineToMarkdown _ (Math DisplayMath str) =
419+ return $ "$$" <> text str <> "$$"
400420inlineToMarkdown _ (TeX str) = return $ text str
401421inlineToMarkdown _ (HtmlInline str) = return $ text str
402−inlineToMarkdown _ (LineBreak) = return $ text " \n"
403−inlineToMarkdown _ Space = return $ char ' '
422+inlineToMarkdown _ (LineBreak) = return $ " " <> cr
423+inlineToMarkdown _ Space = return space
404424inlineToMarkdown opts (Cite (c:cs) lst)
405425 | writerCiteMethod opts == Citeproc = inlineListToMarkdown opts lst
406426 | citationMode c == AuthorInText = do
407427 suffs <- inlineListToMarkdown opts $ citationSuffix c
408428 rest <- mapM convertOne cs
409429 let inbr = suffs <+> joincits rest
410− br = if isEmpty inbr then empty else brackets inbr
430+ br = if isEmpty inbr then empty else char '[' <> inbr <> char ']'
411431 return $ text ("@" ++ citationId c) <+> br
412432 | otherwise = do
413433 cits <- mapM convertOne (c:cs)
414434 return $ text "[" <> joincits cits <> text "]"
415435 where
416− joincits = hcat . punctuate (text "; ") . filter (not . isEmpty)
436+ joincits = hcat . intersperse (text "; ") . filter (not . isEmpty)
417437 convertOne Citation { citationId = k
418438 , citationPrefix = pinlines
419439 , citationSuffix = sinlines
@@ -431,7 +451,9 @@ inlineToMarkdown opts (Cite (c:cs) lst)
431451inlineToMarkdown _ (Cite _ _) = return $ text ""
432452inlineToMarkdown opts (Link txt (src', tit)) = do
433453 linktext <- inlineListToMarkdown opts txt
434− let linktitle = if null tit then empty else text $ " \"" ++ tit ++ "\""
454+ let linktitle = if null tit
455+ then empty
456+ else text $ " \"" ++ tit ++ "\""
435457 let src = unescapeURI src'
436458 let srcSuffix = if isPrefixOf "mailto:" src then drop 7 src else src
437459 let useRefLinks = writerReferenceLinks opts
@@ -439,24 +461,24 @@ inlineToMarkdown opts (Link txt (src', tit)) = do
439461 ref <- if useRefLinks then getReference txt (src, tit) else return []
440462 reftext <- inlineListToMarkdown opts ref
441463 return $ if useAuto
442− then char '<' <> text srcSuffix <> char '>'
464+ then "<" <> text srcSuffix <> ">"
443465 else if useRefLinks
444− then let first = char '[' <> linktext <> char ']'
466+ then let first = "[" <> linktext <> "]"
445467 second = if txt == ref
446− then text "[]"
447− else char '[' <> reftext <> char ']'
468+ then "[]"
469+ else "[" <> reftext <> "]"
448470 in first <> second
449− else char '[' <> linktext <> char ']' <>
450− char '(' <> text src <> linktitle <> char ')'
471+ else "[" <> linktext <> "](" <>
472+ text src <> linktitle <> ")"
451473inlineToMarkdown opts (Image alternate (source, tit)) = do
452474 let txt = if (null alternate) || (alternate == [Str ""]) ||
453475 (alternate == [Str source]) -- to prevent autolinks
454476 then [Str "image"]
455477 else alternate
456478 linkPart <- inlineToMarkdown opts (Link txt (unescapeURI source, tit))
457− return $ char '!' <> linkPart
479+ return $ "!" <> linkPart
458480inlineToMarkdown _ (Note contents) = do
459481 modify (\st -> st{ stNotes = contents : stNotes st })
460482 st <- get
461483 let ref = show $ (length $ stNotes st)
462− return $ text "[^" <> text ref <> char ']'
484+ return $ "[^" <> text ref <> "]"
src/Text/Pandoc/Writers/Org.hs+69−79
@@ -1,3 +1,4 @@
1+{-# LANGUAGE OverloadedStrings #-}
12{-
23Copyright (C) 2006-2010 Puneeth Chaganti <punchagan@gmail.com>
34
@@ -32,10 +33,9 @@ Org-Mode: <http://orgmode.org>
3233module Text.Pandoc.Writers.Org ( writeOrg) where
3334import Text.Pandoc.Definition
3435import Text.Pandoc.Shared
35−import Text.Pandoc.Blocks
36+import Text.Pandoc.Pretty
3637import Text.Pandoc.Templates (renderTemplate)
3738import Data.List ( intersect, intersperse, transpose )
38−import Text.PrettyPrint.HughesPJ hiding ( Str )
3939import Control.Monad.State
4040import Control.Applicative ( (<$>) )
4141
@@ -66,13 +66,16 @@ pandocToOrg (Pandoc (Meta tit auth dat) blocks) = do
6666 notes <- liftM (reverse . stNotes) get >>= notesToOrg
6767 -- note that the notes may contain refs, so we do them first
6868 hasMath <- liftM stHasMath get
69− let main = render $ foldl ($+$) empty $ [body, notes]
69+ let colwidth = if writerWrapText opts
70+ then Just $ writerColumns opts
71+ else Nothing
72+ let main = render colwidth $ foldl ($+$) empty $ [body, notes]
7073 let context = writerVariables opts ++
7174 [ ("body", main)
72− , ("title", render title)
73− , ("date", render date) ] ++
75+ , ("title", render Nothing title)
76+ , ("date", render Nothing date) ] ++
7477 [ ("math", "yes") | hasMath ] ++
75− [ ("author", render a) | a <- authors ]
78+ [ ("author", render Nothing a) | a <- authors ]
7679 if writerStandalone opts
7780 then return $ renderTemplate context $ writerTemplate opts
7881 else return main
@@ -81,22 +84,14 @@ pandocToOrg (Pandoc (Meta tit auth dat) blocks) = do
8184notesToOrg :: [[Block]] -> State WriterState Doc
8285notesToOrg notes =
8386 mapM (\(num, note) -> noteToOrg num note) (zip [1..] notes) >>=
84− return . vcat
87+ return . vsep
8588
8689-- | Return Org representation of a note.
8790noteToOrg :: Int -> [Block] -> State WriterState Doc
8891noteToOrg num note = do
8992 contents <- blockListToOrg note
90− let marker = text "[" <> text (show num) <> text "] "
91− return $ marker <> contents
92−
93−-- | Take list of inline elements and return wrapped doc.
94−wrappedOrg :: WriterOptions -> [Inline] -> State WriterState Doc
95−wrappedOrg opts inlines = do
96− lineBreakDoc <- inlineToOrg LineBreak
97− chunks <- mapM (wrapIfNeeded opts inlineListToOrg)
98− (splitBy LineBreak inlines)
99− return $ vcat $ intersperse lineBreakDoc chunks
93+ let marker = "[" ++ show num ++ "] "
94+ return $ hang (length marker) (text marker) contents
10095
10196-- | Escape special characters for Org.
10297escapeString :: String -> String
@@ -106,32 +101,28 @@ titleToOrg :: [Inline] -> State WriterState Doc
106101titleToOrg [] = return empty
107102titleToOrg lst = do
108103 contents <- inlineListToOrg lst
109− let titleName = text "#+TITLE: "
110− return $ titleName <> contents
104+ return $ "#+TITLE: " <> contents
111105
112106-- | Convert Pandoc block element to Org.
113107blockToOrg :: Block -- ^ Block element
114108 -> State WriterState Doc
115109blockToOrg Null = return empty
116−blockToOrg (Plain inlines) = do
117− opts <- get >>= (return . stOptions)
118− wrappedOrg opts inlines
110+blockToOrg (Plain inlines) = inlineListToOrg inlines
119111blockToOrg (Para [Image txt (src,tit)]) = do
120112 capt <- inlineListToOrg txt
121113 img <- inlineToOrg (Image txt (src,tit))
122− return $ text "#+CAPTION: " <> capt <> text "\n" $$ img
114+ return $ "#+CAPTION: " <> capt <> blankline <> img
123115blockToOrg (Para inlines) = do
124− opts <- get >>= (return . stOptions)
125− contents <- wrappedOrg opts inlines
126− return $ contents <> text "\n"
116+ contents <- inlineListToOrg inlines
117+ return $ contents <> blankline
127118blockToOrg (RawHtml str) =
128− return $ (text "\n#+BEGIN_HTML\n") $$ (nest 2 $ vcat $ map text (lines str))
129− $$ (text "\n#+END_HTML\n")
130−blockToOrg HorizontalRule = return $ text "--------------\n"
119+ return $ blankline $$ "#+BEGIN_HTML" $$
120+ nest 2 (text str) $$ "#+END_HTML" $$ blankline
121+blockToOrg HorizontalRule = return $ blankline $$ "--------------" $$ blankline
131122blockToOrg (Header level inlines) = do
132123 contents <- inlineListToOrg inlines
133124 let headerStr = text $ if level > 999 then " " else replicate level '*'
134− return $ headerStr <> text " " <> contents <> text "\n"
125+ return $ headerStr <> " " <> contents <> blankline
135126blockToOrg (CodeBlock (_,classes,_) str) = do
136127 opts <- stOptions <$> get
137128 let tabstop = writerTabStop opts
@@ -143,31 +134,30 @@ blockToOrg (CodeBlock (_,classes,_) str) = do
143134 let (beg, end) = if null at
144135 then ("#+BEGIN_EXAMPLE", "#+END_EXAMPLE")
145136 else ("#+BEGIN_SRC" ++ head at, "#+END_SRC")
146− return $ text beg $+$ (nest tabstop $ vcat $ map text (lines str))
147− $+$ text end
137+ return $ text beg $$ nest tabstop (text str) $$ text end $$ blankline
148138blockToOrg (BlockQuote blocks) = do
149139 contents <- blockListToOrg blocks
150− return $ (text "\n#+BEGIN_QUOTE\n") $$ (nest 2 contents)
151− $$ (text "\n#+END_QUOTE\n")
140+ return $ blankline $$ "#+BEGIN_QUOTE" $$
141+ nest 2 contents $$ "#+END_QUOTE" $$ blankline
152142blockToOrg (Table caption' _ _ headers rows) = do
153143 caption'' <- inlineListToOrg caption'
154144 let caption = if null caption'
155145 then empty
156− else (text "#+CAPTION: " <> caption'')
146+ else ("#+CAPTION: " <> caption'')
157147 headers' <- mapM blockListToOrg headers
158148 rawRows <- mapM (mapM blockListToOrg) rows
159− let numChars = maximum . map (length . render)
149+ let numChars = maximum . map offset
160150 -- FIXME: width is not being used.
161151 let widthsInChars =
162152 map ((+2) . numChars) $ transpose (headers' : rawRows)
163153 -- FIXME: Org doesn't allow blocks with height more than 1.
164− let hpipeBlocks blocks = hcatBlocks [beg, middle, end]
165− where height = maximum (map heightOfBlock blocks)
166− sep' = TextBlock 3 height (replicate height " | ")
167− beg = TextBlock 2 height (replicate height "| ")
168− end = TextBlock 2 height (replicate height " |")
169− middle = hcatBlocks $ intersperse sep' blocks
170− let makeRow = hpipeBlocks . zipWith docToBlock widthsInChars
154+ let hpipeBlocks blocks = hcat [beg, middle, end]
155+ where h = maximum (map height blocks)
156+ sep' = lblock 3 $ vcat (map text $ replicate h " | ")
157+ beg = lblock 2 $ vcat (map text $ replicate h "| ")
158+ end = lblock 2 $ vcat (map text $ replicate h " |")
159+ middle = hcat $ intersperse sep' blocks
160+ let makeRow = hpipeBlocks . zipWith lblock widthsInChars
171161 let head' = makeRow headers'
172162 rows' <- mapM (\row -> do cols <- mapM blockListToOrg row
173163 return $ makeRow cols) rows
@@ -175,34 +165,37 @@ blockToOrg (Table caption' _ _ headers rows) = do
175165 (hcat $ intersperse (char ch <> char '+' <> char ch) $
176166 map (\l -> text $ replicate l ch) widthsInChars) <>
177167 char ch <> char '|'
178− let body = vcat $ map blockToDoc rows'
168+ let body = vcat rows'
179169 let head'' = if all null headers
180170 then empty
181− else blockToDoc head' $+$ border '-'
182− return $ head'' $+$ body $$ caption $$ text ""
171+ else head' $$ border '-'
172+ return $ head'' $$ body $$ caption $$ blankline
183173blockToOrg (BulletList items) = do
184174 contents <- mapM bulletListItemToOrg items
185175 -- ensure that sublists have preceding blank line
186− return $ text "" $+$ vcat contents <> text "\n"
187−blockToOrg (OrderedList (start, style', delim) items) = do
176+ return $ blankline $+$ vcat contents $$ blankline
177+blockToOrg (OrderedList (start, _, delim) items) = do
178+ let delim' = case delim of
179+ TwoParens -> OneParen
180+ x -> x
188181 let markers = take (length items) $ orderedListMarkers
189− (start, style', delim)
182+ (start, Decimal, delim')
190183 let maxMarkerLength = maximum $ map length markers
191184 let markers' = map (\m -> let s = maxMarkerLength - length m
192185 in m ++ replicate s ' ') markers
193186 contents <- mapM (\(item, num) -> orderedListItemToOrg item num) $
194− zip markers' items
187+ zip markers' items
195188 -- ensure that sublists have preceding blank line
196− return $ text "" $+$ vcat contents <> text "\n"
189+ return $ blankline $$ vcat contents $$ blankline
197190blockToOrg (DefinitionList items) = do
198191 contents <- mapM definitionListItemToOrg items
199− return $ (vcat contents) <> text "\n"
192+ return $ vcat contents $$ blankline
200193
201194-- | Convert bullet list item (list of blocks) to Org.
202195bulletListItemToOrg :: [Block] -> State WriterState Doc
203196bulletListItemToOrg items = do
204197 contents <- blockListToOrg items
205− return $ (text "- ") <> contents
198+ return $ hang 3 "- " (contents <> cr)
206199
207200-- | Convert ordered list item (a list of blocks) to Org.
208201orderedListItemToOrg :: String -- ^ marker for list item
@@ -210,14 +203,14 @@ orderedListItemToOrg :: String -- ^ marker for list item
210203 -> State WriterState Doc
211204orderedListItemToOrg marker items = do
212205 contents <- blockListToOrg items
213− return $ (text marker <> char ' ') <> contents
206+ return $ hang (length marker + 1) (text marker <> space) (contents <> cr)
214207
215208-- | Convert defintion list item (label, list of blocks) to Org.
216209definitionListItemToOrg :: ([Inline], [[Block]]) -> State WriterState Doc
217210definitionListItemToOrg (label, defs) = do
218211 label' <- inlineListToOrg label
219212 contents <- liftM vcat $ mapM blockListToOrg defs
220− return $ (text "- ") <> label' <> (text " :: ") <> contents
213+ return $ hang 3 "- " $ label' <> " :: " <> (contents <> cr)
221214
222215-- | Convert list of Pandoc block elements to Org.
223216blockListToOrg :: [Block] -- ^ List of block elements
@@ -232,60 +225,57 @@ inlineListToOrg lst = mapM inlineToOrg lst >>= return . hcat
232225inlineToOrg :: Inline -> State WriterState Doc
233226inlineToOrg (Emph lst) = do
234227 contents <- inlineListToOrg lst
235− return $ char '/' <> contents <> char '/'
228+ return $ "/" <> contents <> "/"
236229inlineToOrg (Strong lst) = do
237230 contents <- inlineListToOrg lst
238− return $ text "*" <> contents <> text "*"
231+ return $ "*" <> contents <> "*"
239232inlineToOrg (Strikeout lst) = do
240233 contents <- inlineListToOrg lst
241− return $ text "+" <> contents <> char '+'
234+ return $ "+" <> contents <> "+"
242235inlineToOrg (Superscript lst) = do
243236 contents <- inlineListToOrg lst
244− return $ text "^{" <> contents <> text "}"
237+ return $ "^{" <> contents <> "}"
245238inlineToOrg (Subscript lst) = do
246239 contents <- inlineListToOrg lst
247− return $ text "_{" <> contents <> text "}"
240+ return $ "_{" <> contents <> "}"
248241inlineToOrg (SmallCaps lst) = inlineListToOrg lst
249242inlineToOrg (Quoted SingleQuote lst) = do
250243 contents <- inlineListToOrg lst
251− return $ char '\'' <> contents <> char '\''
244+ return $ "'" <> contents <> "'"
252245inlineToOrg (Quoted DoubleQuote lst) = do
253246 contents <- inlineListToOrg lst
254− return $ char '\"' <> contents <> char '\"'
255−inlineToOrg (Cite _ lst) =
256− inlineListToOrg lst
257−inlineToOrg EmDash = return $ text "---"
258−inlineToOrg EnDash = return $ text "--"
259−inlineToOrg Apostrophe = return $ char '\''
260−inlineToOrg Ellipses = return $ text "..."
261−inlineToOrg (Code str) = return $ text $ "=" ++ str ++ "="
247+ return $ "\"" <> contents <> "\""
248+inlineToOrg (Cite _ lst) = inlineListToOrg lst
249+inlineToOrg EmDash = return "---"
250+inlineToOrg EnDash = return "--"
251+inlineToOrg Apostrophe = return "'"
252+inlineToOrg Ellipses = return "..."
253+inlineToOrg (Code str) = return $ "=" <> text str <> "="
262254inlineToOrg (Str str) = return $ text $ escapeString str
263255inlineToOrg (Math t str) = do
264256 modify $ \st -> st{ stHasMath = True }
265257 return $ if t == InlineMath
266− then text $ "$" ++ str ++ "$"
267− else text $ "$$" ++ str ++ "$$"
258+ then "$" <> text str <> "$"
259+ else "$$" <> text str <> "$$"
268260inlineToOrg (TeX str) = return $ text str
269261inlineToOrg (HtmlInline _) = return empty
270−inlineToOrg (LineBreak) = do
271− return $ empty -- there's no line break in Org
272−inlineToOrg Space = return $ char ' '
262+inlineToOrg (LineBreak) = return cr -- there's no line break in Org
263+inlineToOrg Space = return space
273264inlineToOrg (Link txt (src, _)) = do
274265 case txt of
275266 [Code x] | x == src -> -- autolink
276267 do modify $ \s -> s{ stLinks = True }
277− return $ text $ "[[" ++ x ++ "]]"
268+ return $ "[[" <> text x <> "]]"
278269 _ -> do contents <- inlineListToOrg txt
279270 modify $ \s -> s{ stLinks = True }
280− return $ text ("[[" ++ src ++ "][") <> contents <>
281− (text "]]")
271+ return $ "[[" <> text src <> "][" <> contents <> "]]"
282272inlineToOrg (Image _ (source', _)) = do
283273 let source = unescapeURI source'
284274 modify $ \s -> s{ stImages = True }
285− return $ text $ "[[" ++ source ++ "]]"
275+ return $ "[[" <> text source <> "]]"
286276inlineToOrg (Note contents) = do
287277 -- add to notes in state
288278 notes <- get >>= (return . stNotes)
289279 modify $ \st -> st { stNotes = contents:notes }
290280 let ref = show $ (length notes) + 1
291− return $ text " [" <> text ref <> text "]"
281+ return $ " [" <> text ref <> "]"
src/Text/Pandoc/Writers/RST.hs+81−89
@@ -1,3 +1,4 @@
1+{-# LANGUAGE OverloadedStrings #-}
12{-
23Copyright (C) 2006-2010 John MacFarlane <jgm@berkeley.edu>
34
@@ -32,10 +33,9 @@ reStructuredText: <http://docutils.sourceforge.net/rst.html>
3233module Text.Pandoc.Writers.RST ( writeRST) where
3334import Text.Pandoc.Definition
3435import Text.Pandoc.Shared
35−import Text.Pandoc.Blocks
3636import Text.Pandoc.Templates (renderTemplate)
37−import Data.List ( isPrefixOf, isSuffixOf, intersperse, transpose )
38−import Text.PrettyPrint.HughesPJ hiding ( Str )
37+import Data.List ( isPrefixOf, intersperse, transpose )
38+import Text.Pandoc.Pretty
3939import Control.Monad.State
4040import Control.Applicative ( (<$>) )
4141
@@ -70,13 +70,16 @@ pandocToRST (Pandoc (Meta tit auth dat) blocks) = do
7070 refs <- liftM (reverse . stLinks) get >>= refsToRST
7171 pics <- liftM (reverse . stImages) get >>= pictRefsToRST
7272 hasMath <- liftM stHasMath get
73− let main = render $ foldl ($+$) empty $ [body, notes, refs, pics]
73+ let colwidth = if writerWrapText opts
74+ then Just $ writerColumns opts
75+ else Nothing
76+ let main = render colwidth $ foldl ($+$) empty $ [body, notes, refs, pics]
7477 let context = writerVariables opts ++
7578 [ ("body", main)
76− , ("title", render title)
77− , ("date", render date) ] ++
79+ , ("title", render Nothing title)
80+ , ("date", render colwidth date) ] ++
7881 [ ("math", "yes") | hasMath ] ++
79− [ ("author", render a) | a <- authors ]
82+ [ ("author", render colwidth a) | a <- authors ]
8083 if writerStandalone opts
8184 then return $ renderTemplate context $ writerTemplate opts
8285 else return main
@@ -84,49 +87,40 @@ pandocToRST (Pandoc (Meta tit auth dat) blocks) = do
8487-- | Return RST representation of reference key table.
8588refsToRST :: Refs -> State WriterState Doc
8689refsToRST refs = mapM keyToRST refs >>= return . vcat
87−
90+
8891-- | Return RST representation of a reference key.
8992keyToRST :: ([Inline], (String, String))
9093 -> State WriterState Doc
9194keyToRST (label, (src, _)) = do
9295 label' <- inlineListToRST label
93− let label'' = if ':' `elem` (render label')
96+ let label'' = if ':' `elem` (render Nothing label')
9497 then char '`' <> label' <> char '`'
9598 else label'
96− return $ text ".. _" <> label'' <> text ": " <> text src
99+ return $ ".. _" <> label'' <> ": " <> text src
97100
98101-- | Return RST representation of notes.
99102notesToRST :: [[Block]] -> State WriterState Doc
100103notesToRST notes =
101− mapM (\(num, note) -> noteToRST num note) (zip [1..] notes) >>=
102− return . vcat
104+ mapM (\(num, note) -> noteToRST num note) (zip [1..] notes) >>=
105+ return . vsep
103106
104107-- | Return RST representation of a note.
105108noteToRST :: Int -> [Block] -> State WriterState Doc
106109noteToRST num note = do
107110 contents <- blockListToRST note
108− let marker = text ".. [" <> text (show num) <> text "]"
111+ let marker = ".. [" <> text (show num) <> "]"
109112 return $ marker $$ nest 3 contents
110113
111114-- | Return RST representation of picture reference table.
112115pictRefsToRST :: Refs -> State WriterState Doc
113116pictRefsToRST refs = mapM pictToRST refs >>= return . vcat
114−
117+
115118-- | Return RST representation of a picture substitution reference.
116119pictToRST :: ([Inline], (String, String))
117120 -> State WriterState Doc
118121pictToRST (label, (src, _)) = do
119122 label' <- inlineListToRST label
120− return $ text ".. " <> char '|' <> label' <> char '|' <> text " image:: " <>
121− text src
122−
123−-- | Take list of inline elements and return wrapped doc.
124−wrappedRST :: WriterOptions -> [Inline] -> State WriterState Doc
125−wrappedRST opts inlines = do
126− lineBreakDoc <- inlineToRST LineBreak
127− chunks <- mapM (wrapIfNeeded opts inlineListToRST)
128− (splitBy LineBreak inlines)
129− return $ vcat $ intersperse lineBreakDoc chunks
123+ return $ ".. |" <> label' <> "| image:: " <> text src
130124
131125-- | Escape special characters for RST.
132126escapeString :: String -> String
@@ -136,69 +130,66 @@ titleToRST :: [Inline] -> State WriterState Doc
136130titleToRST [] = return empty
137131titleToRST lst = do
138132 contents <- inlineListToRST lst
139− let titleLength = length $ render contents
133+ let titleLength = length $ (render Nothing contents :: String)
140134 let border = text (replicate titleLength '=')
141− return $ border $+$ contents $+$ border
135+ return $ border $$ contents $$ border
142136
143137-- | Convert Pandoc block element to RST.
144138blockToRST :: Block -- ^ Block element
145139 -> State WriterState Doc
146140blockToRST Null = return empty
147−blockToRST (Plain inlines) = do
148− opts <- get >>= (return . stOptions)
149− wrappedRST opts inlines
141+blockToRST (Plain inlines) = inlineListToRST inlines
150142blockToRST (Para [Image txt (src,tit)]) = do
151143 capt <- inlineListToRST txt
152− let fig = text "figure:: " <> text src
153− let align = text ":align: center"
154− let alt = text ":alt: " <> if null tit then capt else text tit
155− return $ (text ".. " <> (fig $$ align $$ alt $$ text "" $$ capt)) $$ text ""
144+ let fig = "figure:: " <> text src
145+ let align = ":align: center"
146+ let alt = ":alt: " <> if null tit then capt else text tit
147+ return $ hang 3 ".. " $ fig $$ align $$ alt $+$ capt $$ blankline
156148blockToRST (Para inlines) = do
157− opts <- get >>= (return . stOptions)
158− contents <- wrappedRST opts inlines
159− return $ contents <> text "\n"
160−blockToRST (RawHtml str) =
161− let str' = if "\n" `isSuffixOf` str then str ++ "\n" else str ++ "\n\n" in
162− return $ (text "\n.. raw:: html\n") $$ (nest 3 $ vcat $ map text (lines str'))
163−blockToRST HorizontalRule = return $ text "--------------\n"
149+ contents <- inlineListToRST inlines
150+ return $ contents <> blankline
151+blockToRST (RawHtml str) =
152+ return $ blankline <> ".. raw:: html" $+$
153+ (nest 3 $ text str) <> blankline
154+blockToRST HorizontalRule =
155+ return $ blankline $$ "--------------" $$ blankline
164156blockToRST (Header level inlines) = do
165157 contents <- inlineListToRST inlines
166− let headerLength = length $ render contents
167158 let headerChar = if level > 5 then ' ' else "=-~^'" !! (level - 1)
168− let border = text $ replicate headerLength headerChar
169− return $ contents $+$ border <> text "\n"
159+ let border = text $ replicate (offset contents) headerChar
160+ return $ contents $$ border $$ blankline
170161blockToRST (CodeBlock (_,classes,_) str) = do
171162 opts <- stOptions <$> get
172163 let tabstop = writerTabStop opts
173164 if "haskell" `elem` classes && "literate" `elem` classes &&
174165 writerLiterateHaskell opts
175− then return $ (vcat $ map (text "> " <>) $ map text (lines str)) <> text "\n"
176− else return $ (text "::\n") $+$
177− (nest tabstop $ vcat $ map text (lines str)) <> text "\n"
166+ then return $ prefixed "> " $ text str $$ blankline
167+ else return $ "::" $+$ nest tabstop (text str) $$ blankline
178168blockToRST (BlockQuote blocks) = do
179169 tabstop <- get >>= (return . writerTabStop . stOptions)
180170 contents <- blockListToRST blocks
181− return $ (nest tabstop contents) <> text "\n"
171+ return $ nest tabstop contents <> blankline
182172blockToRST (Table caption _ widths headers rows) = do
183173 caption' <- inlineListToRST caption
184174 let caption'' = if null caption
185175 then empty
186− else text "" $+$ (text "Table: " <> caption')
176+ else blankline <> text "Table: " <> caption'
187177 headers' <- mapM blockListToRST headers
188178 rawRows <- mapM (mapM blockListToRST) rows
189179 let isSimple = all (==0) widths && all (all (\bs -> length bs == 1)) rows
190− let numChars = maximum . map (length . render)
180+ let numChars = maximum . map offset
181+ opts <- get >>= return . stOptions
191182 let widthsInChars =
192183 if isSimple
193184 then map ((+2) . numChars) $ transpose (headers' : rawRows)
194− else map (floor . (78 *)) widths
195− let hpipeBlocks blocks = hcatBlocks [beg, middle, end]
196− where height = maximum (map heightOfBlock blocks)
197− sep' = TextBlock 3 height (replicate height " | ")
198− beg = TextBlock 2 height (replicate height "| ")
199− end = TextBlock 2 height (replicate height " |")
200− middle = hcatBlocks $ intersperse sep' blocks
201− let makeRow = hpipeBlocks . zipWith docToBlock widthsInChars
185+ else map (floor . (fromIntegral (writerColumns opts) *)) widths
186+ let hpipeBlocks blocks = hcat [beg, middle, end]
187+ where h = maximum (map height blocks)
188+ sep' = lblock 3 $ vcat (map text $ replicate h " | ")
189+ beg = lblock 2 $ vcat (map text $ replicate h "| ")
190+ end = lblock 2 $ vcat (map text $ replicate h " |")
191+ middle = hcat $ intersperse sep' blocks
192+ let makeRow = hpipeBlocks . zipWith lblock widthsInChars
202193 let head' = makeRow headers'
203194 rows' <- mapM (\row -> do cols <- mapM blockListToRST row
204195 return $ makeRow cols) rows
@@ -206,15 +197,15 @@ blockToRST (Table caption _ widths headers rows) = do
206197 (hcat $ intersperse (char ch <> char '+' <> char ch) $
207198 map (\l -> text $ replicate l ch) widthsInChars) <>
208199 char ch <> char '+'
209− let body = vcat $ intersperse (border '-') $ map blockToDoc rows'
200+ let body = vcat $ intersperse (border '-') rows'
210201 let head'' = if all null headers
211202 then empty
212− else blockToDoc head' $+$ border '='
213− return $ border '-' $+$ head'' $+$ body $+$ border '-' $$ caption'' $$ text ""
203+ else head' $$ border '='
204+ return $ border '-' $$ head'' $$ body $$ border '-' $$ caption'' $$ blankline
214205blockToRST (BulletList items) = do
215206 contents <- mapM bulletListItemToRST items
216207 -- ensure that sublists have preceding blank line
217− return $ text "" $+$ vcat contents <> text "\n"
208+ return $ blankline $$ vcat contents $$ blankline
218209blockToRST (OrderedList (start, style', delim) items) = do
219210 let markers = if start == 1 && style' == DefaultStyle && delim == DefaultDelim
220211 then take (length items) $ repeat "#."
@@ -224,18 +215,19 @@ blockToRST (OrderedList (start, style', delim) items) = do
224215 let markers' = map (\m -> let s = maxMarkerLength - length m
225216 in m ++ replicate s ' ') markers
226217 contents <- mapM (\(item, num) -> orderedListItemToRST item num) $
227− zip markers' items
218+ zip markers' items
228219 -- ensure that sublists have preceding blank line
229− return $ text "" $+$ vcat contents <> text "\n"
220+ return $ blankline $$ vcat contents $$ blankline
230221blockToRST (DefinitionList items) = do
231222 contents <- mapM definitionListItemToRST items
232− return $ (vcat contents) <> text "\n"
223+ -- ensure that sublists have preceding blank line
224+ return $ blankline $$ vcat contents $$ blankline
233225
234226-- | Convert bullet list item (list of blocks) to RST.
235227bulletListItemToRST :: [Block] -> State WriterState Doc
236228bulletListItemToRST items = do
237229 contents <- blockListToRST items
238− return $ (text "- ") <> contents
230+ return $ hang 3 "- " $ contents <> cr
239231
240232-- | Convert ordered list item (a list of blocks) to RST.
241233orderedListItemToRST :: String -- ^ marker for list item
@@ -243,7 +235,8 @@ orderedListItemToRST :: String -- ^ marker for list item
243235 -> State WriterState Doc
244236orderedListItemToRST marker items = do
245237 contents <- blockListToRST items
246− return $ (text marker <> char ' ') <> contents
238+ let marker' = marker ++ " "
239+ return $ hang (length marker') (text marker') $ contents <> cr
247240
248241-- | Convert defintion list item (label, list of blocks) to RST.
249242definitionListItemToRST :: ([Inline], [[Block]]) -> State WriterState Doc
@@ -251,7 +244,7 @@ definitionListItemToRST (label, defs) = do
251244 label' <- inlineListToRST label
252245 contents <- liftM vcat $ mapM blockListToRST defs
253246 tabstop <- get >>= (return . writerTabStop . stOptions)
254− return $ label' $+$ nest tabstop contents
247+ return $ label' $$ nest tabstop (contents <> cr)
255248
256249-- | Convert list of Pandoc block elements to RST.
257250blockListToRST :: [Block] -- ^ List of block elements
@@ -266,65 +259,64 @@ inlineListToRST lst = mapM inlineToRST lst >>= return . hcat
266259inlineToRST :: Inline -> State WriterState Doc
267260inlineToRST (Emph lst) = do
268261 contents <- inlineListToRST lst
269− return $ char '*' <> contents <> char '*'
262+ return $ "*" <> contents <> "*"
270263inlineToRST (Strong lst) = do
271264 contents <- inlineListToRST lst
272− return $ text "**" <> contents <> text "**"
265+ return $ "**" <> contents <> "**"
273266inlineToRST (Strikeout lst) = do
274267 contents <- inlineListToRST lst
275− return $ text "[STRIKEOUT:" <> contents <> char ']'
268+ return $ "[STRIKEOUT:" <> contents <> "]"
276269inlineToRST (Superscript lst) = do
277270 contents <- inlineListToRST lst
278− return $ text "\\ :sup:`" <> contents <> text "`\\ "
271+ return $ "\\ :sup:`" <> contents <> "`\\ "
279272inlineToRST (Subscript lst) = do
280273 contents <- inlineListToRST lst
281− return $ text "\\ :sub:`" <> contents <> text "`\\ "
274+ return $ "\\ :sub:`" <> contents <> "`\\ "
282275inlineToRST (SmallCaps lst) = inlineListToRST lst
283276inlineToRST (Quoted SingleQuote lst) = do
284277 contents <- inlineListToRST lst
285− return $ char '‘' <> contents <> char '’'
278+ return $ "‘" <> contents <> "’"
286279inlineToRST (Quoted DoubleQuote lst) = do
287280 contents <- inlineListToRST lst
288− return $ char '“' <> contents <> char '”'
281+ return $ "“" <> contents <> "”"
289282inlineToRST (Cite _ lst) =
290283 inlineListToRST lst
291284inlineToRST EmDash = return $ char '\8212'
292285inlineToRST EnDash = return $ char '\8211'
293286inlineToRST Apostrophe = return $ char '\8217'
294287inlineToRST Ellipses = return $ char '\8230'
295−inlineToRST (Code str) = return $ text $ "``" ++ str ++ "``"
288+inlineToRST (Code str) = return $ "``" <> text str <> "``"
296289inlineToRST (Str str) = return $ text $ escapeString str
297290inlineToRST (Math t str) = do
298291 modify $ \st -> st{ stHasMath = True }
299292 return $ if t == InlineMath
300− then text $ ":math:`$" ++ str ++ "$`"
301− else text $ ":math:`$$" ++ str ++ "$$`"
293+ then ":math:`$" <> text str <> "$`"
294+ else ":math:`$$" <> text str <> "$$`"
302295inlineToRST (TeX _) = return empty
303296inlineToRST (HtmlInline _) = return empty
304−inlineToRST (LineBreak) = do
305− return $ empty -- there's no line break in RST
306−inlineToRST Space = return $ char ' '
297+inlineToRST (LineBreak) = return cr -- there's no line break in RST
298+inlineToRST Space = return space
307299inlineToRST (Link [Code str] (src, _)) | src == str ||
308300 src == "mailto:" ++ str = do
309301 let srcSuffix = if isPrefixOf "mailto:" src then drop 7 src else src
310302 return $ text $ unescapeURI srcSuffix
311303inlineToRST (Link txt (src', tit)) = do
312304 let src = unescapeURI src'
313− useReferenceLinks <- get >>= (return . writerReferenceLinks . stOptions)
305+ useReferenceLinks <- get >>= return . writerReferenceLinks . stOptions
314306 linktext <- inlineListToRST $ normalizeSpaces txt
315307 if useReferenceLinks
316− then do refs <- get >>= (return . stLinks)
308+ then do refs <- get >>= return . stLinks
317309 let refs' = if (txt, (src, tit)) `elem` refs
318310 then refs
319311 else (txt, (src, tit)):refs
320312 modify $ \st -> st { stLinks = refs' }
321− return $ char '`' <> linktext <> text "`_"
322− else return $ char '`' <> linktext <> text " <" <> text src <> text ">`_"
313+ return $ "`" <> linktext <> "`_"
314+ else return $ "`" <> linktext <> " <" <> text src <> ">`_"
323315inlineToRST (Image alternate (source', tit)) = do
324316 let source = unescapeURI source'
325− pics <- get >>= (return . stImages)
317+ pics <- get >>= return . stImages
326318 let labelsUsed = map fst pics
327− let txt = if null alternate || alternate == [Str ""] ||
319+ let txt = if null alternate || alternate == [Str ""] ||
328320 alternate `elem` labelsUsed
329321 then [Str $ "image" ++ show (length pics)]
330322 else alternate
@@ -333,10 +325,10 @@ inlineToRST (Image alternate (source', tit)) = do
333325 else (txt, (source, tit)):pics
334326 modify $ \st -> st { stImages = pics' }
335327 label <- inlineListToRST txt
336− return $ char '|' <> label <> char '|'
328+ return $ "|" <> label <> "|"
337329inlineToRST (Note contents) = do
338330 -- add to notes in state
339− notes <- get >>= (return . stNotes)
331+ notes <- get >>= return . stNotes
340332 modify $ \st -> st { stNotes = contents:notes }
341333 let ref = show $ (length notes) + 1
342− return $ text " [" <> text ref <> text "]_"
334+ return $ " [" <> text ref <> "]_"
src/pandoc.hs+38−20
@@ -36,11 +36,11 @@ import Text.Pandoc.Shared ( tabFilter, ObfuscationMethod (..), readDataFile,
3636#ifdef _HIGHLIGHTING
3737import Text.Pandoc.Highlighting ( languages )
3838#endif
39−import System.Environment ( getArgs, getProgName, getEnvironment )
39+import System.Environment ( getArgs, getProgName )
4040import System.Exit ( exitWith, ExitCode (..) )
4141import System.FilePath
4242import System.Console.GetOpt
43−import Data.Char ( toLower, isDigit )
43+import Data.Char ( toLower )
4444import Data.List ( intercalate, isSuffixOf )
4545import System.Directory ( getAppUserDataDirectory, doesFileExist )
4646import System.IO ( stdout, stderr )
@@ -111,6 +111,7 @@ data Opt = Opt
111111 , optStrict :: Bool -- ^ Use strict markdown syntax
112112 , optReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
113113 , optWrapText :: Bool -- ^ Wrap text
114+ , optColumns :: Int -- ^ Line length in characters
114115 , optPlugins :: [Pandoc -> IO Pandoc] -- ^ Plugins to apply
115116 , optEmailObfuscation :: ObfuscationMethod
116117 , optIdentifierPrefix :: String
@@ -150,6 +151,7 @@ defaultOpts = Opt
150151 , optStrict = False
151152 , optReferenceLinks = False
152153 , optWrapText = True
154+ , optColumns = 72
153155 , optPlugins = []
154156 , optEmailObfuscation = JavascriptObfuscation
155157 , optIdentifierPrefix = ""
@@ -194,8 +196,14 @@ options =
194196
195197 , Option "" ["tab-stop"]
196198 (ReqArg
197− (\arg opt -> return opt { optTabStop = (read arg) } )
198− "TABSTOP")
199+ (\arg opt ->
200+ case reads arg of
201+ [(t,"")] | t > 0 -> return opt { optTabStop = t }
202+ _ -> do
203+ UTF8.hPutStrLn stderr $
204+ "tab-stop must be a number greater than 0"
205+ exitWith $ ExitFailure 31)
206+ "NUMBER")
199207 "" -- "Tab stop (default 4)"
200208
201209 , Option "" ["strict"]
@@ -300,6 +308,18 @@ options =
300308 (\opt -> return opt { optWrapText = False }))
301309 "" -- "Do not wrap text in output"
302310
311+ , Option "" ["columns"]
312+ (ReqArg
313+ (\arg opt ->
314+ case reads arg of
315+ [(t,"")] | t > 0 -> return opt { optColumns = t }
316+ _ -> do
317+ UTF8.hPutStrLn stderr $
318+ "columns must be a number greater than 0"
319+ exitWith $ ExitFailure 33)
320+ "NUMBER")
321+ "" -- "Length of line in characters"
322+
303323 , Option "" ["email-obfuscation"]
304324 (ReqArg
305325 (\arg opt -> do
@@ -333,17 +353,18 @@ options =
333353
334354 , Option "" ["base-header-level"]
335355 (ReqArg
336− (\arg opt -> do
337− if all isDigit arg && (read arg :: Int) >= 1
338− then do
339− let oldTransforms = optTransforms opt
340− let shift = read arg - 1
341− return opt{ optTransforms =
342− headerShift shift : oldTransforms }
343− else do
344− UTF8.hPutStrLn stderr $ "base-header-level must be a number >= 1"
345− exitWith $ ExitFailure 19)
346− "LEVEL")
356+ (\arg opt ->
357+ case reads arg of
358+ [(t,"")] | t > 0 -> do
359+ let oldTransforms = optTransforms opt
360+ let shift = t - 1
361+ return opt{ optTransforms =
362+ headerShift shift : oldTransforms }
363+ _ -> do
364+ UTF8.hPutStrLn stderr $
365+ "base-header-level must be a number > 0"
366+ exitWith $ ExitFailure 19)
367+ "NUMBER")
347368 "" -- "Headers base level"
348369
349370 , Option "" ["template"]
@@ -617,6 +638,7 @@ main = do
617638 , optStrict = strict
618639 , optReferenceLinks = referenceLinks
619640 , optWrapText = wrap
641+ , optColumns = columns
620642 , optEmailObfuscation = obfuscationMethod
621643 , optIdentifierPrefix = idPrefix
622644 , optIndentedCodeClasses = codeBlockClasses
@@ -668,11 +690,6 @@ main = do
668690 Right t -> t
669691 Left e -> error (show e)
670692
671− environment <- getEnvironment
672− let columns = case lookup "COLUMNS" environment of
673− Just cols -> read cols
674− Nothing -> stateColumns defaultParserState
675−
676693 let standalone' = standalone || isNonTextOutput writerName'
677694
678695 variables' <- case (writerName', standalone', offline) of
@@ -746,6 +763,7 @@ main = do
746763 writerStrictMarkdown = strict,
747764 writerReferenceLinks = referenceLinks,
748765 writerWrapText = wrap,
766+ writerColumns = columns,
749767 writerLiterateHaskell = "+lhs" `isSuffixOf` writerName' ||
750768 lhsExtension [outputFile],
751769 writerEmailObfuscation = if strict
src/test-pandoc.hs+7−8
@@ -113,7 +113,7 @@ main = do
113113 "testsuite.native" "testsuite.native"
114114 r14s <- mapM (\style -> runTest ("markdown reader (citations) (" ++ style ++ ")") ["-r", "markdown", "-w", "markdown", "--bibliography", "biblio.bib", "--csl", style ++ ".csl", "--no-wrap"] "markdown-citations.txt" ("markdown-citations." ++ style ++ ".txt")) ["chicago-author-date","ieee","mhra"]
115115 let citopts = ["--bibliography", "biblio.bib", "--csl", "chicago-author-date.csl", "--no-citeproc"]
116− r15 <- runTest "markdown writer (citations)" (["-r", "markdown", "-w", "markdown"] ++ citopts)
116+ r15 <- runTest "markdown writer (citations)" (["-r", "markdown", "-w", "markdown", "--no-wrap"] ++ citopts)
117117 "markdown-citations.txt" "markdown-citations.txt"
118118 r16s <- runLatexCitationTests citopts "biblatex"
119119 r17s <- runLatexCitationTests citopts "natbib"
@@ -159,9 +159,9 @@ runLhsReaderTest format =
159159
160160runLatexCitationTests :: [String] -> String -> IO [Bool]
161161runLatexCitationTests o n
162− = sequence [ rt ("latex reader (" ++ n ++ " citations)") (["-r", "latex", "-w", "markdown", "-s"] ++ o')
162+ = sequence [ rt ("latex reader (" ++ n ++ " citations)") (["-r", "latex", "-w", "markdown", "-s", "--no-wrap"] ++ o')
163163 f "markdown-citations.txt"
164− , rt ("latex writer (" ++ n ++ " citations)") (["-r", "markdown", "-w", "latex", "-s"] ++ o')
164+ , rt ("latex writer (" ++ n ++ " citations)") (["-r", "markdown", "-w", "latex", "-s", "--no-wrap"] ++ o')
165165 "markdown-citations.txt" f
166166 ]
167167 where
@@ -172,8 +172,8 @@ runLatexCitationTests o n
172172
173173runWriterTest :: String -> IO Bool
174174runWriterTest format = do
175− r1 <- runTest (format ++ " writer") ["-r", "native", "-s", "-w", format] "testsuite.native" ("writer" <.> format)
176− r2 <- runTest (format ++ " writer (tables)") ["-r", "native", "-w", format] "tables.native" ("tables" <.> format)
175+ r1 <- runTest (format ++ " writer") ["-r", "native", "-s", "-w", format, "--columns=78"] "testsuite.native" ("writer" <.> format)
176+ r2 <- runTest (format ++ " writer (tables)") ["-r", "native", "-w", format, "--columns=78"] "tables.native" ("tables" <.> format)
177177 return (r1 && r2)
178178
179179runS5WriterTest :: String -> [String] -> String -> IO Bool
@@ -202,9 +202,8 @@ runTestWithNormalize normalize testname opts inp norm = do
202202 let inpPath = inp
203203 let normPath = norm
204204 hFlush stdout
205− -- Note: COLUMNS must be set for markdown table reader
206− ph <- runProcess pandocPath (opts ++ [inpPath] ++ ["--data-dir", ".."]) Nothing
207− (Just [("LANG","en_US.UTF-8"),("COLUMNS", "80"),("HOME", "./")]) Nothing (Just hOut) (Just stderr)
205+ ph <- runProcess pandocPath (["--columns=80"] ++ [inpPath] ++ ["--data-dir", ".."] ++ opts) Nothing
206+ (Just [("LANG","en_US.UTF-8"),("HOME", "./")]) Nothing (Just hOut) (Just stderr)
208207 ec <- waitForProcess ph
209208 result <- if ec == ExitSuccess
210209 then do
templates/org.template+2
@@ -2,7 +2,9 @@ $if(title)$
22$title$
33
44$endif$
5+$if(author)$
56#+AUTHOR: $for(author)$$author$$sep$; $endfor$
7+$endif$
68$if(date)$
79#+DATE: $date$
810
tests/biblatex-citations.latex+3−7
@@ -34,8 +34,7 @@
3434 \textcites{item1}[p.~30]{item2}[see also][]{item3} says blah.
3535
3636\item
37− In a note.%
38− \footnote{A citation without locators \autocite{item3}.}
37+ In a note.\footnote{A citation without locators \autocite{item3}.}
3938
4039\item
4140 A citation group
@@ -45,8 +44,7 @@
4544 Another one \autocite[see][p.~34--35]{item1}.
4645
4746\item
48− And another one in a note.%
49− \footnote{Some citations \autocites[see][chap. 3]{item2}{item3}{item1}.}
47+ And another one in a note.\footnote{Some citations \autocites[see][chap. 3]{item2}{item3}{item1}.}
5048
5149\item
5250 Citation with a suffix and locator
@@ -56,9 +54,7 @@
5654 Citation with suffix only \autocite[and nowhere else]{item1}.
5755
5856\item
59− Now some modifiers.%
60− \footnote{Like a citation without author: \autocite*{item1}, and now Doe with
61−a locator \autocite*[p.~44]{item2}.}
57+ Now some modifiers.\footnote{Like a citation without author: \autocite*{item1}, and now Doe with a locator \autocite*[p.~44]{item2}.}
6258
6359\item
6460 With some markup \autocite[\emph{see}][p. \textbf{32}]{item1}.
tests/markdown-citations.chicago-author-date.txt+3−7
@@ -28,7 +28,6 @@
2828
2929- With some markup (*see* Doe 2005, 32).
3030
31−
3231# References
3332
3433Doe, John. 2005. *First Book*. Cambridge: Cambridge University Press.
@@ -37,11 +36,8 @@ Doe, John. 2005. *First Book*. Cambridge: Cambridge University Press.
3736
3837Doe, John, and Jenny Roe. 2007. Why Water Is Wet. In *Third Book*, ed. Sam Smith. Oxford: Oxford University Press.
3938
40−[^1]:
41− A citation without locators (Doe and Roe 2007).
39+[^1]: A citation without locators (Doe and Roe 2007).
4240
43−[^2]:
44− Some citations (see Doe 2006, chap. 3; Doe and Roe 2007; Doe 2005).
41+[^2]: Some citations (see Doe 2006, chap. 3; Doe and Roe 2007; Doe 2005).
4542
46−[^3]:
47− Like a citation without author: (2005), and now Doe with a locator (2006, 44).
43+[^3]: Like a citation without author: (2005), and now Doe with a locator (2006, 44).
tests/markdown-citations.ieee.txt+3−7
@@ -28,7 +28,6 @@
2828
2929- With some markup [1].
3030
31−
3231# References
3332
3433[1] J. Doe, *First Book*, Cambridge: Cambridge University Press, 2005.
@@ -37,11 +36,8 @@
3736
3837[3] J. Doe and J. Roe, “Why Water Is Wet,” *Third Book*, Smith, S., Ed., Oxford: Oxford University Press, 2007.
3938
40−[^1]:
41− A citation without locators [3].
39+[^1]: A citation without locators [3].
4240
43−[^2]:
44− Some citations [1]-[3].
41+[^2]: Some citations [1]-[3].
4542
46−[^3]:
47− Like a citation without author: [1], and now Doe with a locator [2].
43+[^3]: Like a citation without author: [1], and now Doe with a locator [2].
tests/markdown-citations.mhra.txt+14−25
@@ -28,7 +28,6 @@
2828
2929- With some markup.[^12]
3030
31−
3231# References
3332
3433Doe, John, ‘Article’, *Journal of Generic Studies*, 6 (2006), 33-34.
@@ -37,38 +36,28 @@ Doe, John, ‘Article’, *Journal of Generic Studies*, 6 (2006), 33-34.
3736
3837Doe, John, and Jenny Roe, ‘Why Water Is Wet’, in *Third Book*, ed by Sam Smith (Oxford: Oxford University Press, 2007).
3938
40−[^1]:
41− *First Book* (Cambridge: Cambridge University Press, 2005).
39+[^1]: *First Book* (Cambridge: Cambridge University Press, 2005).
40+
41+[^2]: First Book, p. 30.
4242
43−[^2]:
44− First Book, p. 30.
43+[^3]: First Book, p. 30, with suffix.
4544
46−[^3]:
47− First Book, p. 30, with suffix.
45+[^4]: First Book; ‘Article’, *Journal of Generic Studies*, 6 (2006), 33-34 (p. 30); see also John Doe and Jenny Roe, ‘Why Water Is Wet’, in *Third Book*, ed by Sam Smith (Oxford: Oxford University Press, 2007).
4846
49−[^4]:
50− First Book; ‘Article’, *Journal of Generic Studies*, 6 (2006), 33-34 (p. 30); see also John Doe and Jenny Roe, ‘Why Water Is Wet’, in *Third Book*, ed by Sam Smith (Oxford: Oxford University Press, 2007).
47+[^5]: A citation without locators Doe and Roe.
5148
52−[^5]:
53− A citation without locators Doe and Roe.
49+[^6]: See Doe, First Book, pp. 34-35; also Doe and Roe, chap. 3.
5450
55−[^6]:
56− See Doe, First Book, pp. 34-35; also Doe and Roe, chap. 3.
51+[^7]: See Doe, First Book, pp. 34-35.
5752
58−[^7]:
59− See Doe, First Book, pp. 34-35.
53+[^8]: Some citations see Doe, Article, 33-34 (chap. 3); Doe and Roe; Doe, First Book.
6054
61−[^8]:
62− Some citations see Doe, Article, 33-34 (chap. 3); Doe and Roe; Doe, First Book.
55+[^9]: Doe, First Book, pp. 33, 35-37, and nowhere else.
6356
64−[^9]:
65− Doe, First Book, pp. 33, 35-37, and nowhere else.
57+[^10]: Doe, First Book, and nowhere else.
6658
67−[^10]:
68− Doe, First Book, and nowhere else.
59+[^11]: Like a citation without author: First Book, and now Doe with a locator Article, 33-34 (p. 44).
6960
70−[^11]:
71− Like a citation without author: First Book, and now Doe with a locator Article, 33-34 (p. 44).
61+[^11]: Like a citation without author: First Book, and now Doe with a locator Article, 33-34 (p. 44).
7262
73−[^12]:
74− *See* Doe, First Book, p. 32.
63+[^12]: *See* Doe, First Book, p. 32.
tests/markdown-citations.txt+5−9
@@ -20,8 +20,7 @@
2020
2121- And another one in a note.[^2]
2222
23−- Citation with a suffix and locator
24− [@item1 pp. 33, 35-37, and nowhere else].
23+- Citation with a suffix and locator [@item1 pp. 33, 35-37, and nowhere else].
2524
2625- Citation with suffix only [@item1 and nowhere else].
2726
@@ -32,12 +31,9 @@
3231
3332# References
3433
35−[^1]:
36− A citation without locators [@item3].
34+[^1]: A citation without locators [@item3].
3735
38−[^2]:
39− Some citations [see @item2 chap. 3; @item3; @item1].
36+[^2]: Some citations [see @item2 chap. 3; @item3; @item1].
37+
38+[^3]: Like a citation without author: [-@item1], and now Doe with a locator [-@item2 p. 44].
4039
41−[^3]:
42− Like a citation without author: [-@item1], and now Doe with a
43− locator [-@item2 p. 44].
tests/natbib-citations.latex+6−14
@@ -31,36 +31,28 @@
3131 \citet[p.~30, with suffix]{item1} says blah.
3232
3333\item
34− \citeauthor{item1} \citetext{\citeyear{item1}; \citeyear[p.~30]{item2}; \citealp[see also][]{item3}}
35− says blah.
34+ \citeauthor{item1} \citetext{\citeyear{item1}; \citeyear[p.~30]{item2}; \citealp[see also][]{item3}} says blah.
3635
3736\item
38− In a note.%
39− \footnote{A citation without locators \citep{item3}.}
37+ In a note.\footnote{A citation without locators \citep{item3}.}
4038
4139\item
42− A citation group
43− \citetext{\citealp[see][p.~34--35]{item1}; \citealp[also][chap. 3]{item3}}.
40+ A citation group \citetext{\citealp[see][p.~34--35]{item1}; \citealp[also][chap. 3]{item3}}.
4441
4542\item
4643 Another one \citep[see][p.~34--35]{item1}.
4744
4845\item
49− And another one in a note.%
50− \footnote{Some citations
51−\citetext{\citealp[see][chap. 3]{item2}; \citealp{item3}; \citealp{item1}}.}
46+ And another one in a note.\footnote{Some citations \citetext{\citealp[see][chap. 3]{item2}; \citealp{item3}; \citealp{item1}}.}
5247
5348\item
54− Citation with a suffix and locator
55− \citep[pp.~33, 35--37, and nowhere else]{item1}.
49+ Citation with a suffix and locator \citep[pp.~33, 35--37, and nowhere else]{item1}.
5650
5751\item
5852 Citation with suffix only \citep[and nowhere else]{item1}.
5953
6054\item
61− Now some modifiers.%
62− \footnote{Like a citation without author: \citeyearpar{item1}, and now Doe
63−with a locator \citeyearpar[p.~44]{item2}.}
55+ Now some modifiers.\footnote{Like a citation without author: \citeyearpar{item1}, and now Doe with a locator \citeyearpar[p.~44]{item2}.}
6456
6557\item
6658 With some markup \citep[\emph{see}][p. \textbf{32}]{item1}.
tests/tables.markdown+9−8
@@ -5,7 +5,7 @@ Simple table with caption:
55 12 12 12 12
66 123 123 123 123
77 1 1 1 1
8−
8+
99 : Demonstration of simple table syntax.
1010
1111Simple table without caption:
@@ -23,34 +23,34 @@ Simple table indented two spaces:
2323 12 12 12 12
2424 123 123 123 123
2525 1 1 1 1
26−
26+
2727 : Demonstration of simple table syntax.
2828
2929Multiline table with caption:
3030
3131 --------------------------------------------------------------
3232 Centered Left Right Default aligned
33− Header Aligned Aligned
33+ Header Aligned Aligned
3434 ----------- ---------- ------------ --------------------------
3535 First row 12.0 Example of a row that
3636 spans multiple lines.
37−
37+
3838 Second row 5.0 Here's another one. Note
3939 the blank line between
4040 rows.
4141 --------------------------------------------------------------
42−
42+
4343 : Here's the caption. It may span multiple lines.
4444
4545Multiline table without caption:
4646
4747 --------------------------------------------------------------
4848 Centered Left Right Default aligned
49− Header Aligned Aligned
49+ Header Aligned Aligned
5050 ----------- ---------- ------------ --------------------------
5151 First row 12.0 Example of a row that
5252 spans multiple lines.
53−
53+
5454 Second row 5.0 Here's another one. Note
5555 the blank line between
5656 rows.
@@ -69,8 +69,9 @@ Multiline table without column headers:
6969 ----------- ---------- ------------ --------------------------
7070 First row 12.0 Example of a row that
7171 spans multiple lines.
72−
72+
7373 Second row 5.0 Here's another one. Note
7474 the blank line between
7575 rows.
7676 ----------- ---------- ------------ --------------------------
77+
tests/tables.plain+9−8
@@ -5,7 +5,7 @@ Simple table with caption:
55 12 12 12 12
66 123 123 123 123
77 1 1 1 1
8−
8+
99 : Demonstration of simple table syntax.
1010
1111Simple table without caption:
@@ -23,34 +23,34 @@ Simple table indented two spaces:
2323 12 12 12 12
2424 123 123 123 123
2525 1 1 1 1
26−
26+
2727 : Demonstration of simple table syntax.
2828
2929Multiline table with caption:
3030
3131 --------------------------------------------------------------
3232 Centered Left Right Default aligned
33− Header Aligned Aligned
33+ Header Aligned Aligned
3434 ----------- ---------- ------------ --------------------------
3535 First row 12.0 Example of a row that
3636 spans multiple lines.
37−
37+
3838 Second row 5.0 Here's another one. Note
3939 the blank line between
4040 rows.
4141 --------------------------------------------------------------
42−
42+
4343 : Here's the caption. It may span multiple lines.
4444
4545Multiline table without caption:
4646
4747 --------------------------------------------------------------
4848 Centered Left Right Default aligned
49− Header Aligned Aligned
49+ Header Aligned Aligned
5050 ----------- ---------- ------------ --------------------------
5151 First row 12.0 Example of a row that
5252 spans multiple lines.
53−
53+
5454 Second row 5.0 Here's another one. Note
5555 the blank line between
5656 rows.
@@ -69,8 +69,9 @@ Multiline table without column headers:
6969 ----------- ---------- ------------ --------------------------
7070 First row 12.0 Example of a row that
7171 spans multiple lines.
72−
72+
7373 Second row 5.0 Here's another one. Note
7474 the blank line between
7575 rows.
7676 ----------- ---------- ------------ --------------------------
77+
tests/writer.markdown+37−80
@@ -2,9 +2,8 @@
22% John MacFarlane; Anonymous
33% July 17, 2006
44
5−This is a set of tests for pandoc. Most of them are adapted from
6−John Gruber’s markdown test suite.
7−
5+This is a set of tests for pandoc. Most of them are adapted from John Gruber’s
6+markdown test suite.
87
98* * * * *
109
@@ -30,23 +29,21 @@ with no blank line
3029
3130with no blank line
3231
33−
3432* * * * *
3533
3634# Paragraphs
3735
3836Here’s a regular paragraph.
3937
40−In Markdown 1.0.0 and earlier. Version 8. This line turns into a
41−list item. Because a hard-wrapped line in the middle of a paragraph
42−looked like a list item.
38+In Markdown 1.0.0 and earlier. Version 8. This line turns into a list item.
39+Because a hard-wrapped line in the middle of a paragraph looked like a list
40+item.
4341
4442Here’s one with a bullet. \* criminey.
4543
4644There should be a hard line break
4745here.
4846
49−
5047* * * * *
5148
5249# Block Quotes
@@ -56,27 +53,26 @@ E-mail style:
5653> This is a block quote. It is pretty short.
5754
5855> Code in a block quote:
59−>
56+>
6057> sub status {
6158> print "working";
6259> }
63−>
60+>
6461> A list:
65−>
62+>
6663> 1. item one
6764> 2. item two
68−>
65+>
6966> Nested block quotes:
70−>
67+>
7168> > nested
72−>
69+>
7370> > nested
7471
7572This should not be a block quote: 2 \> 1.
7673
7774And a following paragraph.
7875
79−
8076* * * * *
8177
8278# Code Blocks
@@ -84,19 +80,18 @@ And a following paragraph.
8480Code:
8581
8682 ---- (should be four hyphens)
87−
83+
8884 sub status {
8985 print "working";
9086 }
91−
87+
9288 this code block is indented by one tab
9389
9490And:
9591
9692 this code block is indented by two tabs
97−
98− These should not be escaped: \$ \\ \> \[ \{
9993
94+ These should not be escaped: \$ \\ \> \[ \{
10095
10196* * * * *
10297
@@ -118,7 +113,6 @@ Asterisks loose:
118113
119114- asterisk 3
120115
121−
122116Pluses tight:
123117
124118- Plus 1
@@ -133,7 +127,6 @@ Pluses loose:
133127
134128- Plus 3
135129
136−
137130Minuses tight:
138131
139132- Minus 1
@@ -148,7 +141,6 @@ Minuses loose:
148141
149142- Minus 3
150143
151−
152144## Ordered
153145
154146Tight:
@@ -171,7 +163,6 @@ Loose using tabs:
171163
1721643. Third
173165
174−
175166and using spaces:
176167
1771681. One
@@ -180,27 +171,22 @@ and using spaces:
180171
1811723. Three
182173
183−
184174Multiple paragraphs:
185175
1861761. Item 1, graf one.
187177
188− Item 1. graf two. The quick brown fox jumped over the lazy dog’s
189− back.
178+ Item 1. graf two. The quick brown fox jumped over the lazy dog’s back.
190179
1911802. Item 2.
192181
1931823. Item 3.
194183
195−
196184## Nested
197185
198186- Tab
199187 - Tab
200188 - Tab
201189
202−
203−
204190Here’s another:
205191
2061921. First
@@ -223,7 +209,6 @@ Same thing but with paragraphs:
223209
2242103. Third
225211
226−
227212## Tabs and spaces
228213
229214- this is a list item indented with tabs
@@ -234,8 +219,6 @@ Same thing but with paragraphs:
234219
235220 - this is an example list item indented with spaces
236221
237−
238−
239222## Fancy list markers
240223
241224(2) begins with 2
@@ -248,8 +231,6 @@ Same thing but with paragraphs:
248231 (A) a subsublist
249232 (B) a subsublist
250233
251−
252−
253234Nesting:
254235
255236A. Upper Alpha
@@ -257,23 +238,18 @@ A. Upper Alpha
257238 (6) Decimal start with 6
258239 c) Lower alpha with paren
259240
260−
261−
262−
263241Autonumbering:
264242
2652431. Autonumber.
2662442. More.
267245 1. Nested.
268246
269−
270247Should not be a list item:
271248
272249M.A. 2007
273250
274251B. Williams
275252
276−
277253* * * * *
278254
279255# Definition Lists
@@ -307,7 +283,6 @@ orange
307283banana
308284 ~ yellow fruit
309285
310−
311286Multiple blocks with italics:
312287
313288*apple*
@@ -322,7 +297,6 @@ Multiple blocks with italics:
322297
323298 > orange block quote
324299
325−
326300Multiple definitions, tight:
327301
328302apple
@@ -344,7 +318,6 @@ orange
344318
345319 ~ bank
346320
347−
348321Blank line after term, indented marker, alternate markers:
349322
350323apple
@@ -358,7 +331,6 @@ orange
358331 1. sublist
359332 2. sublist
360333
361−
362334# HTML Blocks
363335
364336Simple block on one line:
@@ -470,7 +442,6 @@ Hr’s:
470442
471443<hr class="foo" id="bar">
472444
473−
474445* * * * *
475446
476447# Inline Markup
@@ -497,9 +468,8 @@ Superscripts: a^bc^d a^*hello*^ a^hello there^.
497468
498469Subscripts: H~2~O, H~23~O, H~many of them~O.
499470
500−These should not be superscripts or subscripts, because of the
501−unescaped spaces: a\^b c\^d, a\~b c\~d.
502−
471+These should not be superscripts or subscripts, because of the unescaped
472+spaces: a\^b c\^d, a\~b c\~d.
503473
504474* * * * *
505475
@@ -513,8 +483,8 @@ unescaped spaces: a\^b c\^d, a\~b c\~d.
513483
514484‘He said, “I want to go.”’ Were you alive in the 70’s?
515485
516−Here is some quoted ‘`code`’ and a
517−“[quoted link](http://example.com/?foo=1&bar=2)”.
486+Here is some quoted ‘`code`’ and a “[quoted
487+link](http://example.com/?foo=1&bar=2)”.
518488
519489Some dashes: one—two — three—four — five.
520490
@@ -522,7 +492,6 @@ Dashes between numbers: 5–7, 255–66, 1987–1999.
522492
523493Ellipses…and…and….
524494
525−
526495* * * * *
527496
528497# LaTeX
@@ -535,14 +504,13 @@ Ellipses…and…and….
535504- $p$-Tree
536505- Here’s some display math:
537506 $$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$$
538−- Here’s one that has a line break in it:
539− $\alpha + \omega \times x^2$.
507+- Here’s one that has a line break in it: $\alpha + \omega \times x^2$.
540508
541509These shouldn’t be math:
542510
543511- To get the famous equation, write `$e = mc^2$`.
544−- $22,000 is a *lot* of money. So is $34,000. (It worked if “lot”
545− is emphasized.)
512+- $22,000 is a *lot* of money. So is $34,000. (It worked if “lot” is
513+ emphasized.)
546514- Shoes ($20) and socks ($5).
547515- Escaped `$`: $73 *this should be emphasized* 23$.
548516
@@ -554,7 +522,6 @@ Dog & 2 \\
554522Cat & 1 \\ \hline
555523\end{tabular}
556524
557−
558525* * * * *
559526
560527# Special Characters
@@ -609,7 +576,6 @@ Plus: +
609576
610577Minus: -
611578
612−
613579* * * * *
614580
615581# Links
@@ -662,8 +628,7 @@ Foo [biz](/url/ "Title with "quote" inside").
662628
663629## With ampersands
664630
665−Here’s a
666−[link with an ampersand in the URL](http://example.com/?foo=1&bar=2).
631+Here’s a [link with an ampersand in the URL](http://example.com/?foo=1&bar=2).
667632
668633Here’s a link with an amersand in the link text:
669634[AT&T](http://att.com/ "AT&T").
@@ -688,7 +653,6 @@ Auto-links should not occur here: `<http://example.com/>`
688653
689654 or here: <http://example.com/>
690655
691−
692656* * * * *
693657
694658# Images
@@ -699,44 +663,37 @@ From “Voyage dans la Lune” by Georges Melies (1902):
699663
700664Here is a movie ![movie](movie.jpg) icon.
701665
702−
703666* * * * *
704667
705668# Footnotes
706669
707−Here is a footnote reference,[^1] and another.[^2] This should
708−*not* be a footnote reference, because it contains a space.[\^my
709−note] Here is an inline note.[^3]
670+Here is a footnote reference,[^1] and another.[^2] This should *not* be a
671+footnote reference, because it contains a space.[\^my note] Here is an inline
672+note.[^3]
710673
711674> Notes can go in quotes.[^4]
712675
7136761. And in list items.[^5]
714677
715−This paragraph should not be part of the note, as it is not
716−indented.
678+This paragraph should not be part of the note, as it is not indented.
717679
718−[^1]:
719− Here is the footnote. It can go anywhere after the footnote
720− reference. It need not be placed at the end of the document.
680+[^1]: Here is the footnote. It can go anywhere after the footnote reference.
681+ It need not be placed at the end of the document.
721682
722−[^2]:
723− Here’s the long note. This one contains multiple blocks.
683+[^2]: Here’s the long note. This one contains multiple blocks.
724684
725− Subsequent blocks are indented to show that they belong to the
726− footnote (as with list items).
685+ Subsequent blocks are indented to show that they belong to the footnote
686+ (as with list items).
727687
728688 { <code> }
729689
730− If you want, you can indent every line, but you can also be lazy
731− and just indent the first line of each block.
690+ If you want, you can indent every line, but you can also be lazy and just
691+ indent the first line of each block.
732692
733−[^3]:
734− This is *easier* to type. Inline notes may contain
693+[^3]: This is *easier* to type. Inline notes may contain
735694 [links](http://google.com) and `]` verbatim characters, as well as
736695 [bracketed text].
737696
738−[^4]:
739− In quote.
697+[^4]: In quote.
740698
741−[^5]:
742− In list.
699+[^5]: In list.
tests/writer.org+85−197
@@ -3,8 +3,8 @@
33#+AUTHOR: John MacFarlane; Anonymous
44#+DATE: July 17, 2006
55
6−This is a set of tests for pandoc. Most of them are adapted from
7−John Gruber's markdown test suite.
6+This is a set of tests for pandoc. Most of them are adapted from John Gruber's
7+markdown test suite.
88
99--------------
1010
@@ -36,9 +36,9 @@ with no blank line
3636
3737Here's a regular paragraph.
3838
39−In Markdown 1.0.0 and earlier. Version 8. This line turns into a
40−list item. Because a hard-wrapped line in the middle of a paragraph
41−looked like a list item.
39+In Markdown 1.0.0 and earlier. Version 8. This line turns into a list item.
40+Because a hard-wrapped line in the middle of a paragraph looked like a list
41+item.
4242
4343Here's one with a bullet. * criminey.
4444
@@ -51,17 +51,11 @@ here.
5151
5252E-mail style:
5353
54−
5554#+BEGIN_QUOTE
56−
5755 This is a block quote. It is pretty short.
58−
59−
6056#+END_QUOTE
6157
62−
6358#+BEGIN_QUOTE
64−
6559 Code in a block quote:
6660
6761 #+BEGIN_EXAMPLE
@@ -69,31 +63,21 @@ E-mail style:
6963 print "working";
7064 }
7165 #+END_EXAMPLE
66+
7267 A list:
7368
74−
7569 1. item one
7670 2. item two
7771
7872 Nested block quotes:
7973
80−
81−#+BEGIN_QUOTE
82−
74+ #+BEGIN_QUOTE
8375 nested
76+ #+END_QUOTE
8477
85−
86−#+END_QUOTE
87−
88−
89−#+BEGIN_QUOTE
90−
78+ #+BEGIN_QUOTE
9179 nested
92−
93−
94−#+END_QUOTE
95−
96−
80+ #+END_QUOTE
9781#+END_QUOTE
9882
9983This should not be a block quote: 2 > 1.
@@ -108,20 +92,22 @@ Code:
10892
10993#+BEGIN_EXAMPLE
11094 ---- (should be four hyphens)
111−
95+
11296 sub status {
11397 print "working";
11498 }
115−
99+
116100 this code block is indented by one tab
117101#+END_EXAMPLE
102+
118103And:
119104
120105#+BEGIN_EXAMPLE
121106 this code block is indented by two tabs
122−
107+
123108 These should not be escaped: \$ \\ \> \[ \{
124109#+END_EXAMPLE
110+
125111--------------
126112
127113* Lists
@@ -130,121 +116,99 @@ And:
130116
131117Asterisks tight:
132118
133−
134119- asterisk 1
135120- asterisk 2
136121- asterisk 3
137122
138123Asterisks loose:
139124
140−
141125- asterisk 1
142126
143127- asterisk 2
144128
145129- asterisk 3
146130
147−
148131Pluses tight:
149132
150−
151133- Plus 1
152134- Plus 2
153135- Plus 3
154136
155137Pluses loose:
156138
157−
158139- Plus 1
159140
160141- Plus 2
161142
162143- Plus 3
163144
164−
165145Minuses tight:
166146
167−
168147- Minus 1
169148- Minus 2
170149- Minus 3
171150
172151Minuses loose:
173152
174−
175153- Minus 1
176154
177155- Minus 2
178156
179157- Minus 3
180158
181−
182159** Ordered
183160
184161Tight:
185162
186−
1871631. First
1881642. Second
1891653. Third
190166
191167and:
192168
193−
1941691. One
1951702. Two
1961713. Three
197172
198173Loose using tabs:
199174
200−
2011751. First
202176
2031772. Second
204178
2051793. Third
206180
207−
208181and using spaces:
209182
210−
2111831. One
212184
2131852. Two
214186
2151873. Three
216188
217−
218189Multiple paragraphs:
219190
220−
2211911. Item 1, graf one.
222192
223− Item 1. graf two. The quick brown fox jumped over the lazy dog's
224− back.
193+ Item 1. graf two. The quick brown fox jumped over the lazy dog's back.
225194
2261952. Item 2.
227196
2281973. Item 3.
229198
230−
231199** Nested
232200
233−
234201- Tab
235−
236− - Tab
237−
238− - Tab
239202
203+ - Tab
240204
205+ - Tab
241206
242207Here's another:
243208
244−
2452091. First
2462102. Second:
247−
211+
248212 - Fee
249213 - Fie
250214 - Foe
@@ -253,72 +217,55 @@ Here's another:
253217
254218Same thing but with paragraphs:
255219
256−
2572201. First
258221
2592222. Second:
260223
261−
262224 - Fee
263225 - Fie
264226 - Foe
265227
2662283. Third
267229
268−
269230** Tabs and spaces
270231
271−
272232- this is a list item indented with tabs
273233
274234- this is a list item indented with spaces
275235
276−
277236 - this is an example list item indented with tabs
278237
279238 - this is an example list item indented with spaces
280239
281−
282−
283240** Fancy list markers
284241
242+2) begins with 2
243+3) and now 3
285244
286−(2) begins with 2
287−(3) and now 3
288−
289− with a continuation
290−
291−
292− iv. sublist with roman numerals, starting with 4
293− v. more items
294−
295− (A) a subsublist
296− (B) a subsublist
245+ with a continuation
297246
247+ 4. sublist with roman numerals, starting with 4
248+ 5. more items
298249
250+ 1) a subsublist
251+ 2) a subsublist
299252
300253Nesting:
301254
255+1. Upper Alpha
302256
303−A. Upper Alpha
304−
305− I. Upper Roman.
306−
307− (6) Decimal start with 6
308−
309− c) Lower alpha with paren
310−
257+ 1. Upper Roman.
311258
259+ 6) Decimal start with 6
312260
261+ 3) Lower alpha with paren
313262
314263Autonumbering:
315264
316−
3172651. Autonumber.
3182662. More.
319−
320− 1. Nested.
321267
268+ 1. Nested.
322269
323270Should not be a list item:
324271
@@ -350,155 +297,123 @@ Loose:
350297
351298- banana :: yellow fruit
352299
353−
354300Multiple blocks with italics:
355301
356302- /apple/ :: red fruit
357303
358− contains seeds, crisp, pleasant to taste
304+ contains seeds, crisp, pleasant to taste
359305
360306- /orange/ :: orange fruit
361307
362− #+BEGIN_EXAMPLE
363− { orange code block }
364− #+END_EXAMPLE
365−
366−#+BEGIN_QUOTE
367−
368− orange block quote
369−
370−
371−#+END_QUOTE
308+ #+BEGIN_EXAMPLE
309+ { orange code block }
310+ #+END_EXAMPLE
372311
312+ #+BEGIN_QUOTE
313+ orange block quote
314+ #+END_QUOTE
373315
374316Multiple definitions, tight:
375317
376318- apple :: red fruit
377− computer
319+ computer
378320- orange :: orange fruit
379− bank
321+ bank
380322
381323Multiple definitions, loose:
382324
383325- apple :: red fruit
384326
385− computer
327+ computer
386328
387329- orange :: orange fruit
388330
389− bank
390−
331+ bank
391332
392333Blank line after term, indented marker, alternate markers:
393334
394335- apple :: red fruit
395336
396− computer
337+ computer
397338
398339- orange :: orange fruit
399340
400−
401− 1. sublist
402− 2. sublist
403−
341+ 1. sublist
342+ 2. sublist
404343
405344* HTML Blocks
406345
407346Simple block on one line:
408347
409−
410348#+BEGIN_HTML
411−
412349 <div>
413−
414350#+END_HTML
415351
416352foo
417353
418354#+BEGIN_HTML
419−
420355 </div>
421−
422356#+END_HTML
423357
424358And nested without indentation:
425359
426−
427360#+BEGIN_HTML
428−
429361 <div>
430362 <div>
431363 <div>
432−
433364#+END_HTML
434365
435366foo
436367
437368#+BEGIN_HTML
438−
439369 </div>
440370 </div>
441371 <div>
442−
443372#+END_HTML
444373
445374bar
446375
447376#+BEGIN_HTML
448−
449377 </div>
450378 </div>
451−
452379#+END_HTML
453380
454381Interpreted markdown in a table:
455382
456−
457383#+BEGIN_HTML
458−
459384 <table>
460385 <tr>
461386 <td>
462−
463387#+END_HTML
464388
465389This is /emphasized/
466390
467391#+BEGIN_HTML
468−
469392 </td>
470393 <td>
471−
472394#+END_HTML
473395
474396And this is *strong*
475397
476398#+BEGIN_HTML
477−
478399 </td>
479400 </tr>
480401 </table>
481−
482− <script type="text/javascript">document.write('This *should not* be interpreted as markdown');</script>
483402
403+ <script type="text/javascript">document.write('This *should not* be interpreted as markdown');</script>
484404#+END_HTML
485405
486406Here's a simple block:
487407
488−
489408#+BEGIN_HTML
490−
491409 <div>
492410
493−
494411#+END_HTML
495412
496413foo
497414
498415#+BEGIN_HTML
499−
500416 </div>
501−
502417#+END_HTML
503418
504419This should be a code block, though:
@@ -508,56 +423,47 @@ This should be a code block, though:
508423 foo
509424 </div>
510425#+END_EXAMPLE
426+
511427As should this:
512428
513429#+BEGIN_EXAMPLE
514430 <div>foo</div>
515431#+END_EXAMPLE
516−Now, nested:
517432
433+Now, nested:
518434
519435#+BEGIN_HTML
520−
521436 <div>
522437 <div>
523438 <div>
524439
525−
526440#+END_HTML
527441
528442foo
529443
530444#+BEGIN_HTML
531−
532445 </div>
533446 </div>
534447 </div>
535−
536448#+END_HTML
537449
538450This should just be an HTML comment:
539451
540−
541452#+BEGIN_HTML
542−
543453 <!-- Comment -->
544−
545454#+END_HTML
546455
547456Multiline:
548457
549−
550458#+BEGIN_HTML
551−
552459 <!--
553460 Blah
554461 Blah
555462 -->
556−
463+
557464 <!--
558465 This is another comment.
559466 -->
560−
561467#+END_HTML
562468
563469Code block:
@@ -565,13 +471,11 @@ Code block:
565471#+BEGIN_EXAMPLE
566472 <!-- Comment -->
567473#+END_EXAMPLE
568−Just plain comment, with trailing spaces on the line:
569474
475+Just plain comment, with trailing spaces on the line:
570476
571477#+BEGIN_HTML
572−
573478 <!-- foo -->
574−
575479#+END_HTML
576480
577481Code:
@@ -579,29 +483,27 @@ Code:
579483#+BEGIN_EXAMPLE
580484 <hr />
581485#+END_EXAMPLE
582−Hr's:
583486
487+Hr's:
584488
585489#+BEGIN_HTML
586−
587490 <hr>
588−
491+
589492 <hr />
590−
493+
591494 <hr />
592−
495+
593496 <hr>
594−
497+
595498 <hr />
596−
499+
597500 <hr />
598−
501+
599502 <hr class="foo" id="bar" />
600−
503+
601504 <hr class="foo" id="bar" />
602−
603− <hr class="foo" id="bar">
604505
506+ <hr class="foo" id="bar">
605507#+END_HTML
606508
607509--------------
@@ -630,8 +532,8 @@ Superscripts: a^{bc}d a^{/hello/} a^{hello there}.
630532
631533Subscripts: H_{2}O, H_{23}O, H_{many of them}O.
632534
633−These should not be superscripts or subscripts, because of the
634−unescaped spaces: a\^b c\^d, a~b c~d.
535+These should not be superscripts or subscripts, because of the unescaped
536+spaces: a\^b c\^d, a~b c~d.
635537
636538--------------
637539
@@ -645,8 +547,8 @@ unescaped spaces: a\^b c\^d, a~b c~d.
645547
646548'He said, "I want to go."' Were you alive in the 70's?
647549
648−Here is some quoted '=code=' and a
649−"[[http://example.com/?foo=1&bar=2][quoted link]]".
550+Here is some quoted '=code=' and a "[[http://example.com/?foo=1&bar=2][quoted
551+link]]".
650552
651553Some dashes: one---two --- three---four --- five.
652554
@@ -658,7 +560,6 @@ Ellipses...and...and....
658560
659561* LaTeX
660562
661−
662563- \cite[22-23]{smith.1899}
663564- $2+2=4$
664565- $x \in y$
@@ -667,15 +568,13 @@ Ellipses...and...and....
667568- $p$-Tree
668569- Here's some display math:
669570 $$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$$
670−- Here's one that has a line break in it:
671− $\alpha + \omega \times x^2$.
571+- Here's one that has a line break in it: $\alpha + \omega \times x^2$.
672572
673573These shouldn't be math:
674574
675−
676575- To get the famous equation, write =$e = mc^2$=.
677−- $22,000 is a /lot/ of money. So is $34,000. (It worked if "lot"
678− is emphasized.)
576+- $22,000 is a /lot/ of money. So is $34,000. (It worked if "lot" is
577+ emphasized.)
679578- Shoes ($20) and socks ($5).
680579- Escaped =$=: $73 /this should be emphasized/ 23$.
681580
@@ -693,7 +592,6 @@ Cat & 1 \\ \hline
693592
694593Here is some unicode:
695594
696−
697595- I hat: Î
698596- o umlaut: ö
699597- section: §
@@ -789,17 +687,17 @@ This should [not][] be a link.
789687#+BEGIN_EXAMPLE
790688 [not]: /url
791689#+END_EXAMPLE
690+
792691Foo [[/url/][bar]].
793692
794693Foo [[/url/][biz]].
795694
796695** With ampersands
797696
798−Here's a
799−[[http://example.com/?foo=1&bar=2][link with an ampersand in the URL]].
697+Here's a [[http://example.com/?foo=1&bar=2][link with an ampersand in the
698+URL]].
800699
801−Here's a link with an amersand in the link text:
802−[[http://att.com/][AT&T]].
700+Here's a link with an amersand in the link text: [[http://att.com/][AT&T]].
803701
804702Here's an [[/script?foo=1&bar=2][inline link]].
805703
@@ -809,20 +707,14 @@ Here's an [[/script?foo=1&bar=2][inline link in pointy braces]].
809707
810708With an ampersand: [[http://example.com/?foo=1&bar=2]]
811709
812−
813710- In a list?
814711- [[http://example.com/]]
815712- It should.
816713
817−An e-mail address:
818−[[mailto:nobody@nowhere.net][=nobody@nowhere.net=]]
819−
714+An e-mail address: [[mailto:nobody@nowhere.net][=nobody@nowhere.net=]]
820715
821716#+BEGIN_QUOTE
822−
823717 Blockquoted: [[http://example.com/]]
824−
825−
826718#+END_QUOTE
827719
828720Auto-links should not occur here: =<http://example.com/>=
@@ -830,6 +722,7 @@ Auto-links should not occur here: =<http://example.com/>=
830722#+BEGIN_EXAMPLE
831723 or here: <http://example.com/>
832724#+END_EXAMPLE
725+
833726--------------
834727
835728* Images
@@ -845,41 +738,36 @@ Here is a movie [[movie.jpg]] icon.
845738
846739* Footnotes
847740
848−Here is a footnote reference, [1] and another. [2] This should
849−/not/ be a footnote reference, because it contains a space.[\^my
850−note] Here is an inline note. [3]
851−
741+Here is a footnote reference, [1] and another. [2] This should /not/ be a
742+footnote reference, because it contains a space.[\^my note] Here is an inline
743+note. [3]
852744
853745#+BEGIN_QUOTE
854−
855746 Notes can go in quotes. [4]
856−
857−
858747#+END_QUOTE
859748
860−
8617491. And in list items. [5]
862750
863−This paragraph should not be part of the note, as it is not
864−indented.
751+This paragraph should not be part of the note, as it is not indented.
865752
866−[1] Here is the footnote. It can go anywhere after the footnote
867− reference. It need not be placed at the end of the document.
753+[1] Here is the footnote. It can go anywhere after the footnote reference. It
754+ need not be placed at the end of the document.
868755
869756[2] Here's the long note. This one contains multiple blocks.
870757
871− Subsequent blocks are indented to show that they belong to the
872− footnote (as with list items).
758+ Subsequent blocks are indented to show that they belong to the footnote
759+ (as with list items).
873760
874761 #+BEGIN_EXAMPLE
875762 { <code> }
876763 #+END_EXAMPLE
877− If you want, you can indent every line, but you can also be lazy
878− and just indent the first line of each block.
764+
765+ If you want, you can indent every line, but you can also be lazy and just
766+ indent the first line of each block.
879767
880768[3] This is /easier/ to type. Inline notes may contain
881− [[http://google.com][links]] and =]= verbatim characters, as well
882− as [bracketed text].
769+ [[http://google.com][links]] and =]= verbatim characters, as well as
770+ [bracketed text].
883771
884772[4] In quote.
885773
tests/writer.plain+37−81
@@ -2,9 +2,8 @@ Pandoc Test Suite
22John MacFarlane; Anonymous
33July 17, 2006
44
5−This is a set of tests for pandoc. Most of them are adapted from
6−John Gruber’s markdown test suite.
7−
5+This is a set of tests for pandoc. Most of them are adapted from John Gruber’s
6+markdown test suite.
87
98* * * * *
109
@@ -35,7 +34,6 @@ Level 2
3534
3635with no blank line
3736
38−
3937* * * * *
4038
4139Paragraphs
@@ -43,16 +41,15 @@ Paragraphs
4341
4442Here’s a regular paragraph.
4543
46−In Markdown 1.0.0 and earlier. Version 8. This line turns into a
47−list item. Because a hard-wrapped line in the middle of a paragraph
48−looked like a list item.
44+In Markdown 1.0.0 and earlier. Version 8. This line turns into a list item.
45+Because a hard-wrapped line in the middle of a paragraph looked like a list
46+item.
4947
5048Here’s one with a bullet. * criminey.
5149
5250There should be a hard line break
5351here.
5452
55−
5653* * * * *
5754
5855Block Quotes
@@ -63,27 +60,26 @@ E-mail style:
6360 This is a block quote. It is pretty short.
6461
6562 Code in a block quote:
66−
63+
6764 sub status {
6865 print "working";
6966 }
70−
67+
7168 A list:
72−
69+
7370 1. item one
7471 2. item two
75−
72+
7673 Nested block quotes:
77−
74+
7875 nested
79−
76+
8077 nested
8178
8279This should not be a block quote: 2 > 1.
8380
8481And a following paragraph.
8582
86−
8783* * * * *
8884
8985Code Blocks
@@ -92,19 +88,18 @@ Code Blocks
9288Code:
9389
9490 ---- (should be four hyphens)
95−
91+
9692 sub status {
9793 print "working";
9894 }
99−
95+
10096 this code block is indented by one tab
10197
10298And:
10399
104100 this code block is indented by two tabs
105−
106− These should not be escaped: \$ \\ \> \[ \{
107101
102+ These should not be escaped: \$ \\ \> \[ \{
108103
109104* * * * *
110105
@@ -128,7 +123,6 @@ Asterisks loose:
128123
129124- asterisk 3
130125
131−
132126Pluses tight:
133127
134128- Plus 1
@@ -143,7 +137,6 @@ Pluses loose:
143137
144138- Plus 3
145139
146−
147140Minuses tight:
148141
149142- Minus 1
@@ -158,7 +151,6 @@ Minuses loose:
158151
159152- Minus 3
160153
161−
162154Ordered
163155-------
164156
@@ -182,7 +174,6 @@ Loose using tabs:
182174
1831753. Third
184176
185−
186177and using spaces:
187178
1881791. One
@@ -191,19 +182,16 @@ and using spaces:
191182
1921833. Three
193184
194−
195185Multiple paragraphs:
196186
1971871. Item 1, graf one.
198188
199− Item 1. graf two. The quick brown fox jumped over the lazy dog’s
200− back.
189+ Item 1. graf two. The quick brown fox jumped over the lazy dog’s back.
201190
2021912. Item 2.
203192
2041933. Item 3.
205194
206−
207195Nested
208196------
209197
@@ -211,8 +199,6 @@ Nested
211199 - Tab
212200 - Tab
213201
214−
215−
216202Here’s another:
217203
2182041. First
@@ -235,7 +221,6 @@ Same thing but with paragraphs:
235221
2362223. Third
237223
238−
239224Tabs and spaces
240225---------------
241226
@@ -247,8 +232,6 @@ Tabs and spaces
247232
248233 - this is an example list item indented with spaces
249234
250−
251−
252235Fancy list markers
253236------------------
254237
@@ -262,8 +245,6 @@ Fancy list markers
262245 (A) a subsublist
263246 (B) a subsublist
264247
265−
266−
267248Nesting:
268249
269250A. Upper Alpha
@@ -271,23 +252,18 @@ A. Upper Alpha
271252 (6) Decimal start with 6
272253 c) Lower alpha with paren
273254
274−
275−
276−
277255Autonumbering:
278256
2792571. Autonumber.
2802582. More.
281259 1. Nested.
282260
283−
284261Should not be a list item:
285262
286263M.A. 2007
287264
288265B. Williams
289266
290−
291267* * * * *
292268
293269Definition Lists
@@ -322,7 +298,6 @@ orange
322298banana
323299 yellow fruit
324300
325−
326301Multiple blocks with italics:
327302
328303apple
@@ -337,7 +312,6 @@ orange
337312
338313 orange block quote
339314
340−
341315Multiple definitions, tight:
342316
343317apple
@@ -359,7 +333,6 @@ orange
359333
360334 bank
361335
362−
363336Blank line after term, indented marker, alternate markers:
364337
365338apple
@@ -373,7 +346,6 @@ orange
373346 1. sublist
374347 2. sublist
375348
376−
377349HTML Blocks
378350===========
379351
@@ -420,7 +392,6 @@ Code:
420392
421393Hr’s:
422394
423−
424395* * * * *
425396
426397Inline Markup
@@ -448,9 +419,8 @@ Superscripts: abcd ahello ahello there.
448419
449420Subscripts: H2O, H23O, Hmany of themO.
450421
451−These should not be superscripts or subscripts, because of the
452−unescaped spaces: a^b c^d, a~b c~d.
453−
422+These should not be superscripts or subscripts, because of the unescaped
423+spaces: a^b c^d, a~b c~d.
454424
455425* * * * *
456426
@@ -473,7 +443,6 @@ Dashes between numbers: 5–7, 255–66, 1987–1999.
473443
474444Ellipses…and…and….
475445
476−
477446* * * * *
478447
479448LaTeX
@@ -487,22 +456,18 @@ LaTeX
487456- p-Tree
488457- Here’s some display math:
489458 \frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}
490−- Here’s one that has a line break in it:
491− \alpha + \omega \times x^2.
459+- Here’s one that has a line break in it: \alpha + \omega \times x^2.
492460
493461These shouldn’t be math:
494462
495463- To get the famous equation, write $e = mc^2$.
496−- $22,000 is a lot of money. So is $34,000. (It worked if “lot”
497− is emphasized.)
464+- $22,000 is a lot of money. So is $34,000. (It worked if “lot” is
465+ emphasized.)
498466- Shoes ($20) and socks ($5).
499467- Escaped $: $73 this should be emphasized 23$.
500468
501469Here’s a LaTeX table:
502470
503−
504−
505−
506471* * * * *
507472
508473Special Characters
@@ -558,7 +523,6 @@ Plus: +
558523
559524Minus: -
560525
561−
562526* * * * *
563527
564528Links
@@ -640,7 +604,6 @@ Auto-links should not occur here: <http://example.com/>
640604
641605 or here: <http://example.com/>
642606
643−
644607* * * * *
645608
646609Images
@@ -648,48 +611,41 @@ Images
648611
649612From “Voyage dans la Lune” by Georges Melies (1902):
650613
614+[lalune]
651615
652−
653−Here is a movie icon.
654−
616+Here is a movie [movie] icon.
655617
656618* * * * *
657619
658620Footnotes
659621=========
660622
661−Here is a footnote reference,[^1] and another.[^2] This should not
662−be a footnote reference, because it contains a space.[^my note]
663−Here is an inline note.[^3]
623+Here is a footnote reference,[^1] and another.[^2] This should not be a
624+footnote reference, because it contains a space.[^my note] Here is an inline
625+note.[^3]
664626
665627 Notes can go in quotes.[^4]
666628
6676291. And in list items.[^5]
668630
669−This paragraph should not be part of the note, as it is not
670−indented.
631+This paragraph should not be part of the note, as it is not indented.
671632
672−[^1]:
673− Here is the footnote. It can go anywhere after the footnote
674− reference. It need not be placed at the end of the document.
633+[^1]: Here is the footnote. It can go anywhere after the footnote reference.
634+ It need not be placed at the end of the document.
675635
676−[^2]:
677− Here’s the long note. This one contains multiple blocks.
636+[^2]: Here’s the long note. This one contains multiple blocks.
678637
679− Subsequent blocks are indented to show that they belong to the
680− footnote (as with list items).
638+ Subsequent blocks are indented to show that they belong to the footnote
639+ (as with list items).
681640
682641 { <code> }
683642
684− If you want, you can indent every line, but you can also be lazy
685− and just indent the first line of each block.
643+ If you want, you can indent every line, but you can also be lazy and just
644+ indent the first line of each block.
686645
687−[^3]:
688− This is easier to type. Inline notes may contain links and ]
689− verbatim characters, as well as [bracketed text].
646+[^3]: This is easier to type. Inline notes may contain links and ] verbatim
647+ characters, as well as [bracketed text].
690648
691−[^4]:
692− In quote.
649+[^4]: In quote.
693650
694−[^5]:
695− In list.
651+[^5]: In list.
tests/writer.rst+67−140
@@ -9,8 +9,8 @@ Pandoc Test Suite
99.. role:: math(raw)
1010 :format: html latex
1111
12−This is a set of tests for pandoc. Most of them are adapted from
13−John Gruber’s markdown test suite.
12+This is a set of tests for pandoc. Most of them are adapted from John Gruber’s
13+markdown test suite.
1414
1515--------------
1616
@@ -52,9 +52,9 @@ Paragraphs
5252
5353Here’s a regular paragraph.
5454
55−In Markdown 1.0.0 and earlier. Version 8. This line turns into a
56−list item. Because a hard-wrapped line in the middle of a paragraph
57−looked like a list item.
55+In Markdown 1.0.0 and earlier. Version 8. This line turns into a list item.
56+Because a hard-wrapped line in the middle of a paragraph looked like a list
57+item.
5858
5959Here’s one with a bullet. \* criminey.
6060
@@ -70,7 +70,6 @@ E-mail style:
7070
7171 This is a block quote. It is pretty short.
7272
73−
7473 Code in a block quote:
7574
7675 ::
@@ -81,7 +80,6 @@ E-mail style:
8180
8281 A list:
8382
84−
8583 1. item one
8684 2. item two
8785
@@ -89,11 +87,8 @@ E-mail style:
8987
9088 nested
9189
92−
9390 nested
9491
95−
96−
9792This should not be a block quote: 2 > 1.
9893
9994And a following paragraph.
@@ -108,11 +103,11 @@ Code:
108103::
109104
110105 ---- (should be four hyphens)
111−
106+
112107 sub status {
113108 print "working";
114109 }
115−
110+
116111 this code block is indented by one tab
117112
118113And:
@@ -120,7 +115,7 @@ And:
120115::
121116
122117 this code block is indented by two tabs
123−
118+
124119 These should not be escaped: \$ \\ \> \[ \{
125120
126121--------------
@@ -133,123 +128,101 @@ Unordered
133128
134129Asterisks tight:
135130
136−
137131- asterisk 1
138132- asterisk 2
139133- asterisk 3
140134
141135Asterisks loose:
142136
143−
144137- asterisk 1
145138
146139- asterisk 2
147140
148141- asterisk 3
149142
150−
151143Pluses tight:
152144
153−
154145- Plus 1
155146- Plus 2
156147- Plus 3
157148
158149Pluses loose:
159150
160−
161151- Plus 1
162152
163153- Plus 2
164154
165155- Plus 3
166156
167−
168157Minuses tight:
169158
170−
171159- Minus 1
172160- Minus 2
173161- Minus 3
174162
175163Minuses loose:
176164
177−
178165- Minus 1
179166
180167- Minus 2
181168
182169- Minus 3
183170
184−
185171Ordered
186172-------
187173
188174Tight:
189175
190−
1911761. First
1921772. Second
1931783. Third
194179
195180and:
196181
197−
1981821. One
1991832. Two
2001843. Three
201185
202186Loose using tabs:
203187
204−
2051881. First
206189
2071902. Second
208191
2091923. Third
210193
211−
212194and using spaces:
213195
214−
2151961. One
216197
2171982. Two
218199
2192003. Three
220201
221−
222202Multiple paragraphs:
223203
224−
2252041. Item 1, graf one.
226205
227− Item 1. graf two. The quick brown fox jumped over the lazy dog’s
228− back.
206+ Item 1. graf two. The quick brown fox jumped over the lazy dog’s back.
229207
2302082. Item 2.
231209
2322103. Item 3.
233211
234−
235212Nested
236213------
237214
238−
239215- Tab
240−
241− - Tab
242−
243− - Tab
244216
217+ - Tab
245218
219+ - Tab
246220
247221Here’s another:
248222
249−
2502231. First
2512242. Second:
252−
225+
253226 - Fee
254227 - Fie
255228 - Foe
@@ -258,74 +231,57 @@ Here’s another:
258231
259232Same thing but with paragraphs:
260233
261−
2622341. First
263235
2642362. Second:
265237
266−
267238 - Fee
268239 - Fie
269240 - Foe
270241
2712423. Third
272243
273−
274244Tabs and spaces
275245---------------
276246
277−
278247- this is a list item indented with tabs
279248
280249- this is a list item indented with spaces
281250
282−
283251 - this is an example list item indented with tabs
284252
285253 - this is an example list item indented with spaces
286254
287−
288−
289255Fancy list markers
290256------------------
291257
292−
293258(2) begins with 2
294259(3) and now 3
295260
296261 with a continuation
297262
298−
299263 iv. sublist with roman numerals, starting with 4
300264 v. more items
301−
265+
302266 (A) a subsublist
303267 (B) a subsublist
304268
305−
306−
307269Nesting:
308270
309−
310271A. Upper Alpha
311−
312− I. Upper Roman.
313−
314− (6) Decimal start with 6
315−
316− c) Lower alpha with paren
317272
273+ I. Upper Roman.
318274
275+ (6) Decimal start with 6
319276
277+ c) Lower alpha with paren
320278
321279Autonumbering:
322280
323−
324281#. Autonumber.
325282#. More.
326−
327− #. Nested.
328283
284+ #. Nested.
329285
330286Should not be a list item:
331287
@@ -367,7 +323,6 @@ orange
367323banana
368324 yellow fruit
369325
370−
371326Multiple blocks with italics:
372327
373328*apple*
@@ -384,8 +339,6 @@ Multiple blocks with italics:
384339
385340 orange block quote
386341
387−
388−
389342Multiple definitions, tight:
390343
391344apple
@@ -407,7 +360,6 @@ orange
407360
408361 bank
409362
410−
411363Blank line after term, indented marker, alternate markers:
412364
413365apple
@@ -418,36 +370,32 @@ apple
418370orange
419371 orange fruit
420372
421−
422373 1. sublist
423374 2. sublist
424375
425−
426376HTML Blocks
427377===========
428378
429379Simple block on one line:
430380
431−
432381.. raw:: html
433382
434383 <div>
435−
384+
436385foo
437386
438387.. raw:: html
439388
440389 </div>
441−
442−And nested without indentation:
443390
391+And nested without indentation:
444392
445393.. raw:: html
446394
447395 <div>
448396 <div>
449397 <div>
450−
398+
451399foo
452400
453401.. raw:: html
@@ -455,30 +403,29 @@ foo
455403 </div>
456404 </div>
457405 <div>
458−
406+
459407bar
460408
461409.. raw:: html
462410
463411 </div>
464412 </div>
465−
466−Interpreted markdown in a table:
467413
414+Interpreted markdown in a table:
468415
469416.. raw:: html
470417
471418 <table>
472419 <tr>
473420 <td>
474−
421+
475422This is *emphasized*
476423
477424.. raw:: html
478425
479426 </td>
480427 <td>
481−
428+
482429And this is **strong**
483430
484431.. raw:: html
@@ -486,23 +433,22 @@ And this is **strong**
486433 </td>
487434 </tr>
488435 </table>
489−
436+
490437 <script type="text/javascript">document.write('This *should not* be interpreted as markdown');</script>
491−
492−Here’s a simple block:
493438
439+Here’s a simple block:
494440
495441.. raw:: html
496442
497443 <div>
498444
499−
445+
500446foo
501447
502448.. raw:: html
503449
504450 </div>
505−
451+
506452This should be a code block, though:
507453
508454::
@@ -519,14 +465,13 @@ As should this:
519465
520466Now, nested:
521467
522−
523468.. raw:: html
524469
525470 <div>
526471 <div>
527472 <div>
528473
529−
474+
530475foo
531476
532477.. raw:: html
@@ -534,16 +479,14 @@ foo
534479 </div>
535480 </div>
536481 </div>
537−
538−This should just be an HTML comment:
539482
483+This should just be an HTML comment:
540484
541485.. raw:: html
542486
543487 <!-- Comment -->
544−
545−Multiline:
546488
489+Multiline:
547490
548491.. raw:: html
549492
@@ -551,11 +494,11 @@ Multiline:
551494 Blah
552495 Blah
553496 -->
554−
497+
555498 <!--
556499 This is another comment.
557500 -->
558−
501+
559502Code block:
560503
561504::
@@ -564,11 +507,10 @@ Code block:
564507
565508Just plain comment, with trailing spaces on the line:
566509
567−
568510.. raw:: html
569511
570512 <!-- foo -->
571−
513+
572514Code:
573515
574516::
@@ -577,27 +519,26 @@ Code:
577519
578520Hr’s:
579521
580−
581522.. raw:: html
582523
583524 <hr>
584−
525+
585526 <hr />
586−
527+
587528 <hr />
588−
529+
589530 <hr>
590−
531+
591532 <hr />
592−
533+
593534 <hr />
594−
535+
595536 <hr class="foo" id="bar" />
596−
537+
597538 <hr class="foo" id="bar" />
598−
539+
599540 <hr class="foo" id="bar">
600−
541+
601542--------------
602543
603544Inline Markup
@@ -621,14 +562,12 @@ This is code: ``>``, ``$``, ``\``, ``\$``, ``<html>``.
621562
622563[STRIKEOUT:This is *strikeout*.]
623564
624−Superscripts: a\ :sup:`bc`\ d a\ :sup:`*hello*`\
625−a\ :sup:`hello there`\ .
565+Superscripts: a\ :sup:`bc`\ d a\ :sup:`*hello*`\ a\ :sup:`hello there`\ .
626566
627−Subscripts: H\ :sub:`2`\ O, H\ :sub:`23`\ O,
628−H\ :sub:`many of them`\ O.
567+Subscripts: H\ :sub:`2`\ O, H\ :sub:`23`\ O, H\ :sub:`many of them`\ O.
629568
630−These should not be superscripts or subscripts, because of the
631−unescaped spaces: a^b c^d, a~b c~d.
569+These should not be superscripts or subscripts, because of the unescaped
570+spaces: a^b c^d, a~b c~d.
632571
633572--------------
634573
@@ -643,8 +582,8 @@ Smart quotes, ellipses, dashes
643582
644583‘He said, “I want to go.”’ Were you alive in the 70’s?
645584
646−Here is some quoted ‘``code``’ and a
647−“`quoted link <http://example.com/?foo=1&bar=2>`_”.
585+Here is some quoted ‘``code``’ and a “`quoted
586+link <http://example.com/?foo=1&bar=2>`_”.
648587
649588Some dashes: one—two — three—four — five.
650589
@@ -657,7 +596,6 @@ Ellipses…and…and….
657596LaTeX
658597=====
659598
660−
661599-
662600- :math:`$2+2=4$`
663601- :math:`$x \in y$`
@@ -671,17 +609,14 @@ LaTeX
671609
672610These shouldn’t be math:
673611
674−
675612- To get the famous equation, write ``$e = mc^2$``.
676−- $22,000 is a *lot* of money. So is $34,000. (It worked if “lot”
677− is emphasized.)
613+- $22,000 is a *lot* of money. So is $34,000. (It worked if “lot” is
614+ emphasized.)
678615- Shoes ($20) and socks ($5).
679616- Escaped ``$``: $73 *this should be emphasized* 23$.
680617
681618Here’s a LaTeX table:
682619
683−
684−
685620--------------
686621
687622Special Characters
@@ -689,7 +624,6 @@ Special Characters
689624
690625Here is some unicode:
691626
692−
693627- I hat: Î
694628- o umlaut: ö
695629- section: §
@@ -796,11 +730,10 @@ Foo `biz </url/>`_.
796730With ampersands
797731---------------
798732
799−Here’s a
800−`link with an ampersand in the URL <http://example.com/?foo=1&bar=2>`_.
733+Here’s a `link with an ampersand in the
734+URL <http://example.com/?foo=1&bar=2>`_.
801735
802−Here’s a link with an amersand in the link text:
803−`AT&T <http://att.com/>`_.
736+Here’s a link with an amersand in the link text: `AT&T <http://att.com/>`_.
804737
805738Here’s an `inline link </script?foo=1&bar=2>`_.
806739
@@ -811,7 +744,6 @@ Autolinks
811744
812745With an ampersand: http://example.com/?foo=1&bar=2
813746
814−
815747- In a list?
816748- http://example.com/
817749- It should.
@@ -820,7 +752,6 @@ An e-mail address: nobody@nowhere.net
820752
821753 Blockquoted: http://example.com/
822754
823−
824755Auto-links should not occur here: ``<http://example.com/>``
825756
826757::
@@ -837,9 +768,8 @@ From “Voyage dans la Lune” by Georges Melies (1902):
837768.. figure:: lalune.jpg
838769 :align: center
839770 :alt: Voyage dans la Lune
840−
841− lalune
842771
772+ lalune
843773Here is a movie |movie| icon.
844774
845775--------------
@@ -847,40 +777,37 @@ Here is a movie |movie| icon.
847777Footnotes
848778=========
849779
850−Here is a footnote reference, [1]_ and another. [2]_ This should
851−*not* be a footnote reference, because it contains a space.[^my
852−note] Here is an inline note. [3]_
780+Here is a footnote reference, [1]_ and another. [2]_ This should *not* be a
781+footnote reference, because it contains a space.[^my note] Here is an inline
782+note. [3]_
853783
854784 Notes can go in quotes. [4]_
855785
856−
857−
8587861. And in list items. [5]_
859787
860−This paragraph should not be part of the note, as it is not
861−indented.
788+This paragraph should not be part of the note, as it is not indented.
862789
863790.. [1]
864− Here is the footnote. It can go anywhere after the footnote
865− reference. It need not be placed at the end of the document.
791+ Here is the footnote. It can go anywhere after the footnote reference. It
792+ need not be placed at the end of the document.
866793
867794.. [2]
868795 Here’s the long note. This one contains multiple blocks.
869796
870− Subsequent blocks are indented to show that they belong to the
871− footnote (as with list items).
797+ Subsequent blocks are indented to show that they belong to the footnote (as
798+ with list items).
872799
873800 ::
874801
875802 { <code> }
876803
877− If you want, you can indent every line, but you can also be lazy
878− and just indent the first line of each block.
804+ If you want, you can indent every line, but you can also be lazy and just
805+ indent the first line of each block.
879806
880807.. [3]
881808 This is *easier* to type. Inline notes may contain
882− `links <http://google.com>`_ and ``]`` verbatim characters, as well
883− as [bracketed text].
809+ `links <http://google.com>`_ and ``]`` verbatim characters, as well as
810+ [bracketed text].
884811
885812.. [4]
886813 In quote.