git.iko.soy/typeable/pandoc
on master help sign in
Fixed whitespace errors.
6d7f0a1John MacFarlane
src/Text/Pandoc/MIME.hs+1−1
@@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19{- |
19{- |
20 Module : Text.Pandoc.MIME
20 Module : Text.Pandoc.MIME
21 Copyright : Copyright (C) 2011 John MacFarlane
21 Copyright : Copyright (C) 2011 John MacFarlane
22− License : GNU GPL, version 2 or above
22+ License : GNU GPL, version 2 or above
23
23
24 Maintainer : John MacFarlane <jgm@berkeley.edu>
24 Maintainer : John MacFarlane <jgm@berkeley.edu>
25 Stability : alpha
25 Stability : alpha
src/Text/Pandoc/Parsing.hs+25−25
@@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19{- |
19{- |
20 Module : Text.Pandoc.Parsing
20 Module : Text.Pandoc.Parsing
21 Copyright : Copyright (C) 2006-2010 John MacFarlane
21 Copyright : Copyright (C) 2006-2010 John MacFarlane
22− License : GNU GPL, version 2 or above
22+ License : GNU GPL, version 2 or above
23
23
24 Maintainer : John MacFarlane <jgm@berkeley.edu>
24 Maintainer : John MacFarlane <jgm@berkeley.edu>
25 Stability : alpha
25 Stability : alpha
@@ -167,7 +167,7 @@ many1Till p end = do
167 rest <- manyTill p end
167 rest <- manyTill p end
168 return (first:rest)
168 return (first:rest)
169
169
170−-- | A more general form of @notFollowedBy@. This one allows any
170+-- | A more general form of @notFollowedBy@. This one allows any
171-- type of parser to be specified, and succeeds only if that parser fails.
171-- type of parser to be specified, and succeeds only if that parser fails.
172-- It does not consume any input.
172-- It does not consume any input.
173notFollowedBy' :: Show b => Parsec [a] st b -> Parsec [a] st ()
173notFollowedBy' :: Show b => Parsec [a] st b -> Parsec [a] st ()
@@ -213,7 +213,7 @@ enclosed :: Parsec [Char] st t -- ^ start parser
213 -> Parsec [Char] st end -- ^ end parser
213 -> Parsec [Char] st end -- ^ end parser
214 -> Parsec [Char] st a -- ^ content parser (to be used repeatedly)
214 -> Parsec [Char] st a -- ^ content parser (to be used repeatedly)
215 -> Parsec [Char] st [a]
215 -> Parsec [Char] st [a]
216−enclosed start end parser = try $
216+enclosed start end parser = try $
217 start >> notFollowedBy space >> many1Till parser end
217 start >> notFollowedBy space >> many1Till parser end
218
218
219-- | Parse string, case insensitive.
219-- | Parse string, case insensitive.
@@ -237,7 +237,7 @@ parseFromString parser str = do
237
237
238-- | Parse raw line block up to and including blank lines.
238-- | Parse raw line block up to and including blank lines.
239lineClump :: Parsec [Char] st String
239lineClump :: Parsec [Char] st String
240−lineClump = blanklines
240+lineClump = blanklines
241 <|> (many1 (notFollowedBy blankline >> anyLine) >>= return . unlines)
241 <|> (many1 (notFollowedBy blankline >> anyLine) >>= return . unlines)
242
242
243-- | Parse a string of characters between an open character
243-- | Parse a string of characters between an open character
@@ -273,11 +273,11 @@ uppercaseRomanDigits = map toUpper lowercaseRomanDigits
273romanNumeral :: Bool -- ^ Uppercase if true
273romanNumeral :: Bool -- ^ Uppercase if true
274 -> Parsec [Char] st Int
274 -> Parsec [Char] st Int
275romanNumeral upperCase = do
275romanNumeral upperCase = do
276− let romanDigits = if upperCase
276+ let romanDigits = if upperCase
277− then uppercaseRomanDigits
277+ then uppercaseRomanDigits
278 else lowercaseRomanDigits
278 else lowercaseRomanDigits
279 lookAhead $ oneOf romanDigits
279 lookAhead $ oneOf romanDigits
280− let [one, five, ten, fifty, hundred, fivehundred, thousand] =
280+ let [one, five, ten, fifty, hundred, fivehundred, thousand] =
281 map char romanDigits
281 map char romanDigits
282 thousands <- many thousand >>= (return . (1000 *) . length)
282 thousands <- many thousand >>= (return . (1000 *) . length)
283 ninehundreds <- option 0 $ try $ hundred >> thousand >> return 900
283 ninehundreds <- option 0 $ try $ hundred >> thousand >> return 900
@@ -468,15 +468,15 @@ romanOne = (char 'i' >> return (LowerRoman, 1)) <|>
468 (char 'I' >> return (UpperRoman, 1))
468 (char 'I' >> return (UpperRoman, 1))
469
469
470-- | Parses an ordered list marker and returns list attributes.
470-- | Parses an ordered list marker and returns list attributes.
471−anyOrderedListMarker :: Parsec [Char] ParserState ListAttributes
471+anyOrderedListMarker :: Parsec [Char] ParserState ListAttributes
472−anyOrderedListMarker = choice $
472+anyOrderedListMarker = choice $
473 [delimParser numParser | delimParser <- [inPeriod, inOneParen, inTwoParens],
473 [delimParser numParser | delimParser <- [inPeriod, inOneParen, inTwoParens],
474 numParser <- [decimal, exampleNum, defaultNum, romanOne,
474 numParser <- [decimal, exampleNum, defaultNum, romanOne,
475 lowerAlpha, lowerRoman, upperAlpha, upperRoman]]
475 lowerAlpha, lowerRoman, upperAlpha, upperRoman]]
476
476
477-- | Parses a list number (num) followed by a period, returns list attributes.
477-- | Parses a list number (num) followed by a period, returns list attributes.
478inPeriod :: Parsec [Char] st (ListNumberStyle, Int)
478inPeriod :: Parsec [Char] st (ListNumberStyle, Int)
479− -> Parsec [Char] st ListAttributes
479+ -> Parsec [Char] st ListAttributes
480inPeriod num = try $ do
480inPeriod num = try $ do
481 (style, start) <- num
481 (style, start) <- num
482 char '.'
482 char '.'
@@ -484,10 +484,10 @@ inPeriod num = try $ do
484 then DefaultDelim
484 then DefaultDelim
485 else Period
485 else Period
486 return (start, style, delim)
486 return (start, style, delim)
487−
487+
488-- | Parses a list number (num) followed by a paren, returns list attributes.
488-- | Parses a list number (num) followed by a paren, returns list attributes.
489inOneParen :: Parsec [Char] st (ListNumberStyle, Int)
489inOneParen :: Parsec [Char] st (ListNumberStyle, Int)
490− -> Parsec [Char] st ListAttributes
490+ -> Parsec [Char] st ListAttributes
491inOneParen num = try $ do
491inOneParen num = try $ do
492 (style, start) <- num
492 (style, start) <- num
493 char ')'
493 char ')'
@@ -495,7 +495,7 @@ inOneParen num = try $ do
495
495
496-- | Parses a list number (num) enclosed in parens, returns list attributes.
496-- | Parses a list number (num) enclosed in parens, returns list attributes.
497inTwoParens :: Parsec [Char] st (ListNumberStyle, Int)
497inTwoParens :: Parsec [Char] st (ListNumberStyle, Int)
498− -> Parsec [Char] st ListAttributes
498+ -> Parsec [Char] st ListAttributes
499inTwoParens num = try $ do
499inTwoParens num = try $ do
500 char '('
500 char '('
501 (style, start) <- num
501 (style, start) <- num
@@ -504,8 +504,8 @@ inTwoParens num = try $ do
504
504
505-- | Parses an ordered list marker with a given style and delimiter,
505-- | Parses an ordered list marker with a given style and delimiter,
506-- returns number.
506-- returns number.
507−orderedListMarker :: ListNumberStyle
507+orderedListMarker :: ListNumberStyle
508− -> ListNumberDelim
508+ -> ListNumberDelim
509 -> Parsec [Char] ParserState Int
509 -> Parsec [Char] ParserState Int
510orderedListMarker style delim = do
510orderedListMarker style delim = do
511 let num = defaultNum <|> -- # can continue any kind of list
511 let num = defaultNum <|> -- # can continue any kind of list
@@ -552,8 +552,8 @@ tableWith headerParser rowParser lineParser footerParser = try $ do
552widthsFromIndices :: Int -- Number of columns on terminal
552widthsFromIndices :: Int -- Number of columns on terminal
553 -> [Int] -- Indices
553 -> [Int] -- Indices
554 -> [Double] -- Fractional relative sizes of columns
554 -> [Double] -- Fractional relative sizes of columns
555−widthsFromIndices _ [] = []
555+widthsFromIndices _ [] = []
556−widthsFromIndices numColumns' indices =
556+widthsFromIndices numColumns' indices =
557 let numColumns = max numColumns' (if null indices then 0 else last indices)
557 let numColumns = max numColumns' (if null indices then 0 else last indices)
558 lengths' = zipWith (-) indices (0:indices)
558 lengths' = zipWith (-) indices (0:indices)
559 lengths = reverse $
559 lengths = reverse $
@@ -614,7 +614,7 @@ gridTableHeader headless block = try $ do
614 optional blanklines
614 optional blanklines
615 dashes <- gridDashedLines '-'
615 dashes <- gridDashedLines '-'
616 rawContent <- if headless
616 rawContent <- if headless
617− then return $ repeat ""
617+ then return $ repeat ""
618 else many1
618 else many1
619 (notFollowedBy (gridTableSep '=') >> char '|' >>
619 (notFollowedBy (gridTableSep '=') >> char '|' >>
620 many1Till anyChar newline)
620 many1Till anyChar newline)
@@ -671,7 +671,7 @@ readWith :: Parsec [t] ParserState a -- ^ parser
671 -> ParserState -- ^ initial state
671 -> ParserState -- ^ initial state
672 -> [t] -- ^ input
672 -> [t] -- ^ input
673 -> a
673 -> a
674−readWith parser state input =
674+readWith parser state input =
675 case runParser parser state "source" input of
675 case runParser parser state "source" input of
676 Left err' -> error $ "\nError:\n" ++ show err'
676 Left err' -> error $ "\nError:\n" ++ show err'
677 Right result -> result
677 Right result -> result
@@ -697,7 +697,7 @@ data ParserState = ParserState
697 stateDate :: [Inline], -- ^ Date of document
697 stateDate :: [Inline], -- ^ Date of document
698 stateHeaderTable :: [HeaderType], -- ^ Ordered list of header types used
698 stateHeaderTable :: [HeaderType], -- ^ Ordered list of header types used
699 stateNextExample :: Int, -- ^ Number of next example
699 stateNextExample :: Int, -- ^ Number of next example
700− stateExamples :: M.Map String Int, -- ^ Map from example labels to numbers
700+ stateExamples :: M.Map String Int, -- ^ Map from example labels to numbers
701 stateHasChapters :: Bool, -- ^ True if \chapter encountered
701 stateHasChapters :: Bool, -- ^ True if \chapter encountered
702 stateMacros :: [Macro], -- ^ List of macros defined so far
702 stateMacros :: [Macro], -- ^ List of macros defined so far
703 stateRstDefaultRole :: String -- ^ Current rST default interpreted text role
703 stateRstDefaultRole :: String -- ^ Current rST default interpreted text role
@@ -708,7 +708,7 @@ instance Default ParserState where
708 def = defaultParserState
708 def = defaultParserState
709
709
710defaultParserState :: ParserState
710defaultParserState :: ParserState
711−defaultParserState =
711+defaultParserState =
712 ParserState { stateOptions = def,
712 ParserState { stateOptions = def,
713 stateParserContext = NullState,
713 stateParserContext = NullState,
714 stateQuoteContext = NoQuote,
714 stateQuoteContext = NoQuote,
@@ -737,12 +737,12 @@ guardEnabled ext = getOption readerExtensions >>= guard . Set.member ext
737guardDisabled :: Extension -> Parser s ParserState ()
737guardDisabled :: Extension -> Parser s ParserState ()
738guardDisabled ext = getOption readerExtensions >>= guard . not . Set.member ext
738guardDisabled ext = getOption readerExtensions >>= guard . not . Set.member ext
739
739
740−data HeaderType
740+data HeaderType
741 = SingleHeader Char -- ^ Single line of characters underneath
741 = SingleHeader Char -- ^ Single line of characters underneath
742 | DoubleHeader Char -- ^ Lines of characters above and below
742 | DoubleHeader Char -- ^ Lines of characters above and below
743 deriving (Eq, Show)
743 deriving (Eq, Show)
744
744
745−data ParserContext
745+data ParserContext
746 = ListItemState -- ^ Used when running parser on list item contents
746 = ListItemState -- ^ Used when running parser on list item contents
747 | NullState -- ^ Default state
747 | NullState -- ^ Default state
748 deriving (Eq, Show)
748 deriving (Eq, Show)
@@ -838,7 +838,7 @@ charOrRef cs =
838 return c)
838 return c)
839
839
840updateLastStrPos :: Parsec [Char] ParserState ()
840updateLastStrPos :: Parsec [Char] ParserState ()
841−updateLastStrPos = getPosition >>= \p ->
841+updateLastStrPos = getPosition >>= \p ->
842 updateState $ \s -> s{ stateLastStrPos = Just p }
842 updateState $ \s -> s{ stateLastStrPos = Just p }
843
843
844singleQuoteStart :: Parsec [Char] ParserState ()
844singleQuoteStart :: Parsec [Char] ParserState ()
@@ -852,7 +852,7 @@ singleQuoteStart = do
852 notFollowedBy (oneOf ")!],;:-? \t\n")
852 notFollowedBy (oneOf ")!],;:-? \t\n")
853 notFollowedBy (char '.') <|> lookAhead (string "..." >> return ())
853 notFollowedBy (char '.') <|> lookAhead (string "..." >> return ())
854 notFollowedBy (try (oneOfStrings ["s","t","m","ve","ll","re"] >>
854 notFollowedBy (try (oneOfStrings ["s","t","m","ve","ll","re"] >>
855− satisfy (not . isAlphaNum)))
855+ satisfy (not . isAlphaNum)))
856 -- possess/contraction
856 -- possess/contraction
857 return ()
857 return ()
858
858
src/Text/Pandoc/Pretty.hs+1−1
@@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111(-1)307 USA
20{- |
20{- |
21 Module : Text.Pandoc.Pretty
21 Module : Text.Pandoc.Pretty
22 Copyright : Copyright (C) 2010 John MacFarlane
22 Copyright : Copyright (C) 2010 John MacFarlane
23− License : GNU GPL, version 2 or above
23+ License : GNU GPL, version 2 or above
24
24
25 Maintainer : John MacFarlane <jgm@berkeley.edu>
25 Maintainer : John MacFarlane <jgm@berkeley.edu>
26 Stability : alpha
26 Stability : alpha
src/Text/Pandoc/Readers/DocBook.hs+5−5
@@ -455,13 +455,13 @@ List of all DocBook tags, with [x] indicating implemented,
455[x] tocfront - An entry in a table of contents for a front matter component
455[x] tocfront - An entry in a table of contents for a front matter component
456[x] toclevel1 - A top-level entry within a table of contents entry for a
456[x] toclevel1 - A top-level entry within a table of contents entry for a
457 chapter-like component
457 chapter-like component
458−[x] toclevel2 - A second-level entry within a table of contents entry for a
458+[x] toclevel2 - A second-level entry within a table of contents entry for a
459 chapter-like component
459 chapter-like component
460−[x] toclevel3 - A third-level entry within a table of contents entry for a
460+[x] toclevel3 - A third-level entry within a table of contents entry for a
461 chapter-like component
461 chapter-like component
462−[x] toclevel4 - A fourth-level entry within a table of contents entry for a
462+[x] toclevel4 - A fourth-level entry within a table of contents entry for a
463 chapter-like component
463 chapter-like component
464−[x] toclevel5 - A fifth-level entry within a table of contents entry for a
464+[x] toclevel5 - A fifth-level entry within a table of contents entry for a
465 chapter-like component
465 chapter-like component
466[x] tocpart - An entry in a table of contents for a part of a book
466[x] tocpart - An entry in a table of contents for a part of a book
467[ ] token - A unit of information
467[ ] token - A unit of information
@@ -574,7 +574,7 @@ addToStart toadd bs =
574 (Para xs : rest) -> para (toadd <> fromList xs) <> fromList rest
574 (Para xs : rest) -> para (toadd <> fromList xs) <> fromList rest
575 _ -> bs
575 _ -> bs
576
576
577−-- function that is used by both mediaobject (in parseBlock)
577+-- function that is used by both mediaobject (in parseBlock)
578-- and inlinemediaobject (in parseInline)
578-- and inlinemediaobject (in parseInline)
579getImage :: Element -> DB Inlines
579getImage :: Element -> DB Inlines
580getImage e = do
580getImage e = do
src/Text/Pandoc/Readers/HTML.hs+5−5
@@ -19,10 +19,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19{- |
19{- |
20 Module : Text.Pandoc.Readers.HTML
20 Module : Text.Pandoc.Readers.HTML
21 Copyright : Copyright (C) 2006-2010 John MacFarlane
21 Copyright : Copyright (C) 2006-2010 John MacFarlane
22− License : GNU GPL, version 2 or above
22+ License : GNU GPL, version 2 or above
23
23
24 Maintainer : John MacFarlane <jgm@berkeley.edu>
24 Maintainer : John MacFarlane <jgm@berkeley.edu>
25− Stability : alpha
25+ Stability : alpha
26 Portability : portable
26 Portability : portable
27
27
28Conversion of HTML to 'Pandoc' document.
28Conversion of HTML to 'Pandoc' document.
@@ -231,7 +231,7 @@ pSimpleTable = try $ do
231 rows <- pOptInTag "tbody"
231 rows <- pOptInTag "tbody"
232 $ many1 $ try $ skipMany pBlank >> pInTags "tr" (pCell "td")
232 $ many1 $ try $ skipMany pBlank >> pInTags "tr" (pCell "td")
233 skipMany pBlank
233 skipMany pBlank
234− TagClose _ <- pSatisfy (~== TagClose "table")
234+ TagClose _ <- pSatisfy (~== TagClose "table")
235 let cols = maximum $ map length rows
235 let cols = maximum $ map length rows
236 let aligns = replicate cols AlignLeft
236 let aligns = replicate cols AlignLeft
237 let widths = replicate cols 0
237 let widths = replicate cols 0
@@ -303,7 +303,7 @@ pLocation = do
303pSat :: (Tag String -> Bool) -> TagParser (Tag String)
303pSat :: (Tag String -> Bool) -> TagParser (Tag String)
304pSat f = do
304pSat f = do
305 pos <- getPosition
305 pos <- getPosition
306− token show (const pos) (\x -> if f x then Just x else Nothing)
306+ token show (const pos) (\x -> if f x then Just x else Nothing)
307
307
308pSatisfy :: (Tag String -> Bool) -> TagParser (Tag String)
308pSatisfy :: (Tag String -> Bool) -> TagParser (Tag String)
309pSatisfy f = try $ optional pLocation >> pSat f
309pSatisfy f = try $ optional pLocation >> pSat f
@@ -608,7 +608,7 @@ htmlTag f = try $ do
608 count (length s + 4) anyChar
608 count (length s + 4) anyChar
609 skipMany (satisfy (/='>'))
609 skipMany (satisfy (/='>'))
610 char '>'
610 char '>'
611− return (next, "<!--" ++ s ++ "-->")
611+ return (next, "<!--" ++ s ++ "-->")
612 _ -> do
612 _ -> do
613 rendered <- manyTill anyChar (char '>')
613 rendered <- manyTill anyChar (char '>')
614 return (next, rendered ++ ">")
614 return (next, rendered ++ ">")
src/Text/Pandoc/Readers/Markdown.hs+31−31
@@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20{- |
20{- |
21 Module : Text.Pandoc.Readers.Markdown
21 Module : Text.Pandoc.Readers.Markdown
22 Copyright : Copyright (C) 2006-2010 John MacFarlane
22 Copyright : Copyright (C) 2006-2010 John MacFarlane
23− License : GNU GPL, version 2 or above
23+ License : GNU GPL, version 2 or above
24
24
25 Maintainer : John MacFarlane <jgm@berkeley.edu>
25 Maintainer : John MacFarlane <jgm@berkeley.edu>
26 Stability : alpha
26 Stability : alpha
@@ -94,7 +94,7 @@ nonindentSpaces :: Parser [Char] ParserState [Char]
94nonindentSpaces = do
94nonindentSpaces = do
95 tabStop <- getOption readerTabStop
95 tabStop <- getOption readerTabStop
96 sps <- many (char ' ')
96 sps <- many (char ' ')
97− if length sps < tabStop
97+ if length sps < tabStop
98 then return sps
98 then return sps
99 else unexpected "indented line"
99 else unexpected "indented line"
100
100
@@ -140,7 +140,7 @@ titleLine = try $ do
140 return $ normalizeSpaces res
140 return $ normalizeSpaces res
141
141
142authorsLine :: Parser [Char] ParserState [[Inline]]
142authorsLine :: Parser [Char] ParserState [[Inline]]
143−authorsLine = try $ do
143+authorsLine = try $ do
144 char '%'
144 char '%'
145 skipSpaces
145 skipSpaces
146 authors <- sepEndBy (many (notFollowedBy (satisfy $ \c ->
146 authors <- sepEndBy (many (notFollowedBy (satisfy $ \c ->
@@ -166,7 +166,7 @@ titleBlock = try $ do
166 optional blanklines
166 optional blanklines
167 return (title, author, date)
167 return (title, author, date)
168
168
169−parseMarkdown :: Parser [Char] ParserState Pandoc
169+parseMarkdown :: Parser [Char] ParserState Pandoc
170parseMarkdown = do
170parseMarkdown = do
171 -- markdown allows raw HTML
171 -- markdown allows raw HTML
172 updateState $ \state -> state { stateOptions =
172 updateState $ \state -> state { stateOptions =
@@ -202,7 +202,7 @@ parseMarkdown = do
202 then return doc
202 then return doc
203 else return $ bottomUp handleExampleRef doc
203 else return $ bottomUp handleExampleRef doc
204
204
205−--
205+--
206-- initial pass for references and notes
206-- initial pass for references and notes
207--
207--
208
208
@@ -422,7 +422,7 @@ codeBlockDelimited = try $ do
422
422
423codeBlockIndented :: Parser [Char] ParserState Block
423codeBlockIndented :: Parser [Char] ParserState Block
424codeBlockIndented = do
424codeBlockIndented = do
425− contents <- many1 (indentedLine <|>
425+ contents <- many1 (indentedLine <|>
426 try (do b <- blanklines
426 try (do b <- blanklines
427 l <- indentedLine
427 l <- indentedLine
428 return $ b ++ l))
428 return $ b ++ l))
@@ -483,7 +483,7 @@ emailBlockQuoteStart = try $ skipNonindentSpaces >> char '>' >>~ optional (char
483emailBlockQuote :: Parser [Char] ParserState [[Char]]
483emailBlockQuote :: Parser [Char] ParserState [[Char]]
484emailBlockQuote = try $ do
484emailBlockQuote = try $ do
485 emailBlockQuoteStart
485 emailBlockQuoteStart
486− raw <- sepBy (many (nonEndline <|>
486+ raw <- sepBy (many (nonEndline <|>
487 (try (endline >> notFollowedBy emailBlockQuoteStart >>
487 (try (endline >> notFollowedBy emailBlockQuoteStart >>
488 return '\n'))))
488 return '\n'))))
489 (try (newline >> emailBlockQuoteStart))
489 (try (newline >> emailBlockQuoteStart))
@@ -492,12 +492,12 @@ emailBlockQuote = try $ do
492 return raw
492 return raw
493
493
494blockQuote :: Parser [Char] ParserState Block
494blockQuote :: Parser [Char] ParserState Block
495−blockQuote = do
495+blockQuote = do
496 raw <- emailBlockQuote
496 raw <- emailBlockQuote
497 -- parse the extracted block, which may contain various block elements:
497 -- parse the extracted block, which may contain various block elements:
498 contents <- parseFromString parseBlocks $ (intercalate "\n" raw) ++ "\n\n"
498 contents <- parseFromString parseBlocks $ (intercalate "\n" raw) ++ "\n\n"
499 return $ BlockQuote contents
499 return $ BlockQuote contents
500−
500+
501--
501--
502-- list blocks
502-- list blocks
503--
503--
@@ -511,7 +511,7 @@ bulletListStart = try $ do
511 spaceChar
511 spaceChar
512 skipSpaces
512 skipSpaces
513
513
514−anyOrderedListStart :: Parser [Char] ParserState (Int, ListNumberStyle, ListNumberDelim)
514+anyOrderedListStart :: Parser [Char] ParserState (Int, ListNumberStyle, ListNumberDelim)
515anyOrderedListStart = try $ do
515anyOrderedListStart = try $ do
516 optional newline -- if preceded by a Plain block in a list context
516 optional newline -- if preceded by a Plain block in a list context
517 skipNonindentSpaces
517 skipNonindentSpaces
@@ -554,7 +554,7 @@ rawListItem start = try $ do
554 blanks <- many blankline
554 blanks <- many blankline
555 return $ concat (first:rest) ++ blanks
555 return $ concat (first:rest) ++ blanks
556
556
557−-- continuation of a list item - indented and separated by blankline
557+-- continuation of a list item - indented and separated by blankline
558-- or (in compact lists) endline.
558-- or (in compact lists) endline.
559-- note: nested lists are parsed as continuations
559-- note: nested lists are parsed as continuations
560listContinuation :: Parser [Char] ParserState [Char]
560listContinuation :: Parser [Char] ParserState [Char]
@@ -672,7 +672,7 @@ isHtmlOrBlank (LineBreak) = True
672isHtmlOrBlank _ = False
672isHtmlOrBlank _ = False
673
673
674para :: Parser [Char] ParserState Block
674para :: Parser [Char] ParserState Block
675−para = try $ do
675+para = try $ do
676 result <- liftM normalizeSpaces $ many1 inline
676 result <- liftM normalizeSpaces $ many1 inline
677 guard $ not . all isHtmlOrBlank $ result
677 guard $ not . all isHtmlOrBlank $ result
678 option (Plain result) $ try $ do
678 option (Plain result) $ try $ do
@@ -685,7 +685,7 @@ para = try $ do
685plain :: Parser [Char] ParserState Block
685plain :: Parser [Char] ParserState Block
686plain = many1 inline >>~ spaces >>= return . Plain . normalizeSpaces
686plain = many1 inline >>~ spaces >>= return . Plain . normalizeSpaces
687
687
688−--
688+--
689-- raw html
689-- raw html
690--
690--
691
691
@@ -741,20 +741,20 @@ rawHtmlBlocks = do
741
741
742--
742--
743-- Tables
743-- Tables
744−--
744+--
745
745
746-- Parse a dashed line with optional trailing spaces; return its length
746-- Parse a dashed line with optional trailing spaces; return its length
747-- and the length including trailing space.
747-- and the length including trailing space.
748−dashedLine :: Char
748+dashedLine :: Char
749 -> Parser [Char] st (Int, Int)
749 -> Parser [Char] st (Int, Int)
750dashedLine ch = do
750dashedLine ch = do
751 dashes <- many1 (char ch)
751 dashes <- many1 (char ch)
752 sp <- many spaceChar
752 sp <- many spaceChar
753 return $ (length dashes, length $ dashes ++ sp)
753 return $ (length dashes, length $ dashes ++ sp)
754
754
755−-- Parse a table header with dashed lines of '-' preceded by
755+-- Parse a table header with dashed lines of '-' preceded by
756-- one (or zero) line of text.
756-- one (or zero) line of text.
757−simpleTableHeader :: Bool -- ^ Headerless table
757+simpleTableHeader :: Bool -- ^ Headerless table
758 -> Parser [Char] ParserState ([[Block]], [Alignment], [Int])
758 -> Parser [Char] ParserState ([[Block]], [Alignment], [Int])
759simpleTableHeader headless = try $ do
759simpleTableHeader headless = try $ do
760 rawContent <- if headless
760 rawContent <- if headless
@@ -768,12 +768,12 @@ simpleTableHeader headless = try $ do
768 -- If no header, calculate alignment on basis of first row of text
768 -- If no header, calculate alignment on basis of first row of text
769 rawHeads <- liftM (tail . splitStringByIndices (init indices)) $
769 rawHeads <- liftM (tail . splitStringByIndices (init indices)) $
770 if headless
770 if headless
771− then lookAhead anyLine
771+ then lookAhead anyLine
772 else return rawContent
772 else return rawContent
773 let aligns = zipWith alignType (map (\a -> [a]) rawHeads) lengths
773 let aligns = zipWith alignType (map (\a -> [a]) rawHeads) lengths
774 let rawHeads' = if headless
774 let rawHeads' = if headless
775 then replicate (length dashes) ""
775 then replicate (length dashes) ""
776− else rawHeads
776+ else rawHeads
777 heads <- mapM (parseFromString (many plain)) $
777 heads <- mapM (parseFromString (many plain)) $
778 map removeLeadingTrailingSpace rawHeads'
778 map removeLeadingTrailingSpace rawHeads'
779 return (heads, aligns, indices)
779 return (heads, aligns, indices)
@@ -792,7 +792,7 @@ rawTableLine :: [Int]
792rawTableLine indices = do
792rawTableLine indices = do
793 notFollowedBy' (blanklines <|> tableFooter)
793 notFollowedBy' (blanklines <|> tableFooter)
794 line <- many1Till anyChar newline
794 line <- many1Till anyChar newline
795− return $ map removeLeadingTrailingSpace $ tail $
795+ return $ map removeLeadingTrailingSpace $ tail $
796 splitStringByIndices (init indices) line
796 splitStringByIndices (init indices) line
797
797
798-- Parse a table line and return a list of lists of blocks (columns).
798-- Parse a table line and return a list of lists of blocks (columns).
@@ -845,7 +845,7 @@ multilineTableHeader headless = try $ do
845 then return '\n'
845 then return '\n'
846 else tableSep >>~ notFollowedBy blankline
846 else tableSep >>~ notFollowedBy blankline
847 rawContent <- if headless
847 rawContent <- if headless
848− then return $ repeat ""
848+ then return $ repeat ""
849 else many1
849 else many1
850 (notFollowedBy tableSep >> many1Till anyChar newline)
850 (notFollowedBy tableSep >> many1Till anyChar newline)
851 initSp <- nonindentSpaces
851 initSp <- nonindentSpaces
@@ -856,7 +856,7 @@ multilineTableHeader headless = try $ do
856 rawHeadsList <- if headless
856 rawHeadsList <- if headless
857 then liftM (map (:[]) . tail .
857 then liftM (map (:[]) . tail .
858 splitStringByIndices (init indices)) $ lookAhead anyLine
858 splitStringByIndices (init indices)) $ lookAhead anyLine
859− else return $ transpose $ map
859+ else return $ transpose $ map
860 (\ln -> tail $ splitStringByIndices (init indices) ln)
860 (\ln -> tail $ splitStringByIndices (init indices) ln)
861 rawContent
861 rawContent
862 let aligns = zipWith alignType rawHeadsList lengths
862 let aligns = zipWith alignType rawHeadsList lengths
@@ -1026,7 +1026,7 @@ exampleRef = try $ do
1026 return $ Str $ '@' : lab
1026 return $ Str $ '@' : lab
1027
1027
1028symbol :: Parser [Char] ParserState Inline
1028symbol :: Parser [Char] ParserState Inline
1029−symbol = do
1029+symbol = do
1030 result <- noneOf "<\\\n\t "
1030 result <- noneOf "<\\\n\t "
1031 <|> try (do lookAhead $ char '\\'
1031 <|> try (do lookAhead $ char '\\'
1032 notFollowedBy' rawTeXBlock
1032 notFollowedBy' rawTeXBlock
@@ -1035,12 +1035,12 @@ symbol = do
1035
1035
1036-- parses inline code, between n `s and n `s
1036-- parses inline code, between n `s and n `s
1037code :: Parser [Char] ParserState Inline
1037code :: Parser [Char] ParserState Inline
1038−code = try $ do
1038+code = try $ do
1039 starts <- many1 (char '`')
1039 starts <- many1 (char '`')
1040 skipSpaces
1040 skipSpaces
1041 result <- many1Till (many1 (noneOf "`\n") <|> many1 (char '`') <|>
1041 result <- many1Till (many1 (noneOf "`\n") <|> many1 (char '`') <|>
1042 (char '\n' >> notFollowedBy' blankline >> return " "))
1042 (char '\n' >> notFollowedBy' blankline >> return " "))
1043− (try (skipSpaces >> count (length starts) (char '`') >>
1043+ (try (skipSpaces >> count (length starts) (char '`') >>
1044 notFollowedBy (char '`')))
1044 notFollowedBy (char '`')))
1045 attr <- option ([],[],[]) (try $ optional whitespace >> attributes)
1045 attr <- option ([],[],[]) (try $ optional whitespace >> attributes)
1046 return $ Code attr $ removeLeadingTrailingSpace $ concat result
1046 return $ Code attr $ removeLeadingTrailingSpace $ concat result
@@ -1058,7 +1058,7 @@ math :: Parser [Char] ParserState Inline
1058math = (mathDisplay >>= applyMacros' >>= return . Math DisplayMath)
1058math = (mathDisplay >>= applyMacros' >>= return . Math DisplayMath)
1059 <|> (mathInline >>= applyMacros' >>= return . Math InlineMath)
1059 <|> (mathInline >>= applyMacros' >>= return . Math InlineMath)
1060
1060
1061−mathDisplay :: Parser [Char] ParserState String
1061+mathDisplay :: Parser [Char] ParserState String
1062mathDisplay = try $ do
1062mathDisplay = try $ do
1063 guardEnabled Ext_tex_math
1063 guardEnabled Ext_tex_math
1064 string "$$"
1064 string "$$"
@@ -1129,14 +1129,14 @@ strikeout = Strikeout `liftM`
1129 strikeEnd = try $ string "~~"
1129 strikeEnd = try $ string "~~"
1130
1130
1131superscript :: Parser [Char] ParserState Inline
1131superscript :: Parser [Char] ParserState Inline
1132−superscript = guardEnabled Ext_superscript >> enclosed (char '^') (char '^')
1132+superscript = guardEnabled Ext_superscript >> enclosed (char '^') (char '^')
1133 (notFollowedBy spaceChar >> inline) >>= -- may not contain Space
1133 (notFollowedBy spaceChar >> inline) >>= -- may not contain Space
1134 return . Superscript
1134 return . Superscript
1135
1135
1136subscript :: Parser [Char] ParserState Inline
1136subscript :: Parser [Char] ParserState Inline
1137subscript = guardEnabled Ext_subscript >> enclosed (char '~') (char '~')
1137subscript = guardEnabled Ext_subscript >> enclosed (char '~') (char '~')
1138 (notFollowedBy spaceChar >> inline) >>= -- may not contain Space
1138 (notFollowedBy spaceChar >> inline) >>= -- may not contain Space
1139− return . Subscript
1139+ return . Subscript
1140
1140
1141whitespace :: Parser [Char] ParserState Inline
1141whitespace :: Parser [Char] ParserState Inline
1142whitespace = spaceChar >>
1142whitespace = spaceChar >>
@@ -1257,13 +1257,13 @@ delinkify = bottomUp $ concatMap go
1257referenceLink :: [Inline]
1257referenceLink :: [Inline]
1258 -> Parser [Char] ParserState (String, [Char])
1258 -> Parser [Char] ParserState (String, [Char])
1259referenceLink lab = do
1259referenceLink lab = do
1260− ref <- option [] (try (optional (char ' ') >>
1260+ ref <- option [] (try (optional (char ' ') >>
1261 optional (newline >> skipSpaces) >> reference))
1261 optional (newline >> skipSpaces) >> reference))
1262 let ref' = if null ref then lab else ref
1262 let ref' = if null ref then lab else ref
1263 state <- getState
1263 state <- getState
1264 case lookupKeySrc (stateKeys state) (toKey ref') of
1264 case lookupKeySrc (stateKeys state) (toKey ref') of
1265− Nothing -> fail "no corresponding key"
1265+ Nothing -> fail "no corresponding key"
1266− Just target -> return target
1266+ Just target -> return target
1267
1267
1268autoLink :: Parser [Char] ParserState Inline
1268autoLink :: Parser [Char] ParserState Inline
1269autoLink = try $ do
1269autoLink = try $ do
src/Text/Pandoc/Readers/Native.hs+1−1
@@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19{- |
19{- |
20 Module : Text.Pandoc.Readers.Native
20 Module : Text.Pandoc.Readers.Native
21 Copyright : Copyright (C) 2011 John MacFarlane
21 Copyright : Copyright (C) 2011 John MacFarlane
22− License : GNU GPL, version 2 or above
22+ License : GNU GPL, version 2 or above
23
23
24 Maintainer : John MacFarlane <jgm@berkeley.edu>
24 Maintainer : John MacFarlane <jgm@berkeley.edu>
25 Stability : alpha
25 Stability : alpha
src/Text/Pandoc/Readers/RST.hs+26−26
@@ -17,9 +17,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17-}
17-}
18
18
19{- |
19{- |
20− Module : Text.Pandoc.Readers.RST
20+ Module : Text.Pandoc.Readers.RST
21 Copyright : Copyright (C) 2006-2010 John MacFarlane
21 Copyright : Copyright (C) 2006-2010 John MacFarlane
22− License : GNU GPL, version 2 or above
22+ License : GNU GPL, version 2 or above
23
23
24 Maintainer : John MacFarlane <jgm@berkeley.edu>
24 Maintainer : John MacFarlane <jgm@berkeley.edu>
25 Stability : alpha
25 Stability : alpha
@@ -71,14 +71,14 @@ isHeader _ _ = False
71-- | Promote all headers in a list of blocks. (Part of
71-- | Promote all headers in a list of blocks. (Part of
72-- title transformation for RST.)
72-- title transformation for RST.)
73promoteHeaders :: Int -> [Block] -> [Block]
73promoteHeaders :: Int -> [Block] -> [Block]
74−promoteHeaders num ((Header level text):rest) =
74+promoteHeaders num ((Header level text):rest) =
75 (Header (level - num) text):(promoteHeaders num rest)
75 (Header (level - num) text):(promoteHeaders num rest)
76promoteHeaders num (other:rest) = other:(promoteHeaders num rest)
76promoteHeaders num (other:rest) = other:(promoteHeaders num rest)
77promoteHeaders _ [] = []
77promoteHeaders _ [] = []
78
78
79-- | If list of blocks starts with a header (or a header and subheader)
79-- | If list of blocks starts with a header (or a header and subheader)
80-- of level that are not found elsewhere, return it as a title and
80-- of level that are not found elsewhere, return it as a title and
81−-- promote all the other headers.
81+-- promote all the other headers.
82titleTransform :: [Block] -- ^ list of blocks
82titleTransform :: [Block] -- ^ list of blocks
83 -> ([Block], [Inline]) -- ^ modified list of blocks, title
83 -> ([Block], [Inline]) -- ^ modified list of blocks, title
84titleTransform ((Header 1 head1):(Header 2 head2):rest) |
84titleTransform ((Header 1 head1):(Header 2 head2):rest) |
@@ -238,14 +238,14 @@ paraBeforeCodeBlock = try $ do
238
238
239-- regular paragraph
239-- regular paragraph
240paraNormal :: Parser [Char] ParserState Block
240paraNormal :: Parser [Char] ParserState Block
241−paraNormal = try $ do
241+paraNormal = try $ do
242 result <- many1 inline
242 result <- many1 inline
243 newline
243 newline
244 blanklines
244 blanklines
245 return $ Para $ normalizeSpaces result
245 return $ Para $ normalizeSpaces result
246
246
247plain :: Parser [Char] ParserState Block
247plain :: Parser [Char] ParserState Block
248−plain = many1 inline >>= return . Plain . normalizeSpaces
248+plain = many1 inline >>= return . Plain . normalizeSpaces
249
249
250--
250--
251-- image block
251-- image block
@@ -284,7 +284,7 @@ doubleHeader = try $ do
284 blankline -- spaces and newline
284 blankline -- spaces and newline
285 count lenTop (char c) -- the bottom line
285 count lenTop (char c) -- the bottom line
286 blanklines
286 blanklines
287− -- check to see if we've had this kind of header before.
287+ -- check to see if we've had this kind of header before.
288 -- if so, get appropriate level. if not, add to list.
288 -- if so, get appropriate level. if not, add to list.
289 state <- getState
289 state <- getState
290 let headerTable = stateHeaderTable state
290 let headerTable = stateHeaderTable state
@@ -296,7 +296,7 @@ doubleHeader = try $ do
296
296
297-- a header with line on the bottom only
297-- a header with line on the bottom only
298singleHeader :: Parser [Char] ParserState Block
298singleHeader :: Parser [Char] ParserState Block
299−singleHeader = try $ do
299+singleHeader = try $ do
300 notFollowedBy' whitespace
300 notFollowedBy' whitespace
301 txt <- many1 (do {notFollowedBy blankline; inline})
301 txt <- many1 (do {notFollowedBy blankline; inline})
302 pos <- getPosition
302 pos <- getPosition
@@ -498,8 +498,8 @@ indentWith num = do
498 tabStop <- getOption readerTabStop
498 tabStop <- getOption readerTabStop
499 if (num < tabStop)
499 if (num < tabStop)
500 then count num (char ' ')
500 then count num (char ' ')
501− else choice [ try (count num (char ' ')),
501+ else choice [ try (count num (char ' ')),
502− (try (char '\t' >> count (num - tabStop) (char ' '))) ]
502+ (try (char '\t' >> count (num - tabStop) (char ' '))) ]
503
503
504-- parse raw text for one list item, excluding start marker and continuations
504-- parse raw text for one list item, excluding start marker and continuations
505rawListItem :: Parser [Char] ParserState Int
505rawListItem :: Parser [Char] ParserState Int
@@ -510,8 +510,8 @@ rawListItem start = try $ do
510 restLines <- many (listLine markerLength)
510 restLines <- many (listLine markerLength)
511 return (markerLength, (firstLine ++ "\n" ++ (concat restLines)))
511 return (markerLength, (firstLine ++ "\n" ++ (concat restLines)))
512
512
513−-- continuation of a list item - indented and separated by blankline or
513+-- continuation of a list item - indented and separated by blankline or
514−-- (in compact lists) endline.
514+-- (in compact lists) endline.
515-- Note: nested lists are parsed as continuations.
515-- Note: nested lists are parsed as continuations.
516listContinuation :: Int -> Parser [Char] ParserState [Char]
516listContinuation :: Int -> Parser [Char] ParserState [Char]
517listContinuation markerLength = try $ do
517listContinuation markerLength = try $ do
@@ -521,7 +521,7 @@ listContinuation markerLength = try $ do
521
521
522listItem :: Parser [Char] ParserState Int
522listItem :: Parser [Char] ParserState Int
523 -> Parser [Char] ParserState [Block]
523 -> Parser [Char] ParserState [Block]
524−listItem start = try $ do
524+listItem start = try $ do
525 (markerLength, first) <- rawListItem start
525 (markerLength, first) <- rawListItem start
526 rest <- many (listContinuation markerLength)
526 rest <- many (listContinuation markerLength)
527 blanks <- choice [ try (many blankline >>~ lookAhead start),
527 blanks <- choice [ try (many blankline >>~ lookAhead start),
@@ -545,7 +545,7 @@ orderedList = try $ do
545 return $ OrderedList (start, style, delim) items'
545 return $ OrderedList (start, style, delim) items'
546
546
547bulletList :: Parser [Char] ParserState Block
547bulletList :: Parser [Char] ParserState Block
548−bulletList = many1 (listItem bulletListStart) >>=
548+bulletList = many1 (listItem bulletListStart) >>=
549 return . BulletList . compactify
549 return . BulletList . compactify
550
550
551--
551--
@@ -617,7 +617,7 @@ noteMarker = do
617quotedReferenceName :: Parser [Char] ParserState [Inline]
617quotedReferenceName :: Parser [Char] ParserState [Inline]
618quotedReferenceName = try $ do
618quotedReferenceName = try $ do
619 char '`' >> notFollowedBy (char '`') -- `` means inline code!
619 char '`' >> notFollowedBy (char '`') -- `` means inline code!
620− label' <- many1Till inline (char '`')
620+ label' <- many1Till inline (char '`')
621 return label'
621 return label'
622
622
623unquotedReferenceName :: Parser [Char] ParserState [Inline]
623unquotedReferenceName :: Parser [Char] ParserState [Inline]
@@ -662,7 +662,7 @@ targetURI :: Parser [Char] st [Char]
662targetURI = do
662targetURI = do
663 skipSpaces
663 skipSpaces
664 optional newline
664 optional newline
665− contents <- many1 (try (many spaceChar >> newline >>
665+ contents <- many1 (try (many spaceChar >> newline >>
666 many1 spaceChar >> noneOf " \t\n") <|> noneOf "\n")
666 many1 spaceChar >> noneOf " \t\n") <|> noneOf "\n")
667 blanklines
667 blanklines
668 return $ escapeURI $ removeLeadingTrailingSpace $ contents
668 return $ escapeURI $ removeLeadingTrailingSpace $ contents
@@ -702,7 +702,7 @@ regularKey = try $ do
702-- Simple tables TODO:
702-- Simple tables TODO:
703-- - column spans
703-- - column spans
704-- - multiline support
704-- - multiline support
705−-- - ensure that rightmost column span does not need to reach end
705+-- - ensure that rightmost column span does not need to reach end
706-- - require at least 2 columns
706-- - require at least 2 columns
707--
707--
708-- Grid tables TODO:
708-- Grid tables TODO:
@@ -745,7 +745,7 @@ simpleTableSplitLine indices line =
745 map removeLeadingTrailingSpace
745 map removeLeadingTrailingSpace
746 $ tail $ splitByIndices (init indices) line
746 $ tail $ splitByIndices (init indices) line
747
747
748−simpleTableHeader :: Bool -- ^ Headerless table
748+simpleTableHeader :: Bool -- ^ Headerless table
749 -> Parser [Char] ParserState ([[Block]], [Alignment], [Int])
749 -> Parser [Char] ParserState ([[Block]], [Alignment], [Int])
750simpleTableHeader headless = try $ do
750simpleTableHeader headless = try $ do
751 optional blanklines
751 optional blanklines
@@ -783,7 +783,7 @@ table = gridTable False <|> simpleTable False <|>
783 gridTable True <|> simpleTable True <?> "table"
783 gridTable True <|> simpleTable True <?> "table"
784
784
785
785
786− --
786+ --
787 -- inline
787 -- inline
788 --
788 --
789
789
@@ -808,7 +808,7 @@ inline = choice [ whitespace
808hyphens :: Parser [Char] ParserState Inline
808hyphens :: Parser [Char] ParserState Inline
809hyphens = do
809hyphens = do
810 result <- many1 (char '-')
810 result <- many1 (char '-')
811− option Space endline
811+ option Space endline
812 -- don't want to treat endline after hyphen or dash as a space
812 -- don't want to treat endline after hyphen or dash as a space
813 return $ Str result
813 return $ Str result
814
814
@@ -819,13 +819,13 @@ escapedChar = do c <- escaped anyChar
819 else Str [c]
819 else Str [c]
820
820
821symbol :: Parser [Char] ParserState Inline
821symbol :: Parser [Char] ParserState Inline
822−symbol = do
822+symbol = do
823 result <- oneOf specialChars
823 result <- oneOf specialChars
824 return $ Str [result]
824 return $ Str [result]
825
825
826-- parses inline code, between codeStart and codeEnd
826-- parses inline code, between codeStart and codeEnd
827code :: Parser [Char] ParserState Inline
827code :: Parser [Char] ParserState Inline
828−code = try $ do
828+code = try $ do
829 string "``"
829 string "``"
830 result <- manyTill anyChar (try (string "``"))
830 result <- manyTill anyChar (try (string "``"))
831 return $ Code nullAttr
831 return $ Code nullAttr
@@ -841,11 +841,11 @@ atStart p = do
841 p
841 p
842
842
843emph :: Parser [Char] ParserState Inline
843emph :: Parser [Char] ParserState Inline
844−emph = enclosed (atStart $ char '*') (char '*') inline >>=
844+emph = enclosed (atStart $ char '*') (char '*') inline >>=
845 return . Emph . normalizeSpaces
845 return . Emph . normalizeSpaces
846
846
847strong :: Parser [Char] ParserState Inline
847strong :: Parser [Char] ParserState Inline
848−strong = enclosed (atStart $ string "**") (try $ string "**") inline >>=
848+strong = enclosed (atStart $ string "**") (try $ string "**") inline >>=
849 return . Strong . normalizeSpaces
849 return . Strong . normalizeSpaces
850
850
851-- Parses inline interpreted text which is required to have the given role.
851-- Parses inline interpreted text which is required to have the given role.
@@ -911,7 +911,7 @@ explicitLink :: Parser [Char] ParserState Inline
911explicitLink = try $ do
911explicitLink = try $ do
912 char '`'
912 char '`'
913 notFollowedBy (char '`') -- `` marks start of inline code
913 notFollowedBy (char '`') -- `` marks start of inline code
914− label' <- manyTill (notFollowedBy (char '`') >> inline)
914+ label' <- manyTill (notFollowedBy (char '`') >> inline)
915 (try (spaces >> char '<'))
915 (try (spaces >> char '<'))
916 src <- manyTill (noneOf ">\n") (char '>')
916 src <- manyTill (noneOf ">\n") (char '>')
917 skipSpaces
917 skipSpaces
@@ -938,7 +938,7 @@ referenceLink = try $ do
938 Just target -> return target
938 Just target -> return target
939 -- if anonymous link, remove key so it won't be used again
939 -- if anonymous link, remove key so it won't be used again
940 when (isAnonKey key) $ updateState $ \s -> s{ stateKeys = M.delete key keyTable }
940 when (isAnonKey key) $ updateState $ \s -> s{ stateKeys = M.delete key keyTable }
941− return $ Link (normalizeSpaces label') (src, tit)
941+ return $ Link (normalizeSpaces label') (src, tit)
942
942
943autoURI :: Parser [Char] ParserState Inline
943autoURI :: Parser [Char] ParserState Inline
944autoURI = do
944autoURI = do
src/Text/Pandoc/Readers/TeXMath.hs+1−1
@@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19{- |
19{- |
20 Module : Text.Pandoc.Readers.TeXMath
20 Module : Text.Pandoc.Readers.TeXMath
21 Copyright : Copyright (C) 2007-2010 John MacFarlane
21 Copyright : Copyright (C) 2007-2010 John MacFarlane
22− License : GNU GPL, version 2 or above
22+ License : GNU GPL, version 2 or above
23
23
24 Maintainer : John MacFarlane <jgm@berkeley.edu>
24 Maintainer : John MacFarlane <jgm@berkeley.edu>
25 Stability : alpha
25 Stability : alpha
src/Text/Pandoc/Readers/Textile.hs+12−12
@@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19{- |
19{- |
20 Module : Text.Pandoc.Readers.Textile
20 Module : Text.Pandoc.Readers.Textile
21 Copyright : Copyright (C) 2010-2012 Paul Rivier and John MacFarlane
21 Copyright : Copyright (C) 2010-2012 Paul Rivier and John MacFarlane
22− License : GNU GPL, version 2 or above
22+ License : GNU GPL, version 2 or above
23
23
24 Maintainer : Paul Rivier <paul*rivier#demotera*com>
24 Maintainer : Paul Rivier <paul*rivier#demotera*com>
25 Stability : alpha
25 Stability : alpha
@@ -232,9 +232,9 @@ genericListItemAtDepth c depth = try $ do
232 return ((Plain p):sublist)
232 return ((Plain p):sublist)
233
233
234-- | A definition list is a set of consecutive definition items
234-- | A definition list is a set of consecutive definition items
235−definitionList :: Parser [Char] ParserState Block
235+definitionList :: Parser [Char] ParserState Block
236definitionList = try $ DefinitionList <$> many1 definitionListItem
236definitionList = try $ DefinitionList <$> many1 definitionListItem
237−
237+
238-- | A definition list item in textile begins with '- ', followed by
238-- | A definition list item in textile begins with '- ', followed by
239-- the term defined, then spaces and ":=". The definition follows, on
239-- the term defined, then spaces and ":=". The definition follows, on
240-- the same single line, or spaned on multiple line, after a line
240-- the same single line, or spaned on multiple line, after a line
@@ -283,7 +283,7 @@ para = try $ Para . normalizeSpaces <$> manyTill inline blockBreak
283
283
284
284
285-- Tables
285-- Tables
286−
286+
287-- | A table cell spans until a pipe |
287-- | A table cell spans until a pipe |
288tableCell :: Parser [Char] ParserState TableCell
288tableCell :: Parser [Char] ParserState TableCell
289tableCell = do
289tableCell = do
@@ -303,7 +303,7 @@ tableRows = many1 tableRow
303tableHeaders :: Parser [Char] ParserState [TableCell]
303tableHeaders :: Parser [Char] ParserState [TableCell]
304tableHeaders = let separator = (try $ string "|_.") in
304tableHeaders = let separator = (try $ string "|_.") in
305 try $ ( separator *> (sepBy1 tableCell separator) <* char '|' <* newline )
305 try $ ( separator *> (sepBy1 tableCell separator) <* char '|' <* newline )
306−
306+
307-- | A table with an optional header. Current implementation can
307-- | A table with an optional header. Current implementation can
308-- handle tables with and without header, but will parse cells
308-- handle tables with and without header, but will parse cells
309-- alignment attributes as content.
309-- alignment attributes as content.
@@ -313,12 +313,12 @@ table = try $ do
313 rows <- tableRows
313 rows <- tableRows
314 blanklines
314 blanklines
315 let nbOfCols = max (length headers) (length $ head rows)
315 let nbOfCols = max (length headers) (length $ head rows)
316− return $ Table []
316+ return $ Table []
317 (replicate nbOfCols AlignDefault)
317 (replicate nbOfCols AlignDefault)
318 (replicate nbOfCols 0.0)
318 (replicate nbOfCols 0.0)
319 headers
319 headers
320 rows
320 rows
321−
321+
322
322
323-- | Blocks like 'p' and 'table' do not need explicit block tag.
323-- | Blocks like 'p' and 'table' do not need explicit block tag.
324-- However, they can be used to set HTML/CSS attributes when needed.
324-- However, they can be used to set HTML/CSS attributes when needed.
@@ -326,7 +326,7 @@ maybeExplicitBlock :: String -- ^ block tag name
326 -> Parser [Char] ParserState Block -- ^ implicit block
326 -> Parser [Char] ParserState Block -- ^ implicit block
327 -> Parser [Char] ParserState Block
327 -> Parser [Char] ParserState Block
328maybeExplicitBlock name blk = try $ do
328maybeExplicitBlock name blk = try $ do
329− optional $ try $ string name >> optional attributes >> char '.' >>
329+ optional $ try $ string name >> optional attributes >> char '.' >>
330 ((try whitespace) <|> endline)
330 ((try whitespace) <|> endline)
331 blk
331 blk
332
332
@@ -410,7 +410,7 @@ note = try $ do
410 Nothing -> fail "note not found"
410 Nothing -> fail "note not found"
411 Just raw -> liftM Note $ parseFromString parseBlocks raw
411 Just raw -> liftM Note $ parseFromString parseBlocks raw
412
412
413−-- | Special chars
413+-- | Special chars
414markupChars :: [Char]
414markupChars :: [Char]
415markupChars = "\\[]*#_@~-+^|%="
415markupChars = "\\[]*#_@~-+^|%="
416
416
@@ -429,10 +429,10 @@ wordBoundaries = markupChars ++ stringBreakers
429hyphenedWords :: Parser [Char] ParserState String
429hyphenedWords :: Parser [Char] ParserState String
430hyphenedWords = try $ do
430hyphenedWords = try $ do
431 hd <- noneOf wordBoundaries
431 hd <- noneOf wordBoundaries
432− tl <- many ( (noneOf wordBoundaries) <|>
432+ tl <- many ( (noneOf wordBoundaries) <|>
433 try (oneOf markupChars <* lookAhead (noneOf wordBoundaries) ) )
433 try (oneOf markupChars <* lookAhead (noneOf wordBoundaries) ) )
434 let wd = hd:tl
434 let wd = hd:tl
435− option wd $ try $
435+ option wd $ try $
436 (\r -> concat [wd, "-", r]) <$> (char '-' *> hyphenedWords)
436 (\r -> concat [wd, "-", r]) <$> (char '-' *> hyphenedWords)
437
437
438-- | Any string
438-- | Any string
@@ -465,7 +465,7 @@ endline = try $ do
465rawHtmlInline :: Parser [Char] ParserState Inline
465rawHtmlInline :: Parser [Char] ParserState Inline
466rawHtmlInline = RawInline "html" . snd <$> htmlTag isInlineTag
466rawHtmlInline = RawInline "html" . snd <$> htmlTag isInlineTag
467
467
468−-- | Raw LaTeX Inline
468+-- | Raw LaTeX Inline
469rawLaTeXInline' :: Parser [Char] ParserState Inline
469rawLaTeXInline' :: Parser [Char] ParserState Inline
470rawLaTeXInline' = try $ do
470rawLaTeXInline' = try $ do
471 guardEnabled Ext_raw_tex
471 guardEnabled Ext_raw_tex
src/Text/Pandoc/SelfContained.hs+2−2
@@ -102,14 +102,14 @@ convertTag userdata t@(TagOpen "script" as) =
102 src -> do
102 src -> do
103 (raw, mime) <- getRaw userdata (fromAttrib "type" t) src
103 (raw, mime) <- getRaw userdata (fromAttrib "type" t) src
104 let enc = "data:" ++ mime ++ "," ++ escapeURIString isOk (toString raw)
104 let enc = "data:" ++ mime ++ "," ++ escapeURIString isOk (toString raw)
105− return $ TagOpen "script" (("src",enc) : [(x,y) | (x,y) <- as, x /= "src"])
105+ return $ TagOpen "script" (("src",enc) : [(x,y) | (x,y) <- as, x /= "src"])
106convertTag userdata t@(TagOpen "link" as) =
106convertTag userdata t@(TagOpen "link" as) =
107 case fromAttrib "href" t of
107 case fromAttrib "href" t of
108 [] -> return t
108 [] -> return t
109 src -> do
109 src -> do
110 (raw, mime) <- getRaw userdata (fromAttrib "type" t) src
110 (raw, mime) <- getRaw userdata (fromAttrib "type" t) src
111 let enc = "data:" ++ mime ++ "," ++ escapeURIString isOk (toString raw)
111 let enc = "data:" ++ mime ++ "," ++ escapeURIString isOk (toString raw)
112− return $ TagOpen "link" (("href",enc) : [(x,y) | (x,y) <- as, x /= "href"])
112+ return $ TagOpen "link" (("href",enc) : [(x,y) | (x,y) <- as, x /= "href"])
113convertTag _ t = return t
113convertTag _ t = return t
114
114
115cssURLs :: Maybe FilePath -> FilePath -> ByteString -> IO ByteString
115cssURLs :: Maybe FilePath -> FilePath -> ByteString -> IO ByteString
src/Text/Pandoc/Shared.hs+9−9
@@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20{- |
20{- |
21 Module : Text.Pandoc.Shared
21 Module : Text.Pandoc.Shared
22 Copyright : Copyright (C) 2006-2010 John MacFarlane
22 Copyright : Copyright (C) 2006-2010 John MacFarlane
23− License : GNU GPL, version 2 or above
23+ License : GNU GPL, version 2 or above
24
24
25 Maintainer : John MacFarlane <jgm@berkeley.edu>
25 Maintainer : John MacFarlane <jgm@berkeley.edu>
26 Stability : alpha
26 Stability : alpha
@@ -150,7 +150,7 @@ backslashEscapes = map (\ch -> (ch, ['\\',ch]))
150-- characters and strings.
150-- characters and strings.
151escapeStringUsing :: [(Char, String)] -> String -> String
151escapeStringUsing :: [(Char, String)] -> String -> String
152escapeStringUsing _ [] = ""
152escapeStringUsing _ [] = ""
153−escapeStringUsing escapeTable (x:xs) =
153+escapeStringUsing escapeTable (x:xs) =
154 case (lookup x escapeTable) of
154 case (lookup x escapeTable) of
155 Just str -> str ++ rest
155 Just str -> str ++ rest
156 Nothing -> x:rest
156 Nothing -> x:rest
@@ -177,7 +177,7 @@ stripFirstAndLast :: String -> String
177stripFirstAndLast str =
177stripFirstAndLast str =
178 drop 1 $ take ((length str) - 1) str
178 drop 1 $ take ((length str) - 1) str
179
179
180−-- | Change CamelCase word to hyphenated lowercase (e.g., camel-case).
180+-- | Change CamelCase word to hyphenated lowercase (e.g., camel-case).
181camelCaseToHyphenated :: String -> String
181camelCaseToHyphenated :: String -> String
182camelCaseToHyphenated [] = ""
182camelCaseToHyphenated [] = ""
183camelCaseToHyphenated (a:b:rest) | isLower a && isUpper b =
183camelCaseToHyphenated (a:b:rest) | isLower a && isUpper b =
@@ -248,13 +248,13 @@ normalizeDate s = fmap (formatTime defaultTimeLocale "%F")
248-- | Generate infinite lazy list of markers for an ordered list,
248-- | Generate infinite lazy list of markers for an ordered list,
249-- depending on list attributes.
249-- depending on list attributes.
250orderedListMarkers :: (Int, ListNumberStyle, ListNumberDelim) -> [String]
250orderedListMarkers :: (Int, ListNumberStyle, ListNumberDelim) -> [String]
251−orderedListMarkers (start, numstyle, numdelim) =
251+orderedListMarkers (start, numstyle, numdelim) =
252 let singleton c = [c]
252 let singleton c = [c]
253 nums = case numstyle of
253 nums = case numstyle of
254 DefaultStyle -> map show [start..]
254 DefaultStyle -> map show [start..]
255 Example -> map show [start..]
255 Example -> map show [start..]
256 Decimal -> map show [start..]
256 Decimal -> map show [start..]
257− UpperAlpha -> drop (start - 1) $ cycle $
257+ UpperAlpha -> drop (start - 1) $ cycle $
258 map singleton ['A'..'Z']
258 map singleton ['A'..'Z']
259 LowerAlpha -> drop (start - 1) $ cycle $
259 LowerAlpha -> drop (start - 1) $ cycle $
260 map singleton ['a'..'z']
260 map singleton ['a'..'z']
@@ -386,7 +386,7 @@ isPara (Para _) = True
386isPara _ = False
386isPara _ = False
387
387
388-- | Data structure for defining hierarchical Pandoc documents
388-- | Data structure for defining hierarchical Pandoc documents
389−data Element = Blk Block
389+data Element = Blk Block
390 | Sec Int [Int] String [Inline] [Element]
390 | Sec Int [Int] String [Inline] [Element]
391 -- lvl num ident label contents
391 -- lvl num ident label contents
392 deriving (Eq, Read, Show, Typeable, Data)
392 deriving (Eq, Read, Show, Typeable, Data)
@@ -414,7 +414,7 @@ hierarchicalizeWithIds ((Header level title'):xs) = do
414 let ident = uniqueIdent title' usedIdents
414 let ident = uniqueIdent title' usedIdents
415 let lastnum' = take level lastnum
415 let lastnum' = take level lastnum
416 let newnum = if length lastnum' >= level
416 let newnum = if length lastnum' >= level
417− then init lastnum' ++ [last lastnum' + 1]
417+ then init lastnum' ++ [last lastnum' + 1]
418 else lastnum ++ replicate (level - length lastnum - 1) 0 ++ [1]
418 else lastnum ++ replicate (level - length lastnum - 1) 0 ++ [1]
419 S.put (newnum, (ident : usedIdents))
419 S.put (newnum, (ident : usedIdents))
420 let (sectionContents, rest) = break (headerLtEq level) xs
420 let (sectionContents, rest) = break (headerLtEq level) xs
@@ -459,7 +459,7 @@ headerShift n = bottomUp shift
459-- Writer options
459-- Writer options
460--
460--
461
461
462−data HTMLMathMethod = PlainMath
462+data HTMLMathMethod = PlainMath
463 | LaTeXMathML (Maybe String) -- url of LaTeXMathML.js
463 | LaTeXMathML (Maybe String) -- url of LaTeXMathML.js
464 | JsMath (Maybe String) -- url of jsMath load script
464 | JsMath (Maybe String) -- url of jsMath load script
465 | GladTeX
465 | GladTeX
@@ -534,7 +534,7 @@ instance Default WriterOptions where
534{-# DEPRECATED writerXeTeX "writerXeTeX no longer does anything" #-}
534{-# DEPRECATED writerXeTeX "writerXeTeX no longer does anything" #-}
535-- | Default writer options.
535-- | Default writer options.
536defaultWriterOptions :: WriterOptions
536defaultWriterOptions :: WriterOptions
537−defaultWriterOptions =
537+defaultWriterOptions =
538 WriterOptions { writerStandalone = False
538 WriterOptions { writerStandalone = False
539 , writerTemplate = ""
539 , writerTemplate = ""
540 , writerVariables = []
540 , writerVariables = []
src/Text/Pandoc/Templates.hs+8−8
@@ -30,7 +30,7 @@ A simple templating system with variable substitution and conditionals.
30Example:
30Example:
31
31
32> renderTemplate [("name","Sam"),("salary","50,000")] $
32> renderTemplate [("name","Sam"),("salary","50,000")] $
33−> "Hi, $name$. $if(salary)$You make $$$salary$.$else$No salary data.$endif$"
33+> "Hi, $name$. $if(salary)$You make $$$salary$.$else$No salary data.$endif$"
34> "Hi, John. You make $50,000."
34> "Hi, John. You make $50,000."
35
35
36A slot for an interpolated variable is a variable name surrounded
36A slot for an interpolated variable is a variable name surrounded
@@ -83,8 +83,8 @@ import Text.Pandoc.Shared (readDataFile)
83import qualified Control.Exception.Extensible as E (try, IOException)
83import qualified Control.Exception.Extensible as E (try, IOException)
84
84
85-- | Get default template for the specified writer.
85-- | Get default template for the specified writer.
86−getDefaultTemplate :: (Maybe FilePath) -- ^ User data directory to search first
86+getDefaultTemplate :: (Maybe FilePath) -- ^ User data directory to search first
87− -> String -- ^ Name of writer
87+ -> String -- ^ Name of writer
88 -> IO (Either E.IOException String)
88 -> IO (Either E.IOException String)
89getDefaultTemplate _ "native" = return $ Right ""
89getDefaultTemplate _ "native" = return $ Right ""
90getDefaultTemplate _ "json" = return $ Right ""
90getDefaultTemplate _ "json" = return $ Right ""
@@ -108,18 +108,18 @@ adjustPosition str = do
108 return str
108 return str
109
109
110class TemplateTarget a where
110class TemplateTarget a where
111− toTarget :: String -> a
111+ toTarget :: String -> a
112
112
113instance TemplateTarget String where
113instance TemplateTarget String where
114 toTarget = id
114 toTarget = id
115
115
116−instance TemplateTarget ByteString where
116+instance TemplateTarget ByteString where
117 toTarget = fromString
117 toTarget = fromString
118
118
119instance TemplateTarget Html where
119instance TemplateTarget Html where
120 toTarget = preEscapedString
120 toTarget = preEscapedString
121
121
122−-- | Renders a template
122+-- | Renders a template
123renderTemplate :: TemplateTarget a
123renderTemplate :: TemplateTarget a
124 => [(String,String)] -- ^ Assoc. list of values for variables
124 => [(String,String)] -- ^ Assoc. list of values for variables
125 -> String -- ^ Template
125 -> String -- ^ Template
@@ -178,14 +178,14 @@ for = try $ do
178 string ")$"
178 string ")$"
179 -- if newline after the "for", then a newline after "endfor" will be swallowed
179 -- if newline after the "for", then a newline after "endfor" will be swallowed
180 multiline <- option False $ try $ skipEndline >> return True
180 multiline <- option False $ try $ skipEndline >> return True
181− let matches = filter (\(k,_) -> k == id') vars
181+ let matches = filter (\(k,_) -> k == id') vars
182 let indent = replicate pos ' '
182 let indent = replicate pos ' '
183 contents <- forM matches $ \m -> do
183 contents <- forM matches $ \m -> do
184 updateState $ \(TemplateState p v) -> TemplateState p (m:v)
184 updateState $ \(TemplateState p v) -> TemplateState p (m:v)
185 raw <- liftM concat $ lookAhead parseTemplate
185 raw <- liftM concat $ lookAhead parseTemplate
186 return $ intercalate ('\n':indent) $ lines $ raw ++ "\n"
186 return $ intercalate ('\n':indent) $ lines $ raw ++ "\n"
187 parseTemplate
187 parseTemplate
188− sep <- option "" $ do try (string "$sep$")
188+ sep <- option "" $ do try (string "$sep$")
189 when multiline $ optional skipEndline
189 when multiline $ optional skipEndline
190 liftM concat parseTemplate
190 liftM concat parseTemplate
191 string "$endfor$"
191 string "$endfor$"
src/Text/Pandoc/UTF8.hs+1−1
@@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19{- |
19{- |
20 Module : Text.Pandoc.UTF8
20 Module : Text.Pandoc.UTF8
21 Copyright : Copyright (C) 2010 John MacFarlane
21 Copyright : Copyright (C) 2010 John MacFarlane
22− License : GNU GPL, version 2 or above
22+ License : GNU GPL, version 2 or above
23
23
24 Maintainer : John MacFarlane <jgm@berkeley.edu>
24 Maintainer : John MacFarlane <jgm@berkeley.edu>
25 Stability : alpha
25 Stability : alpha
src/Text/Pandoc/Writers/ConTeXt.hs+23−23
@@ -20,10 +20,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20{- |
20{- |
21 Module : Text.Pandoc.Writers.ConTeXt
21 Module : Text.Pandoc.Writers.ConTeXt
22 Copyright : Copyright (C) 2007-2010 John MacFarlane
22 Copyright : Copyright (C) 2007-2010 John MacFarlane
23− License : GNU GPL, version 2 or above
23+ License : GNU GPL, version 2 or above
24
24
25 Maintainer : John MacFarlane <jgm@berkeley.edu>
25 Maintainer : John MacFarlane <jgm@berkeley.edu>
26− Stability : alpha
26+ Stability : alpha
27 Portability : portable
27 Portability : portable
28
28
29Conversion of 'Pandoc' format into ConTeXt.
29Conversion of 'Pandoc' format into ConTeXt.
@@ -39,23 +39,23 @@ import Text.Pandoc.Pretty
39import Text.Pandoc.Templates ( renderTemplate )
39import Text.Pandoc.Templates ( renderTemplate )
40import Network.URI ( isURI, unEscapeString )
40import Network.URI ( isURI, unEscapeString )
41
41
42−data WriterState =
42+data WriterState =
43 WriterState { stNextRef :: Int -- number of next URL reference
43 WriterState { stNextRef :: Int -- number of next URL reference
44 , stOrderedListLevel :: Int -- level of ordered list
44 , stOrderedListLevel :: Int -- level of ordered list
45 , stOptions :: WriterOptions -- writer options
45 , stOptions :: WriterOptions -- writer options
46 }
46 }
47
47
48orderedListStyles :: [[Char]]
48orderedListStyles :: [[Char]]
49−orderedListStyles = cycle ["[n]","[a]", "[r]", "[g]"]
49+orderedListStyles = cycle ["[n]","[a]", "[r]", "[g]"]
50
50
51-- | Convert Pandoc to ConTeXt.
51-- | Convert Pandoc to ConTeXt.
52writeConTeXt :: WriterOptions -> Pandoc -> String
52writeConTeXt :: WriterOptions -> Pandoc -> String
53−writeConTeXt options document =
53+writeConTeXt options document =
54 let defaultWriterState = WriterState { stNextRef = 1
54 let defaultWriterState = WriterState { stNextRef = 1
55 , stOrderedListLevel = 0
55 , stOrderedListLevel = 0
56 , stOptions = options
56 , stOptions = options
57− }
57+ }
58− in evalState (pandocToConTeXt options document) defaultWriterState
58+ in evalState (pandocToConTeXt options document) defaultWriterState
59
59
60pandocToConTeXt :: WriterOptions -> Pandoc -> State WriterState String
60pandocToConTeXt :: WriterOptions -> Pandoc -> State WriterState String
61pandocToConTeXt options (Pandoc (Meta title authors date) blocks) = do
61pandocToConTeXt options (Pandoc (Meta title authors date) blocks) = do
@@ -120,7 +120,7 @@ elementToConTeXt opts (Sec level _ id' title' elements) = do
120 return $ vcat (header' : innerContents)
120 return $ vcat (header' : innerContents)
121
121
122-- | Convert Pandoc block element to ConTeXt.
122-- | Convert Pandoc block element to ConTeXt.
123−blockToConTeXt :: Block
123+blockToConTeXt :: Block
124 -> State WriterState Doc
124 -> State WriterState Doc
125blockToConTeXt Null = return empty
125blockToConTeXt Null = return empty
126blockToConTeXt (Plain lst) = inlineListToConTeXt lst
126blockToConTeXt (Plain lst) = inlineListToConTeXt lst
@@ -128,7 +128,7 @@ blockToConTeXt (Para [Image txt (src,_)]) = do
128 capt <- inlineListToConTeXt txt
128 capt <- inlineListToConTeXt txt
129 return $ blankline $$ "\\placefigure[here,nonumber]" <> braces capt <>
129 return $ blankline $$ "\\placefigure[here,nonumber]" <> braces capt <>
130 braces ("\\externalfigure" <> brackets (text src)) <> blankline
130 braces ("\\externalfigure" <> brackets (text src)) <> blankline
131−blockToConTeXt (Para lst) = do
131+blockToConTeXt (Para lst) = do
132 contents <- inlineListToConTeXt lst
132 contents <- inlineListToConTeXt lst
133 return $ contents <> blankline
133 return $ contents <> blankline
134blockToConTeXt (BlockQuote lst) = do
134blockToConTeXt (BlockQuote lst) = do
@@ -147,18 +147,18 @@ blockToConTeXt (OrderedList (start, style', delim) lst) = do
147 let level = stOrderedListLevel st
147 let level = stOrderedListLevel st
148 put $ st {stOrderedListLevel = level + 1}
148 put $ st {stOrderedListLevel = level + 1}
149 contents <- mapM listItemToConTeXt lst
149 contents <- mapM listItemToConTeXt lst
150− put $ st {stOrderedListLevel = level}
150+ put $ st {stOrderedListLevel = level}
151 let start' = if start == 1 then "" else "start=" ++ show start
151 let start' = if start == 1 then "" else "start=" ++ show start
152 let delim' = case delim of
152 let delim' = case delim of
153 DefaultDelim -> ""
153 DefaultDelim -> ""
154− Period -> "stopper=."
154+ Period -> "stopper=."
155− OneParen -> "stopper=)"
155+ OneParen -> "stopper=)"
156 TwoParens -> "left=(,stopper=)"
156 TwoParens -> "left=(,stopper=)"
157− let width = maximum $ map length $ take (length contents)
157+ let width = maximum $ map length $ take (length contents)
158 (orderedListMarkers (start, style', delim))
158 (orderedListMarkers (start, style', delim))
159 let width' = (toEnum width + 1) / 2
159 let width' = (toEnum width + 1) / 2
160− let width'' = if width' > (1.5 :: Double)
160+ let width'' = if width' > (1.5 :: Double)
161− then "width=" ++ show width' ++ "em"
161+ then "width=" ++ show width' ++ "em"
162 else ""
162 else ""
163 let specs2Items = filter (not . null) [start', delim', width'']
163 let specs2Items = filter (not . null) [start', delim', width'']
164 let specs2 = if null specs2Items
164 let specs2 = if null specs2Items
@@ -166,8 +166,8 @@ blockToConTeXt (OrderedList (start, style', delim) lst) = do
166 else "[" ++ intercalate "," specs2Items ++ "]"
166 else "[" ++ intercalate "," specs2Items ++ "]"
167 let style'' = case style' of
167 let style'' = case style' of
168 DefaultStyle -> orderedListStyles !! level
168 DefaultStyle -> orderedListStyles !! level
169− Decimal -> "[n]"
169+ Decimal -> "[n]"
170− Example -> "[n]"
170+ Example -> "[n]"
171 LowerRoman -> "[r]"
171 LowerRoman -> "[r]"
172 UpperRoman -> "[R]"
172 UpperRoman -> "[R]"
173 LowerAlpha -> "[a]"
173 LowerAlpha -> "[a]"
@@ -182,21 +182,21 @@ blockToConTeXt HorizontalRule = return $ "\\thinrule" <> blankline
182blockToConTeXt (Header level lst) = sectionHeader "" level lst
182blockToConTeXt (Header level lst) = sectionHeader "" level lst
183blockToConTeXt (Table caption aligns widths heads rows) = do
183blockToConTeXt (Table caption aligns widths heads rows) = do
184 let colDescriptor colWidth alignment = (case alignment of
184 let colDescriptor colWidth alignment = (case alignment of
185− AlignLeft -> 'l'
185+ AlignLeft -> 'l'
186 AlignRight -> 'r'
186 AlignRight -> 'r'
187 AlignCenter -> 'c'
187 AlignCenter -> 'c'
188 AlignDefault -> 'l'):
188 AlignDefault -> 'l'):
189 if colWidth == 0
189 if colWidth == 0
190 then "|"
190 then "|"
191 else ("p(" ++ printf "%.2f" colWidth ++ "\\textwidth)|")
191 else ("p(" ++ printf "%.2f" colWidth ++ "\\textwidth)|")
192− let colDescriptors = "|" ++ (concat $
192+ let colDescriptors = "|" ++ (concat $
193 zipWith colDescriptor widths aligns)
193 zipWith colDescriptor widths aligns)
194 headers <- if all null heads
194 headers <- if all null heads
195 then return empty
195 then return empty
196− else liftM ($$ "\\HL") $ tableRowToConTeXt heads
196+ else liftM ($$ "\\HL") $ tableRowToConTeXt heads
197− captionText <- inlineListToConTeXt caption
197+ captionText <- inlineListToConTeXt caption
198 let captionText' = if null caption then text "none" else captionText
198 let captionText' = if null caption then text "none" else captionText
199− rows' <- mapM tableRowToConTeXt rows
199+ rows' <- mapM tableRowToConTeXt rows
200 return $ "\\placetable[here]" <> braces captionText' $$
200 return $ "\\placetable[here]" <> braces captionText' $$
201 "\\starttable" <> brackets (text colDescriptors) $$
201 "\\starttable" <> brackets (text colDescriptors) $$
202 "\\HL" $$ headers $$
202 "\\HL" $$ headers $$
@@ -230,7 +230,7 @@ inlineListToConTeXt lst = liftM hcat $ mapM inlineToConTeXt lst
230-- | Convert inline element to ConTeXt
230-- | Convert inline element to ConTeXt
231inlineToConTeXt :: Inline -- ^ Inline to convert
231inlineToConTeXt :: Inline -- ^ Inline to convert
232 -> State WriterState Doc
232 -> State WriterState Doc
233−inlineToConTeXt (Emph lst) = do
233+inlineToConTeXt (Emph lst) = do
234 contents <- inlineListToConTeXt lst
234 contents <- inlineListToConTeXt lst
235 return $ braces $ "\\em " <> contents
235 return $ braces $ "\\em " <> contents
236inlineToConTeXt (Strong lst) = do
236inlineToConTeXt (Strong lst) = do
src/Text/Pandoc/Writers/Docbook.hs+33−33
@@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19{- |
19{- |
20 Module : Text.Pandoc.Writers.Docbook
20 Module : Text.Pandoc.Writers.Docbook
21 Copyright : Copyright (C) 2006-2010 John MacFarlane
21 Copyright : Copyright (C) 2006-2010 John MacFarlane
22− License : GNU GPL, version 2 or above
22+ License : GNU GPL, version 2 or above
23
23
24 Maintainer : John MacFarlane <jgm@berkeley.edu>
24 Maintainer : John MacFarlane <jgm@berkeley.edu>
25 Stability : alpha
25 Stability : alpha
@@ -47,23 +47,23 @@ authorToDocbook opts name' =
47 let name = render Nothing $ inlinesToDocbook opts name'
47 let name = render Nothing $ inlinesToDocbook opts name'
48 in if ',' `elem` name
48 in if ',' `elem` name
49 then -- last name first
49 then -- last name first
50− let (lastname, rest) = break (==',') name
50+ let (lastname, rest) = break (==',') name
51 firstname = removeLeadingSpace rest in
51 firstname = removeLeadingSpace rest in
52− inTagsSimple "firstname" (text $ escapeStringForXML firstname) <>
52+ inTagsSimple "firstname" (text $ escapeStringForXML firstname) <>
53− inTagsSimple "surname" (text $ escapeStringForXML lastname)
53+ inTagsSimple "surname" (text $ escapeStringForXML lastname)
54 else -- last name last
54 else -- last name last
55 let namewords = words name
55 let namewords = words name
56− lengthname = length namewords
56+ lengthname = length namewords
57 (firstname, lastname) = case lengthname of
57 (firstname, lastname) = case lengthname of
58− 0 -> ("","")
58+ 0 -> ("","")
59 1 -> ("", name)
59 1 -> ("", name)
60 n -> (intercalate " " (take (n-1) namewords), last namewords)
60 n -> (intercalate " " (take (n-1) namewords), last namewords)
61− in inTagsSimple "firstname" (text $ escapeStringForXML firstname) $$
61+ in inTagsSimple "firstname" (text $ escapeStringForXML firstname) $$
62− inTagsSimple "surname" (text $ escapeStringForXML lastname)
62+ inTagsSimple "surname" (text $ escapeStringForXML lastname)
63
63
64-- | Convert Pandoc document to string in Docbook format.
64-- | Convert Pandoc document to string in Docbook format.
65writeDocbook :: WriterOptions -> Pandoc -> String
65writeDocbook :: WriterOptions -> Pandoc -> String
66−writeDocbook opts (Pandoc (Meta tit auths dat) blocks) =
66+writeDocbook opts (Pandoc (Meta tit auths dat) blocks) =
67 let title = inlinesToDocbook opts tit
67 let title = inlinesToDocbook opts tit
68 authors = map (authorToDocbook opts) auths
68 authors = map (authorToDocbook opts) auths
69 date = inlinesToDocbook opts dat
69 date = inlinesToDocbook opts dat
@@ -92,7 +92,7 @@ writeDocbook opts (Pandoc (Meta tit auths dat) blocks) =
92
92
93-- | Convert an Element to Docbook.
93-- | Convert an Element to Docbook.
94elementToDocbook :: WriterOptions -> Int -> Element -> Doc
94elementToDocbook :: WriterOptions -> Int -> Element -> Doc
95−elementToDocbook opts _ (Blk block) = blockToDocbook opts block
95+elementToDocbook opts _ (Blk block) = blockToDocbook opts block
96elementToDocbook opts lvl (Sec _ _num id' title elements) =
96elementToDocbook opts lvl (Sec _ _num id' title elements) =
97 -- Docbook doesn't allow sections with no content, so insert some if needed
97 -- Docbook doesn't allow sections with no content, so insert some if needed
98 let elements' = if null elements
98 let elements' = if null elements
@@ -115,10 +115,10 @@ plainToPara :: Block -> Block
115plainToPara (Plain x) = Para x
115plainToPara (Plain x) = Para x
116plainToPara x = x
116plainToPara x = x
117
117
118−-- | Convert a list of pairs of terms and definitions into a list of
118+-- | Convert a list of pairs of terms and definitions into a list of
119-- Docbook varlistentrys.
119-- Docbook varlistentrys.
120deflistItemsToDocbook :: WriterOptions -> [([Inline],[[Block]])] -> Doc
120deflistItemsToDocbook :: WriterOptions -> [([Inline],[[Block]])] -> Doc
121−deflistItemsToDocbook opts items =
121+deflistItemsToDocbook opts items =
122 vcat $ map (\(term, defs) -> deflistItemToDocbook opts term defs) items
122 vcat $ map (\(term, defs) -> deflistItemToDocbook opts term defs) items
123
123
124-- | Convert a term and a list of blocks into a Docbook varlistentry.
124-- | Convert a term and a list of blocks into a Docbook varlistentry.
@@ -167,9 +167,9 @@ blockToDocbook _ (CodeBlock (_,classes,_) str) =
167 then [s]
167 then [s]
168 else languagesByExtension . map toLower $ s
168 else languagesByExtension . map toLower $ s
169 langs = concatMap langsFrom classes
169 langs = concatMap langsFrom classes
170−blockToDocbook opts (BulletList lst) =
170+blockToDocbook opts (BulletList lst) =
171− inTagsIndented "itemizedlist" $ listItemsToDocbook opts lst
171+ inTagsIndented "itemizedlist" $ listItemsToDocbook opts lst
172−blockToDocbook _ (OrderedList _ []) = empty
172+blockToDocbook _ (OrderedList _ []) = empty
173blockToDocbook opts (OrderedList (start, numstyle, _) (first:rest)) =
173blockToDocbook opts (OrderedList (start, numstyle, _) (first:rest)) =
174 let attribs = case numstyle of
174 let attribs = case numstyle of
175 DefaultStyle -> []
175 DefaultStyle -> []
@@ -182,12 +182,12 @@ blockToDocbook opts (OrderedList (start, numstyle, _) (first:rest)) =
182 items = if start == 1
182 items = if start == 1
183 then listItemsToDocbook opts (first:rest)
183 then listItemsToDocbook opts (first:rest)
184 else (inTags True "listitem" [("override",show start)]
184 else (inTags True "listitem" [("override",show start)]
185− (blocksToDocbook opts $ map plainToPara first)) $$
185+ (blocksToDocbook opts $ map plainToPara first)) $$
186− listItemsToDocbook opts rest
186+ listItemsToDocbook opts rest
187 in inTags True "orderedlist" attribs items
187 in inTags True "orderedlist" attribs items
188−blockToDocbook opts (DefinitionList lst) =
188+blockToDocbook opts (DefinitionList lst) =
189− inTagsIndented "variablelist" $ deflistItemsToDocbook opts lst
189+ inTagsIndented "variablelist" $ deflistItemsToDocbook opts lst
190−blockToDocbook _ (RawBlock "docbook" str) = text str -- raw XML block
190+blockToDocbook _ (RawBlock "docbook" str) = text str -- raw XML block
191-- we allow html for compatibility with earlier versions of pandoc
191-- we allow html for compatibility with earlier versions of pandoc
192blockToDocbook _ (RawBlock "html" str) = text str -- raw XML block
192blockToDocbook _ (RawBlock "html" str) = text str -- raw XML block
193blockToDocbook _ (RawBlock _ _) = empty
193blockToDocbook _ (RawBlock _ _) = empty
@@ -237,26 +237,26 @@ inlinesToDocbook opts lst = hcat $ map (inlineToDocbook opts) lst
237
237
238-- | Convert an inline element to Docbook.
238-- | Convert an inline element to Docbook.
239inlineToDocbook :: WriterOptions -> Inline -> Doc
239inlineToDocbook :: WriterOptions -> Inline -> Doc
240−inlineToDocbook _ (Str str) = text $ escapeStringForXML str
240+inlineToDocbook _ (Str str) = text $ escapeStringForXML str
241−inlineToDocbook opts (Emph lst) =
241+inlineToDocbook opts (Emph lst) =
242 inTagsSimple "emphasis" $ inlinesToDocbook opts lst
242 inTagsSimple "emphasis" $ inlinesToDocbook opts lst
243−inlineToDocbook opts (Strong lst) =
243+inlineToDocbook opts (Strong lst) =
244 inTags False "emphasis" [("role", "strong")] $ inlinesToDocbook opts lst
244 inTags False "emphasis" [("role", "strong")] $ inlinesToDocbook opts lst
245−inlineToDocbook opts (Strikeout lst) =
245+inlineToDocbook opts (Strikeout lst) =
246 inTags False "emphasis" [("role", "strikethrough")] $
246 inTags False "emphasis" [("role", "strikethrough")] $
247 inlinesToDocbook opts lst
247 inlinesToDocbook opts lst
248−inlineToDocbook opts (Superscript lst) =
248+inlineToDocbook opts (Superscript lst) =
249 inTagsSimple "superscript" $ inlinesToDocbook opts lst
249 inTagsSimple "superscript" $ inlinesToDocbook opts lst
250−inlineToDocbook opts (Subscript lst) =
250+inlineToDocbook opts (Subscript lst) =
251 inTagsSimple "subscript" $ inlinesToDocbook opts lst
251 inTagsSimple "subscript" $ inlinesToDocbook opts lst
252−inlineToDocbook opts (SmallCaps lst) =
252+inlineToDocbook opts (SmallCaps lst) =
253 inTags False "emphasis" [("role", "smallcaps")] $
253 inTags False "emphasis" [("role", "smallcaps")] $
254 inlinesToDocbook opts lst
254 inlinesToDocbook opts lst
255−inlineToDocbook opts (Quoted _ lst) =
255+inlineToDocbook opts (Quoted _ lst) =
256 inTagsSimple "quote" $ inlinesToDocbook opts lst
256 inTagsSimple "quote" $ inlinesToDocbook opts lst
257inlineToDocbook opts (Cite _ lst) =
257inlineToDocbook opts (Cite _ lst) =
258− inlinesToDocbook opts lst
258+ inlinesToDocbook opts lst
259−inlineToDocbook _ (Code _ str) =
259+inlineToDocbook _ (Code _ str) =
260 inTagsSimple "literal" $ text (escapeStringForXML str)
260 inTagsSimple "literal" $ text (escapeStringForXML str)
261inlineToDocbook opts (Math t str)
261inlineToDocbook opts (Math t str)
262 | isMathML (writerHTMLMathMethod opts) =
262 | isMathML (writerHTMLMathMethod opts) =
@@ -282,7 +282,7 @@ inlineToDocbook _ Space = space
282inlineToDocbook opts (Link txt (src, _)) =
282inlineToDocbook opts (Link txt (src, _)) =
283 if isPrefixOf "mailto:" src
283 if isPrefixOf "mailto:" src
284 then let src' = drop 7 src
284 then let src' = drop 7 src
285− emailLink = inTagsSimple "email" $ text $
285+ emailLink = inTagsSimple "email" $ text $
286 escapeStringForXML $ src'
286 escapeStringForXML $ src'
287 in case txt of
287 in case txt of
288 [Code _ s] | s == src' -> emailLink
288 [Code _ s] | s == src' -> emailLink
@@ -292,14 +292,14 @@ inlineToDocbook opts (Link txt (src, _)) =
292 then inTags False "link" [("linkend", drop 1 src)]
292 then inTags False "link" [("linkend", drop 1 src)]
293 else inTags False "ulink" [("url", src)]) $
293 else inTags False "ulink" [("url", src)]) $
294 inlinesToDocbook opts txt
294 inlinesToDocbook opts txt
295−inlineToDocbook _ (Image _ (src, tit)) =
295+inlineToDocbook _ (Image _ (src, tit)) =
296 let titleDoc = if null tit
296 let titleDoc = if null tit
297 then empty
297 then empty
298 else inTagsIndented "objectinfo" $
298 else inTagsIndented "objectinfo" $
299 inTagsIndented "title" (text $ escapeStringForXML tit)
299 inTagsIndented "title" (text $ escapeStringForXML tit)
300 in inTagsIndented "inlinemediaobject" $ inTagsIndented "imageobject" $
300 in inTagsIndented "inlinemediaobject" $ inTagsIndented "imageobject" $
301 titleDoc $$ selfClosingTag "imagedata" [("fileref", src)]
301 titleDoc $$ selfClosingTag "imagedata" [("fileref", src)]
302−inlineToDocbook opts (Note contents) =
302+inlineToDocbook opts (Note contents) =
303 inTagsIndented "footnote" $ blocksToDocbook opts contents
303 inTagsIndented "footnote" $ blocksToDocbook opts contents
304
304
305isMathML :: HTMLMathMethod -> Bool
305isMathML :: HTMLMathMethod -> Bool
src/Text/Pandoc/Writers/HTML.hs+1−1
@@ -618,7 +618,7 @@ inlineToHtml opts inline =
618 ! A.src (toValue $ url ++ urlEncode str)
618 ! A.src (toValue $ url ++ urlEncode str)
619 ! A.alt (toValue str)
619 ! A.alt (toValue str)
620 ! A.title (toValue str)
620 ! A.title (toValue str)
621− let brtag = if writerHtml5 opts then H5.br else H.br
621+ let brtag = if writerHtml5 opts then H5.br else H.br
622 return $ case t of
622 return $ case t of
623 InlineMath -> m
623 InlineMath -> m
624 DisplayMath -> brtag >> m >> brtag
624 DisplayMath -> brtag >> m >> brtag
src/Text/Pandoc/Writers/Man.hs+39−39
@@ -17,9 +17,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17-}
17-}
18
18
19{- |
19{- |
20− Module : Text.Pandoc.Writers.Man
20+ Module : Text.Pandoc.Writers.Man
21 Copyright : Copyright (C) 2007-2010 John MacFarlane
21 Copyright : Copyright (C) 2007-2010 John MacFarlane
22− License : GNU GPL, version 2 or above
22+ License : GNU GPL, version 2 or above
23
23
24 Maintainer : John MacFarlane <jgm@berkeley.edu>
24 Maintainer : John MacFarlane <jgm@berkeley.edu>
25 Stability : alpha
25 Stability : alpha
@@ -44,21 +44,21 @@ data WriterState = WriterState { stNotes :: Notes
44
44
45-- | Convert Pandoc to Man.
45-- | Convert Pandoc to Man.
46writeMan :: WriterOptions -> Pandoc -> String
46writeMan :: WriterOptions -> Pandoc -> String
47−writeMan opts document = evalState (pandocToMan opts document) (WriterState [] False)
47+writeMan opts document = evalState (pandocToMan opts document) (WriterState [] False)
48
48
49-- | Return groff man representation of document.
49-- | Return groff man representation of document.
50pandocToMan :: WriterOptions -> Pandoc -> State WriterState String
50pandocToMan :: WriterOptions -> Pandoc -> State WriterState String
51pandocToMan opts (Pandoc (Meta title authors date) blocks) = do
51pandocToMan opts (Pandoc (Meta title authors date) blocks) = do
52 titleText <- inlineListToMan opts title
52 titleText <- inlineListToMan opts title
53 authors' <- mapM (inlineListToMan opts) authors
53 authors' <- mapM (inlineListToMan opts) authors
54− date' <- inlineListToMan opts date
54+ date' <- inlineListToMan opts date
55 let colwidth = if writerWrapText opts
55 let colwidth = if writerWrapText opts
56 then Just $ writerColumns opts
56 then Just $ writerColumns opts
57 else Nothing
57 else Nothing
58 let render' = render colwidth
58 let render' = render colwidth
59 let (cmdName, rest) = break (== ' ') $ render' titleText
59 let (cmdName, rest) = break (== ' ') $ render' titleText
60 let (title', section) = case reverse cmdName of
60 let (title', section) = case reverse cmdName of
61− (')':d:'(':xs) | d `elem` ['0'..'9'] ->
61+ (')':d:'(':xs) | d `elem` ['0'..'9'] ->
62 (text (reverse xs), char d)
62 (text (reverse xs), char d)
63 xs -> (text (reverse xs), doubleQuotes empty)
63 xs -> (text (reverse xs), doubleQuotes empty)
64 let description = hsep $
64 let description = hsep $
@@ -86,7 +86,7 @@ notesToMan :: WriterOptions -> [[Block]] -> State WriterState Doc
86notesToMan opts notes =
86notesToMan opts notes =
87 if null notes
87 if null notes
88 then return empty
88 then return empty
89− else mapM (\(num, note) -> noteToMan opts num note) (zip [1..] notes) >>=
89+ else mapM (\(num, note) -> noteToMan opts num note) (zip [1..] notes) >>=
90 return . (text ".SH NOTES" $$) . vcat
90 return . (text ".SH NOTES" $$) . vcat
91
91
92-- | Return man representation of a note.
92-- | Return man representation of a note.
@@ -94,7 +94,7 @@ noteToMan :: WriterOptions -> Int -> [Block] -> State WriterState Doc
94noteToMan opts num note = do
94noteToMan opts num note = do
95 contents <- blockListToMan opts note
95 contents <- blockListToMan opts note
96 let marker = cr <> text ".SS " <> brackets (text (show num))
96 let marker = cr <> text ".SS " <> brackets (text (show num))
97− return $ marker $$ contents
97+ return $ marker $$ contents
98
98
99-- | Association list of characters to escape.
99-- | Association list of characters to escape.
100manEscapes :: [(Char, String)]
100manEscapes :: [(Char, String)]
@@ -113,7 +113,7 @@ escapeString = escapeStringUsing manEscapes
113-- | Escape a literal (code) section for Man.
113-- | Escape a literal (code) section for Man.
114escapeCode :: String -> String
114escapeCode :: String -> String
115escapeCode = concat . intersperse "\n" . map escapeLine . lines where
115escapeCode = concat . intersperse "\n" . map escapeLine . lines where
116− escapeLine codeline =
116+ escapeLine codeline =
117 case escapeStringUsing (manEscapes ++ backslashEscapes "\t ") codeline of
117 case escapeStringUsing (manEscapes ++ backslashEscapes "\t ") codeline of
118 a@('.':_) -> "\\&" ++ a
118 a@('.':_) -> "\\&" ++ a
119 b -> b
119 b -> b
@@ -150,14 +150,14 @@ splitSentences xs =
150-- | Convert Pandoc block element to man.
150-- | Convert Pandoc block element to man.
151blockToMan :: WriterOptions -- ^ Options
151blockToMan :: WriterOptions -- ^ Options
152 -> Block -- ^ Block element
152 -> Block -- ^ Block element
153− -> State WriterState Doc
153+ -> State WriterState Doc
154blockToMan _ Null = return empty
154blockToMan _ Null = return empty
155−blockToMan opts (Plain inlines) =
155+blockToMan opts (Plain inlines) =
156 liftM vcat $ mapM (inlineListToMan opts) $ splitSentences inlines
156 liftM vcat $ mapM (inlineListToMan opts) $ splitSentences inlines
157blockToMan opts (Para inlines) = do
157blockToMan opts (Para inlines) = do
158 contents <- liftM vcat $ mapM (inlineListToMan opts) $
158 contents <- liftM vcat $ mapM (inlineListToMan opts) $
159 splitSentences inlines
159 splitSentences inlines
160− return $ text ".PP" $$ contents
160+ return $ text ".PP" $$ contents
161blockToMan _ (RawBlock "man" str) = return $ text str
161blockToMan _ (RawBlock "man" str) = return $ text str
162blockToMan _ (RawBlock _ _) = return empty
162blockToMan _ (RawBlock _ _) = return empty
163blockToMan _ HorizontalRule = return $ text ".PP" $$ text " * * * * *"
163blockToMan _ HorizontalRule = return $ text ".PP" $$ text " * * * * *"
@@ -166,7 +166,7 @@ blockToMan opts (Header level inlines) = do
166 let heading = case level of
166 let heading = case level of
167 1 -> ".SH "
167 1 -> ".SH "
168 _ -> ".SS "
168 _ -> ".SS "
169− return $ text heading <> contents
169+ return $ text heading <> contents
170blockToMan _ (CodeBlock _ str) = return $
170blockToMan _ (CodeBlock _ str) = return $
171 text ".IP" $$
171 text ".IP" $$
172 text ".nf" $$
172 text ".nf" $$
@@ -174,10 +174,10 @@ blockToMan _ (CodeBlock _ str) = return $
174 text (escapeCode str) $$
174 text (escapeCode str) $$
175 text "\\f[]" $$
175 text "\\f[]" $$
176 text ".fi"
176 text ".fi"
177−blockToMan opts (BlockQuote blocks) = do
177+blockToMan opts (BlockQuote blocks) = do
178 contents <- blockListToMan opts blocks
178 contents <- blockListToMan opts blocks
179 return $ text ".RS" $$ contents $$ text ".RE"
179 return $ text ".RS" $$ contents $$ text ".RE"
180−blockToMan opts (Table caption alignments widths headers rows) =
180+blockToMan opts (Table caption alignments widths headers rows) =
181 let aligncode AlignLeft = "l"
181 let aligncode AlignLeft = "l"
182 aligncode AlignRight = "r"
182 aligncode AlignRight = "r"
183 aligncode AlignCenter = "c"
183 aligncode AlignCenter = "c"
@@ -190,53 +190,53 @@ blockToMan opts (Table caption alignments widths headers rows) =
190 else map (printf "w(%0.2fn)" . (70 *)) widths
190 else map (printf "w(%0.2fn)" . (70 *)) widths
191 -- 78n default width - 8n indent = 70n
191 -- 78n default width - 8n indent = 70n
192 let coldescriptions = text $ intercalate " "
192 let coldescriptions = text $ intercalate " "
193− (zipWith (\align width -> aligncode align ++ width)
193+ (zipWith (\align width -> aligncode align ++ width)
194 alignments iwidths) ++ "."
194 alignments iwidths) ++ "."
195 colheadings <- mapM (blockListToMan opts) headers
195 colheadings <- mapM (blockListToMan opts) headers
196− let makeRow cols = text "T{" $$
196+ let makeRow cols = text "T{" $$
197− (vcat $ intersperse (text "T}@T{") cols) $$
197+ (vcat $ intersperse (text "T}@T{") cols) $$
198 text "T}"
198 text "T}"
199 let colheadings' = if all null headers
199 let colheadings' = if all null headers
200 then empty
200 then empty
201 else makeRow colheadings $$ char '_'
201 else makeRow colheadings $$ char '_'
202− body <- mapM (\row -> do
202+ body <- mapM (\row -> do
203 cols <- mapM (blockListToMan opts) row
203 cols <- mapM (blockListToMan opts) row
204 return $ makeRow cols) rows
204 return $ makeRow cols) rows
205− return $ text ".PP" $$ caption' $$
205+ return $ text ".PP" $$ caption' $$
206− text ".TS" $$ text "tab(@);" $$ coldescriptions $$
206+ text ".TS" $$ text "tab(@);" $$ coldescriptions $$
207 colheadings' $$ vcat body $$ text ".TE"
207 colheadings' $$ vcat body $$ text ".TE"
208
208
209blockToMan opts (BulletList items) = do
209blockToMan opts (BulletList items) = do
210 contents <- mapM (bulletListItemToMan opts) items
210 contents <- mapM (bulletListItemToMan opts) items
211− return (vcat contents)
211+ return (vcat contents)
212blockToMan opts (OrderedList attribs items) = do
212blockToMan opts (OrderedList attribs items) = do
213− let markers = take (length items) $ orderedListMarkers attribs
213+ let markers = take (length items) $ orderedListMarkers attribs
214 let indent = 1 + (maximum $ map length markers)
214 let indent = 1 + (maximum $ map length markers)
215 contents <- mapM (\(num, item) -> orderedListItemToMan opts num indent item) $
215 contents <- mapM (\(num, item) -> orderedListItemToMan opts num indent item) $
216− zip markers items
216+ zip markers items
217 return (vcat contents)
217 return (vcat contents)
218−blockToMan opts (DefinitionList items) = do
218+blockToMan opts (DefinitionList items) = do
219 contents <- mapM (definitionListItemToMan opts) items
219 contents <- mapM (definitionListItemToMan opts) items
220 return (vcat contents)
220 return (vcat contents)
221
221
222-- | Convert bullet list item (list of blocks) to man.
222-- | Convert bullet list item (list of blocks) to man.
223bulletListItemToMan :: WriterOptions -> [Block] -> State WriterState Doc
223bulletListItemToMan :: WriterOptions -> [Block] -> State WriterState Doc
224bulletListItemToMan _ [] = return empty
224bulletListItemToMan _ [] = return empty
225−bulletListItemToMan opts ((Para first):rest) =
225+bulletListItemToMan opts ((Para first):rest) =
226 bulletListItemToMan opts ((Plain first):rest)
226 bulletListItemToMan opts ((Plain first):rest)
227bulletListItemToMan opts ((Plain first):rest) = do
227bulletListItemToMan opts ((Plain first):rest) = do
228− first' <- blockToMan opts (Plain first)
228+ first' <- blockToMan opts (Plain first)
229 rest' <- blockListToMan opts rest
229 rest' <- blockListToMan opts rest
230 let first'' = text ".IP \\[bu] 2" $$ first'
230 let first'' = text ".IP \\[bu] 2" $$ first'
231 let rest'' = if null rest
231 let rest'' = if null rest
232 then empty
232 then empty
233 else text ".RS 2" $$ rest' $$ text ".RE"
233 else text ".RS 2" $$ rest' $$ text ".RE"
234− return (first'' $$ rest'')
234+ return (first'' $$ rest'')
235bulletListItemToMan opts (first:rest) = do
235bulletListItemToMan opts (first:rest) = do
236 first' <- blockToMan opts first
236 first' <- blockToMan opts first
237 rest' <- blockListToMan opts rest
237 rest' <- blockListToMan opts rest
238 return $ text "\\[bu] .RS 2" $$ first' $$ rest' $$ text ".RE"
238 return $ text "\\[bu] .RS 2" $$ first' $$ rest' $$ text ".RE"
239−
239+
240-- | Convert ordered list item (a list of blocks) to man.
240-- | Convert ordered list item (a list of blocks) to man.
241orderedListItemToMan :: WriterOptions -- ^ options
241orderedListItemToMan :: WriterOptions -- ^ options
242 -> String -- ^ order marker for list item
242 -> String -- ^ order marker for list item
@@ -244,7 +244,7 @@ orderedListItemToMan :: WriterOptions -- ^ options
244 -> [Block] -- ^ list item (list of blocks)
244 -> [Block] -- ^ list item (list of blocks)
245 -> State WriterState Doc
245 -> State WriterState Doc
246orderedListItemToMan _ _ _ [] = return empty
246orderedListItemToMan _ _ _ [] = return empty
247−orderedListItemToMan opts num indent ((Para first):rest) =
247+orderedListItemToMan opts num indent ((Para first):rest) =
248 orderedListItemToMan opts num indent ((Plain first):rest)
248 orderedListItemToMan opts num indent ((Plain first):rest)
249orderedListItemToMan opts num indent (first:rest) = do
249orderedListItemToMan opts num indent (first:rest) = do
250 first' <- blockToMan opts first
250 first' <- blockToMan opts first
@@ -254,17 +254,17 @@ orderedListItemToMan opts num indent (first:rest) = do
254 let rest'' = if null rest
254 let rest'' = if null rest
255 then empty
255 then empty
256 else text ".RS 4" $$ rest' $$ text ".RE"
256 else text ".RS 4" $$ rest' $$ text ".RE"
257− return $ first'' $$ rest''
257+ return $ first'' $$ rest''
258
258
259-- | Convert definition list item (label, list of blocks) to man.
259-- | Convert definition list item (label, list of blocks) to man.
260definitionListItemToMan :: WriterOptions
260definitionListItemToMan :: WriterOptions
261− -> ([Inline],[[Block]])
261+ -> ([Inline],[[Block]])
262 -> State WriterState Doc
262 -> State WriterState Doc
263definitionListItemToMan opts (label, defs) = do
263definitionListItemToMan opts (label, defs) = do
264 labelText <- inlineListToMan opts label
264 labelText <- inlineListToMan opts label
265− contents <- if null defs
265+ contents <- if null defs
266 then return empty
266 then return empty
267− else liftM vcat $ forM defs $ \blocks -> do
267+ else liftM vcat $ forM defs $ \blocks -> do
268 let (first, rest) = case blocks of
268 let (first, rest) = case blocks of
269 ((Para x):y) -> (Plain x,y)
269 ((Para x):y) -> (Plain x,y)
270 (x:y) -> (x,y)
270 (x:y) -> (x,y)
@@ -278,7 +278,7 @@ definitionListItemToMan opts (label, defs) = do
278-- | Convert list of Pandoc block elements to man.
278-- | Convert list of Pandoc block elements to man.
279blockListToMan :: WriterOptions -- ^ Options
279blockListToMan :: WriterOptions -- ^ Options
280 -> [Block] -- ^ List of block elements
280 -> [Block] -- ^ List of block elements
281− -> State WriterState Doc
281+ -> State WriterState Doc
282blockListToMan opts blocks =
282blockListToMan opts blocks =
283 mapM (blockToMan opts) blocks >>= (return . vcat)
283 mapM (blockToMan opts) blocks >>= (return . vcat)
284
284
@@ -292,7 +292,7 @@ inlineListToMan opts lst = mapM (inlineToMan opts) lst >>= (return . hcat)
292
292
293-- | Convert Pandoc inline element to man.
293-- | Convert Pandoc inline element to man.
294inlineToMan :: WriterOptions -> Inline -> State WriterState Doc
294inlineToMan :: WriterOptions -> Inline -> State WriterState Doc
295−inlineToMan opts (Emph lst) = do
295+inlineToMan opts (Emph lst) = do
296 contents <- inlineListToMan opts lst
296 contents <- inlineListToMan opts lst
297 return $ text "\\f[I]" <> contents <> text "\\f[]"
297 return $ text "\\f[I]" <> contents <> text "\\f[]"
298inlineToMan opts (Strong lst) = do
298inlineToMan opts (Strong lst) = do
@@ -333,16 +333,16 @@ inlineToMan opts (Link txt (src, _)) = do
333 let srcSuffix = if isPrefixOf "mailto:" src then drop 7 src else src
333 let srcSuffix = if isPrefixOf "mailto:" src then drop 7 src else src
334 return $ case txt of
334 return $ case txt of
335 [Code _ s]
335 [Code _ s]
336− | s == srcSuffix -> char '<' <> text srcSuffix <> char '>'
336+ | s == srcSuffix -> char '<' <> text srcSuffix <> char '>'
337 _ -> linktext <> text " (" <> text src <> char ')'
337 _ -> linktext <> text " (" <> text src <> char ')'
338inlineToMan opts (Image alternate (source, tit)) = do
338inlineToMan opts (Image alternate (source, tit)) = do
339− let txt = if (null alternate) || (alternate == [Str ""]) ||
339+ let txt = if (null alternate) || (alternate == [Str ""]) ||
340 (alternate == [Str source]) -- to prevent autolinks
340 (alternate == [Str source]) -- to prevent autolinks
341 then [Str "image"]
341 then [Str "image"]
342 else alternate
342 else alternate
343− linkPart <- inlineToMan opts (Link txt (source, tit))
343+ linkPart <- inlineToMan opts (Link txt (source, tit))
344 return $ char '[' <> text "IMAGE: " <> linkPart <> char ']'
344 return $ char '[' <> text "IMAGE: " <> linkPart <> char ']'
345−inlineToMan _ (Note contents) = do
345+inlineToMan _ (Note contents) = do
346 -- add to notes in state
346 -- add to notes in state
347 modify $ \st -> st{ stNotes = contents : stNotes st }
347 modify $ \st -> st{ stNotes = contents : stNotes st }
348 notes <- liftM stNotes get
348 notes <- liftM stNotes get
src/Text/Pandoc/Writers/Markdown.hs+20−20
@@ -18,9 +18,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18-}
18-}
19
19
20{- |
20{- |
21− Module : Text.Pandoc.Writers.Markdown
21+ Module : Text.Pandoc.Writers.Markdown
22 Copyright : Copyright (C) 2006-2010 John MacFarlane
22 Copyright : Copyright (C) 2006-2010 John MacFarlane
23− License : GNU GPL, version 2 or above
23+ License : GNU GPL, version 2 or above
24
24
25 Maintainer : John MacFarlane <jgm@berkeley.edu>
25 Maintainer : John MacFarlane <jgm@berkeley.edu>
26 Stability : alpha
26 Stability : alpha
@@ -48,7 +48,7 @@ data WriterState = WriterState { stNotes :: Notes
48
48
49-- | Convert Pandoc to Markdown.
49-- | Convert Pandoc to Markdown.
50writeMarkdown :: WriterOptions -> Pandoc -> String
50writeMarkdown :: WriterOptions -> Pandoc -> String
51−writeMarkdown opts document =
51+writeMarkdown opts document =
52 evalState (pandocToMarkdown opts document) WriterState{ stNotes = []
52 evalState (pandocToMarkdown opts document) WriterState{ stNotes = []
53 , stRefs = []
53 , stRefs = []
54 , stPlain = False }
54 , stPlain = False }
@@ -88,7 +88,7 @@ pandocToMarkdown opts (Pandoc (Meta title authors date) blocks) = do
88 date' <- inlineListToMarkdown opts date
88 date' <- inlineListToMarkdown opts date
89 let titleblock = not $ null title && null authors && null date
89 let titleblock = not $ null title && null authors && null date
90 let headerBlocks = filter isHeaderBlock blocks
90 let headerBlocks = filter isHeaderBlock blocks
91− let toc = if writerTableOfContents opts
91+ let toc = if writerTableOfContents opts
92 then tableOfContents opts headerBlocks
92 then tableOfContents opts headerBlocks
93 else empty
93 else empty
94 body <- blockListToMarkdown opts blocks
94 body <- blockListToMarkdown opts blocks
@@ -118,9 +118,9 @@ pandocToMarkdown opts (Pandoc (Meta title authors date) blocks) = do
118refsToMarkdown :: WriterOptions -> Refs -> State WriterState Doc
118refsToMarkdown :: WriterOptions -> Refs -> State WriterState Doc
119refsToMarkdown opts refs = mapM (keyToMarkdown opts) refs >>= return . vcat
119refsToMarkdown opts refs = mapM (keyToMarkdown opts) refs >>= return . vcat
120
120
121−-- | Return markdown representation of a reference key.
121+-- | Return markdown representation of a reference key.
122−keyToMarkdown :: WriterOptions
122+keyToMarkdown :: WriterOptions
123− -> ([Inline], (String, String))
123+ -> ([Inline], (String, String))
124 -> State WriterState Doc
124 -> State WriterState Doc
125keyToMarkdown opts (label, (src, tit)) = do
125keyToMarkdown opts (label, (src, tit)) = do
126 label' <- inlineListToMarkdown opts label
126 label' <- inlineListToMarkdown opts label
@@ -132,7 +132,7 @@ keyToMarkdown opts (label, (src, tit)) = do
132
132
133-- | Return markdown representation of notes.
133-- | Return markdown representation of notes.
134notesToMarkdown :: WriterOptions -> [[Block]] -> State WriterState Doc
134notesToMarkdown :: WriterOptions -> [[Block]] -> State WriterState Doc
135−notesToMarkdown opts notes =
135+notesToMarkdown opts notes =
136 mapM (\(num, note) -> noteToMarkdown opts num note) (zip [1..] notes) >>=
136 mapM (\(num, note) -> noteToMarkdown opts num note) (zip [1..] notes) >>=
137 return . vsep
137 return . vsep
138
138
@@ -154,7 +154,7 @@ escapeString = escapeStringUsing markdownEscapes
154 where markdownEscapes = backslashEscapes "\\`*_$<>#~^"
154 where markdownEscapes = backslashEscapes "\\`*_$<>#~^"
155
155
156-- | Construct table of contents from list of header blocks.
156-- | Construct table of contents from list of header blocks.
157−tableOfContents :: WriterOptions -> [Block] -> Doc
157+tableOfContents :: WriterOptions -> [Block] -> Doc
158tableOfContents opts headers =
158tableOfContents opts headers =
159 let opts' = opts { writerIgnoreNotes = True }
159 let opts' = opts { writerIgnoreNotes = True }
160 contents = BulletList $ map elementToListItem $ hierarchicalize headers
160 contents = BulletList $ map elementToListItem $ hierarchicalize headers
@@ -165,7 +165,7 @@ tableOfContents opts headers =
165-- | Converts an Element to a list item for a table of contents,
165-- | Converts an Element to a list item for a table of contents,
166elementToListItem :: Element -> [Block]
166elementToListItem :: Element -> [Block]
167elementToListItem (Blk _) = []
167elementToListItem (Blk _) = []
168−elementToListItem (Sec _ _ _ headerText subsecs) = [Plain headerText] ++
168+elementToListItem (Sec _ _ _ headerText subsecs) = [Plain headerText] ++
169 if null subsecs
169 if null subsecs
170 then []
170 then []
171 else [BulletList $ map elementToListItem subsecs]
171 else [BulletList $ map elementToListItem subsecs]
@@ -189,7 +189,7 @@ attrsToMarkdown attribs = braces $ hsep [attribId, attribClasses, attribKeys]
189-- | Ordered list start parser for use in Para below.
189-- | Ordered list start parser for use in Para below.
190olMarker :: Parser [Char] ParserState Char
190olMarker :: Parser [Char] ParserState Char
191olMarker = do (start, style', delim) <- anyOrderedListMarker
191olMarker = do (start, style', delim) <- anyOrderedListMarker
192− if delim == Period &&
192+ if delim == Period &&
193 (style' == UpperAlpha || (style' == UpperRoman &&
193 (style' == UpperAlpha || (style' == UpperRoman &&
194 start `elem` [1, 5, 10, 50, 100, 500, 1000]))
194 start `elem` [1, 5, 10, 50, 100, 500, 1000]))
195 then spaceChar >> spaceChar
195 then spaceChar >> spaceChar
@@ -205,7 +205,7 @@ beginsWithOrderedListMarker str =
205-- | Convert Pandoc block element to markdown.
205-- | Convert Pandoc block element to markdown.
206blockToMarkdown :: WriterOptions -- ^ Options
206blockToMarkdown :: WriterOptions -- ^ Options
207 -> Block -- ^ Block element
207 -> Block -- ^ Block element
208− -> State WriterState Doc
208+ -> State WriterState Doc
209blockToMarkdown _ Null = return empty
209blockToMarkdown _ Null = return empty
210blockToMarkdown opts (Plain inlines) = do
210blockToMarkdown opts (Plain inlines) = do
211 contents <- inlineListToMarkdown opts inlines
211 contents <- inlineListToMarkdown opts inlines
@@ -348,7 +348,7 @@ orderedListItemToMarkdown opts marker items = do
348
348
349-- | Convert definition list item (label, list of blocks) to markdown.
349-- | Convert definition list item (label, list of blocks) to markdown.
350definitionListItemToMarkdown :: WriterOptions
350definitionListItemToMarkdown :: WriterOptions
351− -> ([Inline],[[Block]])
351+ -> ([Inline],[[Block]])
352 -> State WriterState Doc
352 -> State WriterState Doc
353definitionListItemToMarkdown opts (label, defs) = do
353definitionListItemToMarkdown opts (label, defs) = do
354 labelText <- inlineListToMarkdown opts label
354 labelText <- inlineListToMarkdown opts label
@@ -365,7 +365,7 @@ definitionListItemToMarkdown opts (label, defs) = do
365-- | Convert list of Pandoc block elements to markdown.
365-- | Convert list of Pandoc block elements to markdown.
366blockListToMarkdown :: WriterOptions -- ^ Options
366blockListToMarkdown :: WriterOptions -- ^ Options
367 -> [Block] -- ^ List of block elements
367 -> [Block] -- ^ List of block elements
368− -> State WriterState Doc
368+ -> State WriterState Doc
369blockListToMarkdown opts blocks =
369blockListToMarkdown opts blocks =
370 mapM (blockToMarkdown opts) (fixBlocks blocks) >>= return . cat
370 mapM (blockToMarkdown opts) (fixBlocks blocks) >>= return . cat
371 -- insert comment between list and indented code block, or the
371 -- insert comment between list and indented code block, or the
@@ -411,7 +411,7 @@ escapeSpaces x = x
411
411
412-- | Convert Pandoc inline element to markdown.
412-- | Convert Pandoc inline element to markdown.
413inlineToMarkdown :: WriterOptions -> Inline -> State WriterState Doc
413inlineToMarkdown :: WriterOptions -> Inline -> State WriterState Doc
414−inlineToMarkdown opts (Emph lst) = do
414+inlineToMarkdown opts (Emph lst) = do
415 contents <- inlineListToMarkdown opts lst
415 contents <- inlineListToMarkdown opts lst
416 return $ "*" <> contents <> "*"
416 return $ "*" <> contents <> "*"
417inlineToMarkdown opts (Strong lst) = do
417inlineToMarkdown opts (Strong lst) = do
@@ -436,11 +436,11 @@ inlineToMarkdown opts (Quoted DoubleQuote lst) = do
436 contents <- inlineListToMarkdown opts lst
436 contents <- inlineListToMarkdown opts lst
437 return $ "“" <> contents <> "”"
437 return $ "“" <> contents <> "”"
438inlineToMarkdown opts (Code attr str) =
438inlineToMarkdown opts (Code attr str) =
439− let tickGroups = filter (\s -> '`' `elem` s) $ group str
439+ let tickGroups = filter (\s -> '`' `elem` s) $ group str
440 longest = if null tickGroups
440 longest = if null tickGroups
441 then 0
441 then 0
442− else maximum $ map length tickGroups
442+ else maximum $ map length tickGroups
443− marker = replicate (longest + 1) '`'
443+ marker = replicate (longest + 1) '`'
444 spacer = if (longest == 0) then "" else " "
444 spacer = if (longest == 0) then "" else " "
445 attrs = if writerStrictMarkdown opts || attr == nullAttr
445 attrs = if writerStrictMarkdown opts || attr == nullAttr
446 then empty
446 then empty
@@ -512,7 +512,7 @@ inlineToMarkdown opts (Link txt (src, tit)) = do
512 then "[]"
512 then "[]"
513 else "[" <> reftext <> "]"
513 else "[" <> reftext <> "]"
514 in first <> second
514 in first <> second
515− else "[" <> linktext <> "](" <>
515+ else "[" <> linktext <> "](" <>
516 text src <> linktitle <> ")"
516 text src <> linktitle <> ")"
517inlineToMarkdown opts (Image alternate (source, tit)) = do
517inlineToMarkdown opts (Image alternate (source, tit)) = do
518 let txt = if null alternate || alternate == [Str source]
518 let txt = if null alternate || alternate == [Str source]
@@ -521,7 +521,7 @@ inlineToMarkdown opts (Image alternate (source, tit)) = do
521 else alternate
521 else alternate
522 linkPart <- inlineToMarkdown opts (Link txt (source, tit))
522 linkPart <- inlineToMarkdown opts (Link txt (source, tit))
523 return $ "!" <> linkPart
523 return $ "!" <> linkPart
524−inlineToMarkdown _ (Note contents) = do
524+inlineToMarkdown _ (Note contents) = do
525 modify (\st -> st{ stNotes = contents : stNotes st })
525 modify (\st -> st{ stNotes = contents : stNotes st })
526 st <- get
526 st <- get
527 let ref = show $ (length $ stNotes st)
527 let ref = show $ (length $ stNotes st)
src/Text/Pandoc/Writers/MediaWiki.hs+23−23
@@ -17,9 +17,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17-}
17-}
18
18
19{- |
19{- |
20− Module : Text.Pandoc.Writers.MediaWiki
20+ Module : Text.Pandoc.Writers.MediaWiki
21 Copyright : Copyright (C) 2008-2010 John MacFarlane
21 Copyright : Copyright (C) 2008-2010 John MacFarlane
22− License : GNU GPL, version 2 or above
22+ License : GNU GPL, version 2 or above
23
23
24 Maintainer : John MacFarlane <jgm@berkeley.edu>
24 Maintainer : John MacFarlane <jgm@berkeley.edu>
25 Stability : alpha
25 Stability : alpha
@@ -31,7 +31,7 @@ MediaWiki: <http://www.mediawiki.org/wiki/MediaWiki>
31-}
31-}
32module Text.Pandoc.Writers.MediaWiki ( writeMediaWiki ) where
32module Text.Pandoc.Writers.MediaWiki ( writeMediaWiki ) where
33import Text.Pandoc.Definition
33import Text.Pandoc.Definition
34−import Text.Pandoc.Shared
34+import Text.Pandoc.Shared
35import Text.Pandoc.Templates (renderTemplate)
35import Text.Pandoc.Templates (renderTemplate)
36import Text.Pandoc.XML ( escapeStringForXML )
36import Text.Pandoc.XML ( escapeStringForXML )
37import Data.List ( intersect, intercalate )
37import Data.List ( intersect, intercalate )
@@ -46,9 +46,9 @@ data WriterState = WriterState {
46
46
47-- | Convert Pandoc to MediaWiki.
47-- | Convert Pandoc to MediaWiki.
48writeMediaWiki :: WriterOptions -> Pandoc -> String
48writeMediaWiki :: WriterOptions -> Pandoc -> String
49−writeMediaWiki opts document =
49+writeMediaWiki opts document =
50− evalState (pandocToMediaWiki opts document)
50+ evalState (pandocToMediaWiki opts document)
51− (WriterState { stNotes = False, stListLevel = [], stUseTags = False })
51+ (WriterState { stNotes = False, stListLevel = [], stUseTags = False })
52
52
53-- | Return MediaWiki representation of document.
53-- | Return MediaWiki representation of document.
54pandocToMediaWiki :: WriterOptions -> Pandoc -> State WriterState String
54pandocToMediaWiki :: WriterOptions -> Pandoc -> State WriterState String
@@ -57,7 +57,7 @@ pandocToMediaWiki opts (Pandoc _ blocks) = do
57 notesExist <- get >>= return . stNotes
57 notesExist <- get >>= return . stNotes
58 let notes = if notesExist
58 let notes = if notesExist
59 then "\n<references />"
59 then "\n<references />"
60− else ""
60+ else ""
61 let main = body ++ notes
61 let main = body ++ notes
62 let context = writerVariables opts ++
62 let context = writerVariables opts ++
63 [ ("body", main) ] ++
63 [ ("body", main) ] ++
@@ -70,18 +70,18 @@ pandocToMediaWiki opts (Pandoc _ blocks) = do
70escapeString :: String -> String
70escapeString :: String -> String
71escapeString = escapeStringForXML
71escapeString = escapeStringForXML
72
72
73−-- | Convert Pandoc block element to MediaWiki.
73+-- | Convert Pandoc block element to MediaWiki.
74blockToMediaWiki :: WriterOptions -- ^ Options
74blockToMediaWiki :: WriterOptions -- ^ Options
75 -> Block -- ^ Block element
75 -> Block -- ^ Block element
76− -> State WriterState String
76+ -> State WriterState String
77
77
78blockToMediaWiki _ Null = return ""
78blockToMediaWiki _ Null = return ""
79
79
80−blockToMediaWiki opts (Plain inlines) =
80+blockToMediaWiki opts (Plain inlines) =
81 inlineListToMediaWiki opts inlines
81 inlineListToMediaWiki opts inlines
82
82
83blockToMediaWiki opts (Para [Image txt (src,tit)]) = do
83blockToMediaWiki opts (Para [Image txt (src,tit)]) = do
84− capt <- inlineListToMediaWiki opts txt
84+ capt <- inlineListToMediaWiki opts txt
85 let opt = if null txt
85 let opt = if null txt
86 then ""
86 then ""
87 else "|alt=" ++ if null tit then capt else tit ++
87 else "|alt=" ++ if null tit then capt else tit ++
@@ -115,7 +115,7 @@ blockToMediaWiki _ (CodeBlock (_,classes,_) str) = do
115 "javascript", "latex", "lisp", "lua", "matlab", "mirc", "mpasm", "mysql", "nsis", "objc",
115 "javascript", "latex", "lisp", "lua", "matlab", "mirc", "mpasm", "mysql", "nsis", "objc",
116 "ocaml", "ocaml-brief", "oobas", "oracle8", "pascal", "perl", "php", "php-brief", "plsql",
116 "ocaml", "ocaml-brief", "oobas", "oracle8", "pascal", "perl", "php", "php-brief", "plsql",
117 "python", "qbasic", "rails", "reg", "robots", "ruby", "sas", "scheme", "sdlbasic",
117 "python", "qbasic", "rails", "reg", "robots", "ruby", "sas", "scheme", "sdlbasic",
118− "smalltalk", "smarty", "sql", "tcl", "", "thinbasic", "tsql", "vb", "vbnet", "vhdl",
118+ "smalltalk", "smarty", "sql", "tcl", "", "thinbasic", "tsql", "vb", "vbnet", "vhdl",
119 "visualfoxpro", "winbatch", "xml", "xpp", "z80"]
119 "visualfoxpro", "winbatch", "xml", "xpp", "z80"]
120 let (beg, end) = if null at
120 let (beg, end) = if null at
121 then ("<pre" ++ if null classes then ">" else " class=\"" ++ unwords classes ++ "\">", "</pre>")
121 then ("<pre" ++ if null classes then ">" else " class=\"" ++ unwords classes ++ "\">", "</pre>")
@@ -124,7 +124,7 @@ blockToMediaWiki _ (CodeBlock (_,classes,_) str) = do
124
124
125blockToMediaWiki opts (BlockQuote blocks) = do
125blockToMediaWiki opts (BlockQuote blocks) = do
126 contents <- blockListToMediaWiki opts blocks
126 contents <- blockListToMediaWiki opts blocks
127− return $ "<blockquote>" ++ contents ++ "</blockquote>"
127+ return $ "<blockquote>" ++ contents ++ "</blockquote>"
128
128
129blockToMediaWiki opts (Table capt aligns widths headers rows') = do
129blockToMediaWiki opts (Table capt aligns widths headers rows') = do
130 let alignStrings = map alignmentToString aligns
130 let alignStrings = map alignmentToString aligns
@@ -221,7 +221,7 @@ listItemToMediaWiki opts items = do
221
221
222-- | Convert definition list item (label, list of blocks) to MediaWiki.
222-- | Convert definition list item (label, list of blocks) to MediaWiki.
223definitionListItemToMediaWiki :: WriterOptions
223definitionListItemToMediaWiki :: WriterOptions
224− -> ([Inline],[[Block]])
224+ -> ([Inline],[[Block]])
225 -> State WriterState String
225 -> State WriterState String
226definitionListItemToMediaWiki opts (label, items) = do
226definitionListItemToMediaWiki opts (label, items) = do
227 labelText <- inlineListToMediaWiki opts label
227 labelText <- inlineListToMediaWiki opts label
@@ -242,7 +242,7 @@ isSimpleList x =
242 BulletList items -> all isSimpleListItem items
242 BulletList items -> all isSimpleListItem items
243 OrderedList (num, sty, _) items -> all isSimpleListItem items &&
243 OrderedList (num, sty, _) items -> all isSimpleListItem items &&
244 num == 1 && sty `elem` [DefaultStyle, Decimal]
244 num == 1 && sty `elem` [DefaultStyle, Decimal]
245− DefinitionList items -> all isSimpleListItem $ concatMap snd items
245+ DefinitionList items -> all isSimpleListItem $ concatMap snd items
246 _ -> False
246 _ -> False
247
247
248-- | True if list item can be handled with the simple wiki syntax. False if
248-- | True if list item can be handled with the simple wiki syntax. False if
@@ -287,8 +287,8 @@ tableRowToMediaWiki opts alignStrings rownum cols' = do
287 0 -> "header"
287 0 -> "header"
288 x | x `rem` 2 == 1 -> "odd"
288 x | x `rem` 2 == 1 -> "odd"
289 _ -> "even"
289 _ -> "even"
290− cols'' <- sequence $ zipWith
290+ cols'' <- sequence $ zipWith
291− (\alignment item -> tableItemToMediaWiki opts celltype alignment item)
291+ (\alignment item -> tableItemToMediaWiki opts celltype alignment item)
292 alignStrings cols'
292 alignStrings cols'
293 return $ "<tr class=\"" ++ rowclass ++ "\">\n" ++ unlines cols'' ++ "</tr>"
293 return $ "<tr class=\"" ++ rowclass ++ "\">\n" ++ unlines cols'' ++ "</tr>"
294
294
@@ -313,7 +313,7 @@ tableItemToMediaWiki opts celltype align' item = do
313-- | Convert list of Pandoc block elements to MediaWiki.
313-- | Convert list of Pandoc block elements to MediaWiki.
314blockListToMediaWiki :: WriterOptions -- ^ Options
314blockListToMediaWiki :: WriterOptions -- ^ Options
315 -> [Block] -- ^ List of block elements
315 -> [Block] -- ^ List of block elements
316− -> State WriterState String
316+ -> State WriterState String
317blockListToMediaWiki opts blocks =
317blockListToMediaWiki opts blocks =
318 mapM (blockToMediaWiki opts) blocks >>= return . vcat
318 mapM (blockToMediaWiki opts) blocks >>= return . vcat
319
319
@@ -325,9 +325,9 @@ inlineListToMediaWiki opts lst =
325-- | Convert Pandoc inline element to MediaWiki.
325-- | Convert Pandoc inline element to MediaWiki.
326inlineToMediaWiki :: WriterOptions -> Inline -> State WriterState String
326inlineToMediaWiki :: WriterOptions -> Inline -> State WriterState String
327
327
328−inlineToMediaWiki opts (Emph lst) = do
328+inlineToMediaWiki opts (Emph lst) = do
329 contents <- inlineListToMediaWiki opts lst
329 contents <- inlineListToMediaWiki opts lst
330− return $ "''" ++ contents ++ "''"
330+ return $ "''" ++ contents ++ "''"
331
331
332inlineToMediaWiki opts (Strong lst) = do
332inlineToMediaWiki opts (Strong lst) = do
333 contents <- inlineListToMediaWiki opts lst
333 contents <- inlineListToMediaWiki opts lst
@@ -365,8 +365,8 @@ inlineToMediaWiki _ (Str str) = return $ escapeString str
365inlineToMediaWiki _ (Math _ str) = return $ "<math>" ++ str ++ "</math>"
365inlineToMediaWiki _ (Math _ str) = return $ "<math>" ++ str ++ "</math>"
366 -- note: str should NOT be escaped
366 -- note: str should NOT be escaped
367
367
368−inlineToMediaWiki _ (RawInline "mediawiki" str) = return str
368+inlineToMediaWiki _ (RawInline "mediawiki" str) = return str
369−inlineToMediaWiki _ (RawInline "html" str) = return str
369+inlineToMediaWiki _ (RawInline "html" str) = return str
370inlineToMediaWiki _ (RawInline _ _) = return ""
370inlineToMediaWiki _ (RawInline _ _) = return ""
371
371
372inlineToMediaWiki _ (LineBreak) = return "<br />\n"
372inlineToMediaWiki _ (LineBreak) = return "<br />\n"
@@ -392,7 +392,7 @@ inlineToMediaWiki opts (Image alt (source, tit)) = do
392 else "|" ++ tit
392 else "|" ++ tit
393 return $ "[[Image:" ++ source ++ txt ++ "]]"
393 return $ "[[Image:" ++ source ++ txt ++ "]]"
394
394
395−inlineToMediaWiki opts (Note contents) = do
395+inlineToMediaWiki opts (Note contents) = do
396 contents' <- blockListToMediaWiki opts contents
396 contents' <- blockListToMediaWiki opts contents
397 modify (\s -> s { stNotes = True })
397 modify (\s -> s { stNotes = True })
398 return $ "<ref>" ++ contents' ++ "</ref>"
398 return $ "<ref>" ++ contents' ++ "</ref>"
src/Text/Pandoc/Writers/Native.hs+4−4
@@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20{- |
20{- |
21 Module : Text.Pandoc.Writers.Native
21 Module : Text.Pandoc.Writers.Native
22 Copyright : Copyright (C) 2006-2010 John MacFarlane
22 Copyright : Copyright (C) 2006-2010 John MacFarlane
23− License : GNU GPL, version 2 or above
23+ License : GNU GPL, version 2 or above
24
24
25 Maintainer : John MacFarlane <jgm@berkeley.edu>
25 Maintainer : John MacFarlane <jgm@berkeley.edu>
26 Stability : alpha
26 Stability : alpha
@@ -47,17 +47,17 @@ prettyList ds =
47prettyBlock :: Block -> Doc
47prettyBlock :: Block -> Doc
48prettyBlock (BlockQuote blocks) =
48prettyBlock (BlockQuote blocks) =
49 "BlockQuote" $$ prettyList (map prettyBlock blocks)
49 "BlockQuote" $$ prettyList (map prettyBlock blocks)
50−prettyBlock (OrderedList attribs blockLists) =
50+prettyBlock (OrderedList attribs blockLists) =
51 "OrderedList" <> space <> text (show attribs) $$
51 "OrderedList" <> space <> text (show attribs) $$
52 (prettyList $ map (prettyList . map prettyBlock) blockLists)
52 (prettyList $ map (prettyList . map prettyBlock) blockLists)
53−prettyBlock (BulletList blockLists) =
53+prettyBlock (BulletList blockLists) =
54 "BulletList" $$
54 "BulletList" $$
55 (prettyList $ map (prettyList . map prettyBlock) blockLists)
55 (prettyList $ map (prettyList . map prettyBlock) blockLists)
56prettyBlock (DefinitionList items) = "DefinitionList" $$
56prettyBlock (DefinitionList items) = "DefinitionList" $$
57 (prettyList $ map deflistitem items)
57 (prettyList $ map deflistitem items)
58 where deflistitem (term, defs) = "(" <> text (show term) <> "," <> cr <>
58 where deflistitem (term, defs) = "(" <> text (show term) <> "," <> cr <>
59 nest 1 (prettyList $ map (prettyList . map prettyBlock) defs) <> ")"
59 nest 1 (prettyList $ map (prettyList . map prettyBlock) defs) <> ")"
60−prettyBlock (Table caption aligns widths header rows) =
60+prettyBlock (Table caption aligns widths header rows) =
61 "Table " <> text (show caption) <> " " <> text (show aligns) <> " " <>
61 "Table " <> text (show caption) <> " " <> text (show aligns) <> " " <>
62 text (show widths) $$
62 text (show widths) $$
63 prettyRow header $$
63 prettyRow header $$
src/Text/Pandoc/Writers/Org.hs+26−26
@@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20{- |
20{- |
21 Module : Text.Pandoc.Writers.Org
21 Module : Text.Pandoc.Writers.Org
22 Copyright : Copyright (C) 2010 Puneeth Chaganti
22 Copyright : Copyright (C) 2010 Puneeth Chaganti
23− License : GNU GPL, version 2 or above
23+ License : GNU GPL, version 2 or above
24
24
25 Maintainer : Puneeth Chaganti <punchagan@gmail.com>
25 Maintainer : Puneeth Chaganti <punchagan@gmail.com>
26 Stability : alpha
26 Stability : alpha
@@ -32,14 +32,14 @@ Org-Mode: <http://orgmode.org>
32-}
32-}
33module Text.Pandoc.Writers.Org ( writeOrg) where
33module Text.Pandoc.Writers.Org ( writeOrg) where
34import Text.Pandoc.Definition
34import Text.Pandoc.Definition
35−import Text.Pandoc.Shared
35+import Text.Pandoc.Shared
36import Text.Pandoc.Pretty
36import Text.Pandoc.Pretty
37import Text.Pandoc.Templates (renderTemplate)
37import Text.Pandoc.Templates (renderTemplate)
38import Data.List ( intersect, intersperse, transpose )
38import Data.List ( intersect, intersperse, transpose )
39import Control.Monad.State
39import Control.Monad.State
40import Control.Applicative ( (<$>) )
40import Control.Applicative ( (<$>) )
41
41
42−data WriterState =
42+data WriterState =
43 WriterState { stNotes :: [[Block]]
43 WriterState { stNotes :: [[Block]]
44 , stLinks :: Bool
44 , stLinks :: Bool
45 , stImages :: Bool
45 , stImages :: Bool
@@ -49,7 +49,7 @@ data WriterState =
49
49
50-- | Convert Pandoc to Org.
50-- | Convert Pandoc to Org.
51writeOrg :: WriterOptions -> Pandoc -> String
51writeOrg :: WriterOptions -> Pandoc -> String
52−writeOrg opts document =
52+writeOrg opts document =
53 let st = WriterState { stNotes = [], stLinks = False,
53 let st = WriterState { stNotes = [], stLinks = False,
54 stImages = False, stHasMath = False,
54 stImages = False, stHasMath = False,
55 stOptions = opts }
55 stOptions = opts }
@@ -82,8 +82,8 @@ pandocToOrg (Pandoc (Meta tit auth dat) blocks) = do
82
82
83-- | Return Org representation of notes.
83-- | Return Org representation of notes.
84notesToOrg :: [[Block]] -> State WriterState Doc
84notesToOrg :: [[Block]] -> State WriterState Doc
85−notesToOrg notes =
85+notesToOrg notes =
86− mapM (\(num, note) -> noteToOrg num note) (zip [1..] notes) >>=
86+ mapM (\(num, note) -> noteToOrg num note) (zip [1..] notes) >>=
87 return . vsep
87 return . vsep
88
88
89-- | Return Org representation of a note.
89-- | Return Org representation of a note.
@@ -106,11 +106,11 @@ titleToOrg :: [Inline] -> State WriterState Doc
106titleToOrg [] = return empty
106titleToOrg [] = return empty
107titleToOrg lst = do
107titleToOrg lst = do
108 contents <- inlineListToOrg lst
108 contents <- inlineListToOrg lst
109− return $ "#+TITLE: " <> contents
109+ return $ "#+TITLE: " <> contents
110
110
111−-- | Convert Pandoc block element to Org.
111+-- | Convert Pandoc block element to Org.
112blockToOrg :: Block -- ^ Block element
112blockToOrg :: Block -- ^ Block element
113− -> State WriterState Doc
113+ -> State WriterState Doc
114blockToOrg Null = return empty
114blockToOrg Null = return empty
115blockToOrg (Plain inlines) = inlineListToOrg inlines
115blockToOrg (Plain inlines) = inlineListToOrg inlines
116blockToOrg (Para [Image txt (src,tit)]) = do
116blockToOrg (Para [Image txt (src,tit)]) = do
@@ -120,7 +120,7 @@ blockToOrg (Para [Image txt (src,tit)]) = do
120blockToOrg (Para inlines) = do
120blockToOrg (Para inlines) = do
121 contents <- inlineListToOrg inlines
121 contents <- inlineListToOrg inlines
122 return $ contents <> blankline
122 return $ contents <> blankline
123−blockToOrg (RawBlock "html" str) =
123+blockToOrg (RawBlock "html" str) =
124 return $ blankline $$ "#+BEGIN_HTML" $$
124 return $ blankline $$ "#+BEGIN_HTML" $$
125 nest 2 (text str) $$ "#+END_HTML" $$ blankline
125 nest 2 (text str) $$ "#+END_HTML" $$ blankline
126blockToOrg (RawBlock f str) | f == "org" || f == "latex" || f == "tex" =
126blockToOrg (RawBlock f str) | f == "org" || f == "latex" || f == "tex" =
@@ -134,17 +134,17 @@ blockToOrg (Header level inlines) = do
134blockToOrg (CodeBlock (_,classes,_) str) = do
134blockToOrg (CodeBlock (_,classes,_) str) = do
135 opts <- stOptions <$> get
135 opts <- stOptions <$> get
136 let tabstop = writerTabStop opts
136 let tabstop = writerTabStop opts
137− let at = classes `intersect` ["asymptote", "C", "clojure", "css", "ditaa",
137+ let at = classes `intersect` ["asymptote", "C", "clojure", "css", "ditaa",
138− "dot", "emacs-lisp", "gnuplot", "haskell", "js", "latex",
138+ "dot", "emacs-lisp", "gnuplot", "haskell", "js", "latex",
139− "ledger", "lisp", "matlab", "mscgen", "ocaml", "octave",
139+ "ledger", "lisp", "matlab", "mscgen", "ocaml", "octave",
140− "oz", "perl", "plantuml", "python", "R", "ruby", "sass",
140+ "oz", "perl", "plantuml", "python", "R", "ruby", "sass",
141 "scheme", "screen", "sh", "sql", "sqlite"]
141 "scheme", "screen", "sh", "sql", "sqlite"]
142 let (beg, end) = case at of
142 let (beg, end) = case at of
143 [] -> ("#+BEGIN_EXAMPLE", "#+END_EXAMPLE")
143 [] -> ("#+BEGIN_EXAMPLE", "#+END_EXAMPLE")
144 (x:_) -> ("#+BEGIN_SRC " ++ x, "#+END_SRC")
144 (x:_) -> ("#+BEGIN_SRC " ++ x, "#+END_SRC")
145 return $ text beg $$ nest tabstop (text str) $$ text end $$ blankline
145 return $ text beg $$ nest tabstop (text str) $$ text end $$ blankline
146blockToOrg (BlockQuote blocks) = do
146blockToOrg (BlockQuote blocks) = do
147− contents <- blockListToOrg blocks
147+ contents <- blockListToOrg blocks
148 return $ blankline $$ "#+BEGIN_QUOTE" $$
148 return $ blankline $$ "#+BEGIN_QUOTE" $$
149 nest 2 contents $$ "#+END_QUOTE" $$ blankline
149 nest 2 contents $$ "#+END_QUOTE" $$ blankline
150blockToOrg (Table caption' _ _ headers rows) = do
150blockToOrg (Table caption' _ _ headers rows) = do
@@ -155,11 +155,11 @@ blockToOrg (Table caption' _ _ headers rows) = do
155 headers' <- mapM blockListToOrg headers
155 headers' <- mapM blockListToOrg headers
156 rawRows <- mapM (mapM blockListToOrg) rows
156 rawRows <- mapM (mapM blockListToOrg) rows
157 let numChars = maximum . map offset
157 let numChars = maximum . map offset
158− -- FIXME: width is not being used.
158+ -- FIXME: width is not being used.
159 let widthsInChars =
159 let widthsInChars =
160 map ((+2) . numChars) $ transpose (headers' : rawRows)
160 map ((+2) . numChars) $ transpose (headers' : rawRows)
161− -- FIXME: Org doesn't allow blocks with height more than 1.
161+ -- FIXME: Org doesn't allow blocks with height more than 1.
162− let hpipeBlocks blocks = hcat [beg, middle, end]
162+ let hpipeBlocks blocks = hcat [beg, middle, end]
163 where h = maximum (map height blocks)
163 where h = maximum (map height blocks)
164 sep' = lblock 3 $ vcat (map text $ replicate h " | ")
164 sep' = lblock 3 $ vcat (map text $ replicate h " | ")
165 beg = lblock 2 $ vcat (map text $ replicate h "| ")
165 beg = lblock 2 $ vcat (map text $ replicate h "| ")
@@ -170,7 +170,7 @@ blockToOrg (Table caption' _ _ headers rows) = do
170 rows' <- mapM (\row -> do cols <- mapM blockListToOrg row
170 rows' <- mapM (\row -> do cols <- mapM blockListToOrg row
171 return $ makeRow cols) rows
171 return $ makeRow cols) rows
172 let border ch = char '|' <> char ch <>
172 let border ch = char '|' <> char ch <>
173− (hcat $ intersperse (char ch <> char '+' <> char ch) $
173+ (hcat $ intersperse (char ch <> char '+' <> char ch) $
174 map (\l -> text $ replicate l ch) widthsInChars) <>
174 map (\l -> text $ replicate l ch) widthsInChars) <>
175 char ch <> char '|'
175 char ch <> char '|'
176 let body = vcat rows'
176 let body = vcat rows'
@@ -186,7 +186,7 @@ blockToOrg (OrderedList (start, _, delim) items) = do
186 let delim' = case delim of
186 let delim' = case delim of
187 TwoParens -> OneParen
187 TwoParens -> OneParen
188 x -> x
188 x -> x
189− let markers = take (length items) $ orderedListMarkers
189+ let markers = take (length items) $ orderedListMarkers
190 (start, Decimal, delim')
190 (start, Decimal, delim')
191 let maxMarkerLength = maximum $ map length markers
191 let maxMarkerLength = maximum $ map length markers
192 let markers' = map (\m -> let s = maxMarkerLength - length m
192 let markers' = map (\m -> let s = maxMarkerLength - length m
@@ -222,7 +222,7 @@ definitionListItemToOrg (label, defs) = do
222
222
223-- | Convert list of Pandoc block elements to Org.
223-- | Convert list of Pandoc block elements to Org.
224blockListToOrg :: [Block] -- ^ List of block elements
224blockListToOrg :: [Block] -- ^ List of block elements
225− -> State WriterState Doc
225+ -> State WriterState Doc
226blockListToOrg blocks = mapM blockToOrg blocks >>= return . vcat
226blockListToOrg blocks = mapM blockToOrg blocks >>= return . vcat
227
227
228-- | Convert list of Pandoc inline elements to Org.
228-- | Convert list of Pandoc inline elements to Org.
@@ -231,19 +231,19 @@ inlineListToOrg lst = mapM inlineToOrg lst >>= return . hcat
231
231
232-- | Convert Pandoc inline element to Org.
232-- | Convert Pandoc inline element to Org.
233inlineToOrg :: Inline -> State WriterState Doc
233inlineToOrg :: Inline -> State WriterState Doc
234−inlineToOrg (Emph lst) = do
234+inlineToOrg (Emph lst) = do
235 contents <- inlineListToOrg lst
235 contents <- inlineListToOrg lst
236 return $ "/" <> contents <> "/"
236 return $ "/" <> contents <> "/"
237inlineToOrg (Strong lst) = do
237inlineToOrg (Strong lst) = do
238 contents <- inlineListToOrg lst
238 contents <- inlineListToOrg lst
239 return $ "*" <> contents <> "*"
239 return $ "*" <> contents <> "*"
240−inlineToOrg (Strikeout lst) = do
240+inlineToOrg (Strikeout lst) = do
241 contents <- inlineListToOrg lst
241 contents <- inlineListToOrg lst
242 return $ "+" <> contents <> "+"
242 return $ "+" <> contents <> "+"
243−inlineToOrg (Superscript lst) = do
243+inlineToOrg (Superscript lst) = do
244 contents <- inlineListToOrg lst
244 contents <- inlineListToOrg lst
245 return $ "^{" <> contents <> "}"
245 return $ "^{" <> contents <> "}"
246−inlineToOrg (Subscript lst) = do
246+inlineToOrg (Subscript lst) = do
247 contents <- inlineListToOrg lst
247 contents <- inlineListToOrg lst
248 return $ "_{" <> contents <> "}"
248 return $ "_{" <> contents <> "}"
249inlineToOrg (SmallCaps lst) = inlineListToOrg lst
249inlineToOrg (SmallCaps lst) = inlineListToOrg lst
@@ -276,7 +276,7 @@ inlineToOrg (Link txt (src, _)) = do
276inlineToOrg (Image _ (source, _)) = do
276inlineToOrg (Image _ (source, _)) = do
277 modify $ \s -> s{ stImages = True }
277 modify $ \s -> s{ stImages = True }
278 return $ "[[" <> text source <> "]]"
278 return $ "[[" <> text source <> "]]"
279−inlineToOrg (Note contents) = do
279+inlineToOrg (Note contents) = do
280 -- add to notes in state
280 -- add to notes in state
281 notes <- get >>= (return . stNotes)
281 notes <- get >>= (return . stNotes)
282 modify $ \st -> st { stNotes = contents:notes }
282 modify $ \st -> st { stNotes = contents:notes }
src/Text/Pandoc/Writers/RST.hs+24−24
@@ -18,9 +18,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18-}
18-}
19
19
20{- |
20{- |
21− Module : Text.Pandoc.Writers.RST
21+ Module : Text.Pandoc.Writers.RST
22 Copyright : Copyright (C) 2006-2010 John MacFarlane
22 Copyright : Copyright (C) 2006-2010 John MacFarlane
23− License : GNU GPL, version 2 or above
23+ License : GNU GPL, version 2 or above
24
24
25 Maintainer : John MacFarlane <jgm@berkeley.edu>
25 Maintainer : John MacFarlane <jgm@berkeley.edu>
26 Stability : alpha
26 Stability : alpha
@@ -32,7 +32,7 @@ reStructuredText: <http://docutils.sourceforge.net/rst.html>
32-}
32-}
33module Text.Pandoc.Writers.RST ( writeRST) where
33module Text.Pandoc.Writers.RST ( writeRST) where
34import Text.Pandoc.Definition
34import Text.Pandoc.Definition
35−import Text.Pandoc.Shared
35+import Text.Pandoc.Shared
36import Text.Pandoc.Templates (renderTemplate)
36import Text.Pandoc.Templates (renderTemplate)
37import Data.List ( isPrefixOf, intersperse, transpose )
37import Data.List ( isPrefixOf, intersperse, transpose )
38import Text.Pandoc.Pretty
38import Text.Pandoc.Pretty
@@ -42,7 +42,7 @@ import Data.Char (isSpace)
42
42
43type Refs = [([Inline], Target)]
43type Refs = [([Inline], Target)]
44
44
45−data WriterState =
45+data WriterState =
46 WriterState { stNotes :: [[Block]]
46 WriterState { stNotes :: [[Block]]
47 , stLinks :: Refs
47 , stLinks :: Refs
48 , stImages :: Refs
48 , stImages :: Refs
@@ -52,7 +52,7 @@ data WriterState =
52
52
53-- | Convert Pandoc to RST.
53-- | Convert Pandoc to RST.
54writeRST :: WriterOptions -> Pandoc -> String
54writeRST :: WriterOptions -> Pandoc -> String
55−writeRST opts document =
55+writeRST opts document =
56 let st = WriterState { stNotes = [], stLinks = [],
56 let st = WriterState { stNotes = [], stLinks = [],
57 stImages = [], stHasMath = False,
57 stImages = [], stHasMath = False,
58 stOptions = opts }
58 stOptions = opts }
@@ -89,8 +89,8 @@ pandocToRST (Pandoc (Meta tit auth dat) blocks) = do
89refsToRST :: Refs -> State WriterState Doc
89refsToRST :: Refs -> State WriterState Doc
90refsToRST refs = mapM keyToRST refs >>= return . vcat
90refsToRST refs = mapM keyToRST refs >>= return . vcat
91
91
92−-- | Return RST representation of a reference key.
92+-- | Return RST representation of a reference key.
93−keyToRST :: ([Inline], (String, String))
93+keyToRST :: ([Inline], (String, String))
94 -> State WriterState Doc
94 -> State WriterState Doc
95keyToRST (label, (src, _)) = do
95keyToRST (label, (src, _)) = do
96 label' <- inlineListToRST label
96 label' <- inlineListToRST label
@@ -101,7 +101,7 @@ keyToRST (label, (src, _)) = do
101
101
102-- | Return RST representation of notes.
102-- | Return RST representation of notes.
103notesToRST :: [[Block]] -> State WriterState Doc
103notesToRST :: [[Block]] -> State WriterState Doc
104−notesToRST notes =
104+notesToRST notes =
105 mapM (\(num, note) -> noteToRST num note) (zip [1..] notes) >>=
105 mapM (\(num, note) -> noteToRST num note) (zip [1..] notes) >>=
106 return . vsep
106 return . vsep
107
107
@@ -116,8 +116,8 @@ noteToRST num note = do
116pictRefsToRST :: Refs -> State WriterState Doc
116pictRefsToRST :: Refs -> State WriterState Doc
117pictRefsToRST refs = mapM pictToRST refs >>= return . vcat
117pictRefsToRST refs = mapM pictToRST refs >>= return . vcat
118
118
119−-- | Return RST representation of a picture substitution reference.
119+-- | Return RST representation of a picture substitution reference.
120−pictToRST :: ([Inline], (String, String))
120+pictToRST :: ([Inline], (String, String))
121 -> State WriterState Doc
121 -> State WriterState Doc
122pictToRST (label, (src, _)) = do
122pictToRST (label, (src, _)) = do
123 label' <- inlineListToRST label
123 label' <- inlineListToRST label
@@ -135,9 +135,9 @@ titleToRST lst = do
135 let border = text (replicate titleLength '=')
135 let border = text (replicate titleLength '=')
136 return $ border $$ contents $$ border
136 return $ border $$ contents $$ border
137
137
138−-- | Convert Pandoc block element to RST.
138+-- | Convert Pandoc block element to RST.
139blockToRST :: Block -- ^ Block element
139blockToRST :: Block -- ^ Block element
140− -> State WriterState Doc
140+ -> State WriterState Doc
141blockToRST Null = return empty
141blockToRST Null = return empty
142blockToRST (Plain inlines) = inlineListToRST inlines
142blockToRST (Plain inlines) = inlineListToRST inlines
143blockToRST (Para [Image txt (src,tit)]) = do
143blockToRST (Para [Image txt (src,tit)]) = do
@@ -168,7 +168,7 @@ blockToRST (CodeBlock (_,classes,_) str) = do
168 else return $ "::" $+$ nest tabstop (text str) $$ blankline
168 else return $ "::" $+$ nest tabstop (text str) $$ blankline
169blockToRST (BlockQuote blocks) = do
169blockToRST (BlockQuote blocks) = do
170 tabstop <- get >>= (return . writerTabStop . stOptions)
170 tabstop <- get >>= (return . writerTabStop . stOptions)
171− contents <- blockListToRST blocks
171+ contents <- blockListToRST blocks
172 return $ (nest tabstop contents) <> blankline
172 return $ (nest tabstop contents) <> blankline
173blockToRST (Table caption _ widths headers rows) = do
173blockToRST (Table caption _ widths headers rows) = do
174 caption' <- inlineListToRST caption
174 caption' <- inlineListToRST caption
@@ -184,7 +184,7 @@ blockToRST (Table caption _ widths headers rows) = do
184 if isSimple
184 if isSimple
185 then map ((+2) . numChars) $ transpose (headers' : rawRows)
185 then map ((+2) . numChars) $ transpose (headers' : rawRows)
186 else map (floor . (fromIntegral (writerColumns opts) *)) widths
186 else map (floor . (fromIntegral (writerColumns opts) *)) widths
187− let hpipeBlocks blocks = hcat [beg, middle, end]
187+ let hpipeBlocks blocks = hcat [beg, middle, end]
188 where h = maximum (map height blocks)
188 where h = maximum (map height blocks)
189 sep' = lblock 3 $ vcat (map text $ replicate h " | ")
189 sep' = lblock 3 $ vcat (map text $ replicate h " | ")
190 beg = lblock 2 $ vcat (map text $ replicate h "| ")
190 beg = lblock 2 $ vcat (map text $ replicate h "| ")
@@ -195,7 +195,7 @@ blockToRST (Table caption _ widths headers rows) = do
195 rows' <- mapM (\row -> do cols <- mapM blockListToRST row
195 rows' <- mapM (\row -> do cols <- mapM blockListToRST row
196 return $ makeRow cols) rows
196 return $ makeRow cols) rows
197 let border ch = char '+' <> char ch <>
197 let border ch = char '+' <> char ch <>
198− (hcat $ intersperse (char ch <> char '+' <> char ch) $
198+ (hcat $ intersperse (char ch <> char '+' <> char ch) $
199 map (\l -> text $ replicate l ch) widthsInChars) <>
199 map (\l -> text $ replicate l ch) widthsInChars) <>
200 char ch <> char '+'
200 char ch <> char '+'
201 let body = vcat $ intersperse (border '-') rows'
201 let body = vcat $ intersperse (border '-') rows'
@@ -208,9 +208,9 @@ blockToRST (BulletList items) = do
208 -- ensure that sublists have preceding blank line
208 -- ensure that sublists have preceding blank line
209 return $ blankline $$ vcat contents $$ blankline
209 return $ blankline $$ vcat contents $$ blankline
210blockToRST (OrderedList (start, style', delim) items) = do
210blockToRST (OrderedList (start, style', delim) items) = do
211− let markers = if start == 1 && style' == DefaultStyle && delim == DefaultDelim
211+ let markers = if start == 1 && style' == DefaultStyle && delim == DefaultDelim
212 then take (length items) $ repeat "#."
212 then take (length items) $ repeat "#."
213− else take (length items) $ orderedListMarkers
213+ else take (length items) $ orderedListMarkers
214 (start, style', delim)
214 (start, style', delim)
215 let maxMarkerLength = maximum $ map length markers
215 let maxMarkerLength = maximum $ map length markers
216 let markers' = map (\m -> let s = maxMarkerLength - length m
216 let markers' = map (\m -> let s = maxMarkerLength - length m
@@ -249,7 +249,7 @@ definitionListItemToRST (label, defs) = do
249
249
250-- | Convert list of Pandoc block elements to RST.
250-- | Convert list of Pandoc block elements to RST.
251blockListToRST :: [Block] -- ^ List of block elements
251blockListToRST :: [Block] -- ^ List of block elements
252− -> State WriterState Doc
252+ -> State WriterState Doc
253blockListToRST blocks = mapM blockToRST blocks >>= return . vcat
253blockListToRST blocks = mapM blockToRST blocks >>= return . vcat
254
254
255-- | Convert list of Pandoc inline elements to RST.
255-- | Convert list of Pandoc inline elements to RST.
@@ -303,19 +303,19 @@ inlineListToRST lst = mapM inlineToRST (insertBS lst) >>= return . hcat
303
303
304-- | Convert Pandoc inline element to RST.
304-- | Convert Pandoc inline element to RST.
305inlineToRST :: Inline -> State WriterState Doc
305inlineToRST :: Inline -> State WriterState Doc
306−inlineToRST (Emph lst) = do
306+inlineToRST (Emph lst) = do
307 contents <- inlineListToRST lst
307 contents <- inlineListToRST lst
308 return $ "*" <> contents <> "*"
308 return $ "*" <> contents <> "*"
309inlineToRST (Strong lst) = do
309inlineToRST (Strong lst) = do
310 contents <- inlineListToRST lst
310 contents <- inlineListToRST lst
311 return $ "**" <> contents <> "**"
311 return $ "**" <> contents <> "**"
312−inlineToRST (Strikeout lst) = do
312+inlineToRST (Strikeout lst) = do
313 contents <- inlineListToRST lst
313 contents <- inlineListToRST lst
314 return $ "[STRIKEOUT:" <> contents <> "]"
314 return $ "[STRIKEOUT:" <> contents <> "]"
315−inlineToRST (Superscript lst) = do
315+inlineToRST (Superscript lst) = do
316 contents <- inlineListToRST lst
316 contents <- inlineListToRST lst
317 return $ ":sup:`" <> contents <> "`"
317 return $ ":sup:`" <> contents <> "`"
318−inlineToRST (Subscript lst) = do
318+inlineToRST (Subscript lst) = do
319 contents <- inlineListToRST lst
319 contents <- inlineListToRST lst
320 return $ ":sub:`" <> contents <> "`"
320 return $ ":sub:`" <> contents <> "`"
321inlineToRST (SmallCaps lst) = inlineListToRST lst
321inlineToRST (SmallCaps lst) = inlineListToRST lst
@@ -358,7 +358,7 @@ inlineToRST (Link txt (src, tit)) = do
358 else return $ "`" <> linktext <> " <" <> text src <> ">`_"
358 else return $ "`" <> linktext <> " <" <> text src <> ">`_"
359inlineToRST (Image alternate (source, tit)) = do
359inlineToRST (Image alternate (source, tit)) = do
360 pics <- get >>= return . stImages
360 pics <- get >>= return . stImages
361− let labelsUsed = map fst pics
361+ let labelsUsed = map fst pics
362 let txt = if null alternate || alternate == [Str ""] ||
362 let txt = if null alternate || alternate == [Str ""] ||
363 alternate `elem` labelsUsed
363 alternate `elem` labelsUsed
364 then [Str $ "image" ++ show (length pics)]
364 then [Str $ "image" ++ show (length pics)]
@@ -369,7 +369,7 @@ inlineToRST (Image alternate (source, tit)) = do
369 modify $ \st -> st { stImages = pics' }
369 modify $ \st -> st { stImages = pics' }
370 label <- inlineListToRST txt
370 label <- inlineListToRST txt
371 return $ "|" <> label <> "|"
371 return $ "|" <> label <> "|"
372−inlineToRST (Note contents) = do
372+inlineToRST (Note contents) = do
373 -- add to notes in state
373 -- add to notes in state
374 notes <- get >>= return . stNotes
374 notes <- get >>= return . stNotes
375 modify $ \st -> st { stNotes = contents:notes }
375 modify $ \st -> st { stNotes = contents:notes }
src/Text/Pandoc/Writers/RTF.hs+40−40
@@ -19,10 +19,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19{- |
19{- |
20 Module : Text.Pandoc.Writers.RTF
20 Module : Text.Pandoc.Writers.RTF
21 Copyright : Copyright (C) 2006-2010 John MacFarlane
21 Copyright : Copyright (C) 2006-2010 John MacFarlane
22− License : GNU GPL, version 2 or above
22+ License : GNU GPL, version 2 or above
23
23
24 Maintainer : John MacFarlane <jgm@berkeley.edu>
24 Maintainer : John MacFarlane <jgm@berkeley.edu>
25− Stability : alpha
25+ Stability : alpha
26 Portability : portable
26 Portability : portable
27
27
28Conversion of 'Pandoc' documents to RTF (rich text format).
28Conversion of 'Pandoc' documents to RTF (rich text format).
@@ -65,7 +65,7 @@ rtfEmbedImage x = return x
65
65
66-- | Convert Pandoc to a string in rich text format.
66-- | Convert Pandoc to a string in rich text format.
67writeRTF :: WriterOptions -> Pandoc -> String
67writeRTF :: WriterOptions -> Pandoc -> String
68−writeRTF options (Pandoc (Meta title authors date) blocks) =
68+writeRTF options (Pandoc (Meta title authors date) blocks) =
69 let titletext = inlineListToRTF title
69 let titletext = inlineListToRTF title
70 authorstext = map inlineListToRTF authors
70 authorstext = map inlineListToRTF authors
71 datetext = inlineListToRTF date
71 datetext = inlineListToRTF date
@@ -84,11 +84,11 @@ writeRTF options (Pandoc (Meta title authors date) blocks) =
84 else body
84 else body
85
85
86-- | Construct table of contents from list of header blocks.
86-- | Construct table of contents from list of header blocks.
87−tableOfContents :: [Block] -> String
87+tableOfContents :: [Block] -> String
88tableOfContents headers =
88tableOfContents headers =
89 let contentsTree = hierarchicalize headers
89 let contentsTree = hierarchicalize headers
90− in concatMap (blockToRTF 0 AlignDefault) $
90+ in concatMap (blockToRTF 0 AlignDefault) $
91− [Header 1 [Str "Contents"],
91+ [Header 1 [Str "Contents"],
92 BulletList (map elementToListItem contentsTree)]
92 BulletList (map elementToListItem contentsTree)]
93
93
94elementToListItem :: Element -> [Block]
94elementToListItem :: Element -> [Block]
@@ -102,7 +102,7 @@ elementToListItem (Sec _ _ _ sectext subsecs) = [Plain sectext] ++
102handleUnicode :: String -> String
102handleUnicode :: String -> String
103handleUnicode [] = []
103handleUnicode [] = []
104handleUnicode (c:cs) =
104handleUnicode (c:cs) =
105− if ord c > 127
105+ if ord c > 127
106 then '\\':'u':(show (ord c)) ++ "?" ++ handleUnicode cs
106 then '\\':'u':(show (ord c)) ++ "?" ++ handleUnicode cs
107 else c:(handleUnicode cs)
107 else c:(handleUnicode cs)
108
108
@@ -132,32 +132,32 @@ rtfParSpaced :: Int -- ^ space after (in twips)
132 -> Int -- ^ first line indent (relative to block) (in twips)
132 -> Int -- ^ first line indent (relative to block) (in twips)
133 -> Alignment -- ^ alignment
133 -> Alignment -- ^ alignment
134 -> String -- ^ string with content
134 -> String -- ^ string with content
135− -> String
135+ -> String
136−rtfParSpaced spaceAfter indent firstLineIndent alignment content =
136+rtfParSpaced spaceAfter indent firstLineIndent alignment content =
137 let alignString = case alignment of
137 let alignString = case alignment of
138 AlignLeft -> "\\ql "
138 AlignLeft -> "\\ql "
139 AlignRight -> "\\qr "
139 AlignRight -> "\\qr "
140 AlignCenter -> "\\qc "
140 AlignCenter -> "\\qc "
141 AlignDefault -> "\\ql "
141 AlignDefault -> "\\ql "
142 in "{\\pard " ++ alignString ++
142 in "{\\pard " ++ alignString ++
143− "\\f0 \\sa" ++ (show spaceAfter) ++ " \\li" ++ (show indent) ++
143+ "\\f0 \\sa" ++ (show spaceAfter) ++ " \\li" ++ (show indent) ++
144 " \\fi" ++ (show firstLineIndent) ++ " " ++ content ++ "\\par}\n"
144 " \\fi" ++ (show firstLineIndent) ++ " " ++ content ++ "\\par}\n"
145
145
146−-- | Default paragraph.
146+-- | Default paragraph.
147rtfPar :: Int -- ^ block indent (in twips)
147rtfPar :: Int -- ^ block indent (in twips)
148 -> Int -- ^ first line indent (relative to block) (in twips)
148 -> Int -- ^ first line indent (relative to block) (in twips)
149 -> Alignment -- ^ alignment
149 -> Alignment -- ^ alignment
150 -> String -- ^ string with content
150 -> String -- ^ string with content
151− -> String
151+ -> String
152−rtfPar = rtfParSpaced 180
152+rtfPar = rtfParSpaced 180
153
153
154-- | Compact paragraph (e.g. for compact list items).
154-- | Compact paragraph (e.g. for compact list items).
155rtfCompact :: Int -- ^ block indent (in twips)
155rtfCompact :: Int -- ^ block indent (in twips)
156 -> Int -- ^ first line indent (relative to block) (in twips)
156 -> Int -- ^ first line indent (relative to block) (in twips)
157 -> Alignment -- ^ alignment
157 -> Alignment -- ^ alignment
158 -> String -- ^ string with content
158 -> String -- ^ string with content
159− -> String
159+ -> String
160−rtfCompact = rtfParSpaced 0
160+rtfCompact = rtfParSpaced 0
161
161
162-- number of twips to indent
162-- number of twips to indent
163indentIncrement :: Int
163indentIncrement :: Int
@@ -174,7 +174,7 @@ bulletMarker indent = case indent `mod` 720 of
174
174
175-- | Returns appropriate (list of) ordered list markers for indent level.
175-- | Returns appropriate (list of) ordered list markers for indent level.
176orderedMarkers :: Int -> ListAttributes -> [String]
176orderedMarkers :: Int -> ListAttributes -> [String]
177−orderedMarkers indent (start, style, delim) =
177+orderedMarkers indent (start, style, delim) =
178 if style == DefaultStyle && delim == DefaultDelim
178 if style == DefaultStyle && delim == DefaultDelim
179 then case indent `mod` 720 of
179 then case indent `mod` 720 of
180 0 -> orderedListMarkers (start, Decimal, Period)
180 0 -> orderedListMarkers (start, Decimal, Period)
@@ -187,30 +187,30 @@ blockToRTF :: Int -- ^ indent level
187 -> Block -- ^ block to convert
187 -> Block -- ^ block to convert
188 -> String
188 -> String
189blockToRTF _ _ Null = ""
189blockToRTF _ _ Null = ""
190−blockToRTF indent alignment (Plain lst) =
190+blockToRTF indent alignment (Plain lst) =
191 rtfCompact indent 0 alignment $ inlineListToRTF lst
191 rtfCompact indent 0 alignment $ inlineListToRTF lst
192−blockToRTF indent alignment (Para lst) =
192+blockToRTF indent alignment (Para lst) =
193 rtfPar indent 0 alignment $ inlineListToRTF lst
193 rtfPar indent 0 alignment $ inlineListToRTF lst
194−blockToRTF indent alignment (BlockQuote lst) =
194+blockToRTF indent alignment (BlockQuote lst) =
195− concatMap (blockToRTF (indent + indentIncrement) alignment) lst
195+ concatMap (blockToRTF (indent + indentIncrement) alignment) lst
196blockToRTF indent _ (CodeBlock _ str) =
196blockToRTF indent _ (CodeBlock _ str) =
197 rtfPar indent 0 AlignLeft ("\\f1 " ++ (codeStringToRTF str))
197 rtfPar indent 0 AlignLeft ("\\f1 " ++ (codeStringToRTF str))
198blockToRTF _ _ (RawBlock "rtf" str) = str
198blockToRTF _ _ (RawBlock "rtf" str) = str
199blockToRTF _ _ (RawBlock _ _) = ""
199blockToRTF _ _ (RawBlock _ _) = ""
200−blockToRTF indent alignment (BulletList lst) = spaceAtEnd $
200+blockToRTF indent alignment (BulletList lst) = spaceAtEnd $
201 concatMap (listItemToRTF alignment indent (bulletMarker indent)) lst
201 concatMap (listItemToRTF alignment indent (bulletMarker indent)) lst
202−blockToRTF indent alignment (OrderedList attribs lst) = spaceAtEnd $ concat $
202+blockToRTF indent alignment (OrderedList attribs lst) = spaceAtEnd $ concat $
203 zipWith (listItemToRTF alignment indent) (orderedMarkers indent attribs) lst
203 zipWith (listItemToRTF alignment indent) (orderedMarkers indent attribs) lst
204−blockToRTF indent alignment (DefinitionList lst) = spaceAtEnd $
204+blockToRTF indent alignment (DefinitionList lst) = spaceAtEnd $
205 concatMap (definitionListItemToRTF alignment indent) lst
205 concatMap (definitionListItemToRTF alignment indent) lst
206−blockToRTF indent _ HorizontalRule =
206+blockToRTF indent _ HorizontalRule =
207 rtfPar indent 0 AlignCenter "\\emdash\\emdash\\emdash\\emdash\\emdash"
207 rtfPar indent 0 AlignCenter "\\emdash\\emdash\\emdash\\emdash\\emdash"
208blockToRTF indent alignment (Header level lst) = rtfPar indent 0 alignment $
208blockToRTF indent alignment (Header level lst) = rtfPar indent 0 alignment $
209 "\\b \\fs" ++ (show (40 - (level * 4))) ++ " " ++ inlineListToRTF lst
209 "\\b \\fs" ++ (show (40 - (level * 4))) ++ " " ++ inlineListToRTF lst
210−blockToRTF indent alignment (Table caption aligns sizes headers rows) =
210+blockToRTF indent alignment (Table caption aligns sizes headers rows) =
211 (if all null headers
211 (if all null headers
212 then ""
212 then ""
213− else tableRowToRTF True indent aligns sizes headers) ++
213+ else tableRowToRTF True indent aligns sizes headers) ++
214 concatMap (tableRowToRTF False indent aligns sizes) rows ++
214 concatMap (tableRowToRTF False indent aligns sizes) rows ++
215 rtfPar indent 0 alignment (inlineListToRTF caption)
215 rtfPar indent 0 alignment (inlineListToRTF caption)
216
216
@@ -232,7 +232,7 @@ tableRowToRTF header indent aligns sizes' cols =
232 end = "}\n\\intbl\\row}\n"
232 end = "}\n\\intbl\\row}\n"
233 in start ++ columns ++ end
233 in start ++ columns ++ end
234
234
235−tableItemToRTF :: Int -> Alignment -> [Block] -> String
235+tableItemToRTF :: Int -> Alignment -> [Block] -> String
236tableItemToRTF indent alignment item =
236tableItemToRTF indent alignment item =
237 let contents = concatMap (blockToRTF indent alignment) item
237 let contents = concatMap (blockToRTF indent alignment) item
238 in "{\\intbl " ++ contents ++ "\\cell}\n"
238 in "{\\intbl " ++ contents ++ "\\cell}\n"
@@ -240,7 +240,7 @@ tableItemToRTF indent alignment item =
240-- | Ensure that there's the same amount of space after compact
240-- | Ensure that there's the same amount of space after compact
241-- lists as after regular lists.
241-- lists as after regular lists.
242spaceAtEnd :: String -> String
242spaceAtEnd :: String -> String
243−spaceAtEnd str =
243+spaceAtEnd str =
244 if isSuffixOf "\\par}\n" str
244 if isSuffixOf "\\par}\n" str
245 then (take ((length str) - 6) str) ++ "\\sa180\\par}\n"
245 then (take ((length str) - 6) str) ++ "\\sa180\\par}\n"
246 else str
246 else str
@@ -251,10 +251,10 @@ listItemToRTF :: Alignment -- ^ alignment
251 -> String -- ^ list start marker
251 -> String -- ^ list start marker
252 -> [Block] -- ^ list item (list of blocks)
252 -> [Block] -- ^ list item (list of blocks)
253 -> [Char]
253 -> [Char]
254−listItemToRTF alignment indent marker [] =
254+listItemToRTF alignment indent marker [] =
255− rtfCompact (indent + listIncrement) (0 - listIncrement) alignment
255+ rtfCompact (indent + listIncrement) (0 - listIncrement) alignment
256− (marker ++ "\\tx" ++ (show listIncrement) ++ "\\tab ")
256+ (marker ++ "\\tx" ++ (show listIncrement) ++ "\\tab ")
257−listItemToRTF alignment indent marker list =
257+listItemToRTF alignment indent marker list =
258 let (first:rest) = map (blockToRTF (indent + listIncrement) alignment) list
258 let (first:rest) = map (blockToRTF (indent + listIncrement) alignment) list
259 listMarker = "\\fi" ++ show (0 - listIncrement) ++ " " ++ marker ++ "\\tx" ++
259 listMarker = "\\fi" ++ show (0 - listIncrement) ++ " " ++ marker ++ "\\tx" ++
260 show listIncrement ++ "\\tab"
260 show listIncrement ++ "\\tab"
@@ -277,7 +277,7 @@ definitionListItemToRTF alignment indent (label, defs) =
277 let labelText = blockToRTF indent alignment (Plain label)
277 let labelText = blockToRTF indent alignment (Plain label)
278 itemsText = concatMap (blockToRTF (indent + listIncrement) alignment) $
278 itemsText = concatMap (blockToRTF (indent + listIncrement) alignment) $
279 concat defs
279 concat defs
280− in labelText ++ itemsText
280+ in labelText ++ itemsText
281
281
282-- | Convert list of inline items to RTF.
282-- | Convert list of inline items to RTF.
283inlineListToRTF :: [Inline] -- ^ list of inlines to convert
283inlineListToRTF :: [Inline] -- ^ list of inlines to convert
@@ -293,9 +293,9 @@ inlineToRTF (Strikeout lst) = "{\\strike " ++ (inlineListToRTF lst) ++ "}"
293inlineToRTF (Superscript lst) = "{\\super " ++ (inlineListToRTF lst) ++ "}"
293inlineToRTF (Superscript lst) = "{\\super " ++ (inlineListToRTF lst) ++ "}"
294inlineToRTF (Subscript lst) = "{\\sub " ++ (inlineListToRTF lst) ++ "}"
294inlineToRTF (Subscript lst) = "{\\sub " ++ (inlineListToRTF lst) ++ "}"
295inlineToRTF (SmallCaps lst) = "{\\scaps " ++ (inlineListToRTF lst) ++ "}"
295inlineToRTF (SmallCaps lst) = "{\\scaps " ++ (inlineListToRTF lst) ++ "}"
296−inlineToRTF (Quoted SingleQuote lst) =
296+inlineToRTF (Quoted SingleQuote lst) =
297 "\\u8216'" ++ (inlineListToRTF lst) ++ "\\u8217'"
297 "\\u8216'" ++ (inlineListToRTF lst) ++ "\\u8217'"
298−inlineToRTF (Quoted DoubleQuote lst) =
298+inlineToRTF (Quoted DoubleQuote lst) =
299 "\\u8220\"" ++ (inlineListToRTF lst) ++ "\\u8221\""
299 "\\u8220\"" ++ (inlineListToRTF lst) ++ "\\u8221\""
300inlineToRTF (Code _ str) = "{\\f1 " ++ (codeStringToRTF str) ++ "}"
300inlineToRTF (Code _ str) = "{\\f1 " ++ (codeStringToRTF str) ++ "}"
301inlineToRTF (Str str) = stringToRTF str
301inlineToRTF (Str str) = stringToRTF str
@@ -305,11 +305,11 @@ inlineToRTF (RawInline "rtf" str) = str
305inlineToRTF (RawInline _ _) = ""
305inlineToRTF (RawInline _ _) = ""
306inlineToRTF (LineBreak) = "\\line "
306inlineToRTF (LineBreak) = "\\line "
307inlineToRTF Space = " "
307inlineToRTF Space = " "
308−inlineToRTF (Link text (src, _)) =
308+inlineToRTF (Link text (src, _)) =
309− "{\\field{\\*\\fldinst{HYPERLINK \"" ++ (codeStringToRTF src) ++
309+ "{\\field{\\*\\fldinst{HYPERLINK \"" ++ (codeStringToRTF src) ++
310 "\"}}{\\fldrslt{\\ul\n" ++ (inlineListToRTF text) ++ "\n}}}\n"
310 "\"}}{\\fldrslt{\\ul\n" ++ (inlineListToRTF text) ++ "\n}}}\n"
311−inlineToRTF (Image _ (source, _)) =
311+inlineToRTF (Image _ (source, _)) =
312− "{\\cf1 [image: " ++ source ++ "]\\cf0}"
312+ "{\\cf1 [image: " ++ source ++ "]\\cf0}"
313inlineToRTF (Note contents) =
313inlineToRTF (Note contents) =
314− "{\\super\\chftn}{\\*\\footnote\\chftn\\~\\plain\\pard " ++
314+ "{\\super\\chftn}{\\*\\footnote\\chftn\\~\\plain\\pard " ++
315 (concatMap (blockToRTF 0 AlignDefault) contents) ++ "}"
315 (concatMap (blockToRTF 0 AlignDefault) contents) ++ "}"
src/Text/Pandoc/Writers/Texinfo.hs+9−9
@@ -19,10 +19,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19{- |
19{- |
20 Module : Text.Pandoc.Writers.Texinfo
20 Module : Text.Pandoc.Writers.Texinfo
21 Copyright : Copyright (C) 2008-2010 John MacFarlane and Peter Wang
21 Copyright : Copyright (C) 2008-2010 John MacFarlane and Peter Wang
22− License : GNU GPL, version 2 or above
22+ License : GNU GPL, version 2 or above
23
23
24 Maintainer : John MacFarlane <jgm@berkeley.edu>
24 Maintainer : John MacFarlane <jgm@berkeley.edu>
25− Stability : alpha
25+ Stability : alpha
26 Portability : portable
26 Portability : portable
27
27
28Conversion of 'Pandoc' format into Texinfo.
28Conversion of 'Pandoc' format into Texinfo.
@@ -40,7 +40,7 @@ import Text.Pandoc.Pretty
40import Network.URI ( isAbsoluteURI, unEscapeString )
40import Network.URI ( isAbsoluteURI, unEscapeString )
41import System.FilePath
41import System.FilePath
42
42
43−data WriterState =
43+data WriterState =
44 WriterState { stStrikeout :: Bool -- document contains strikeout
44 WriterState { stStrikeout :: Bool -- document contains strikeout
45 , stSuperscript :: Bool -- document contains superscript
45 , stSuperscript :: Bool -- document contains superscript
46 , stSubscript :: Bool -- document contains subscript
46 , stSubscript :: Bool -- document contains subscript
@@ -53,8 +53,8 @@ data WriterState =
53
53
54-- | Convert Pandoc to Texinfo.
54-- | Convert Pandoc to Texinfo.
55writeTexinfo :: WriterOptions -> Pandoc -> String
55writeTexinfo :: WriterOptions -> Pandoc -> String
56−writeTexinfo options document =
56+writeTexinfo options document =
57− evalState (pandocToTexinfo options $ wrapTop document) $
57+ evalState (pandocToTexinfo options $ wrapTop document) $
58 WriterState { stStrikeout = False, stSuperscript = False, stSubscript = False }
58 WriterState { stStrikeout = False, stSuperscript = False, stSubscript = False }
59
59
60-- | Add a "Top" node around the document, needed by Texinfo.
60-- | Add a "Top" node around the document, needed by Texinfo.
@@ -217,7 +217,7 @@ blockToTexinfo (Table caption aligns widths heads rows) = do
217 else return $ "@columnfractions " ++ concatMap (printf "%.2f ") widths
217 else return $ "@columnfractions " ++ concatMap (printf "%.2f ") widths
218 let tableBody = text ("@multitable " ++ colDescriptors) $$
218 let tableBody = text ("@multitable " ++ colDescriptors) $$
219 headers $$
219 headers $$
220− vcat rowsText $$
220+ vcat rowsText $$
221 text "@end multitable"
221 text "@end multitable"
222 return $ if isEmpty captionText
222 return $ if isEmpty captionText
223 then tableBody <> blankline
223 then tableBody <> blankline
@@ -241,7 +241,7 @@ tableAnyRowToTexinfo :: String
241 -> [[Block]]
241 -> [[Block]]
242 -> State WriterState Doc
242 -> State WriterState Doc
243tableAnyRowToTexinfo itemtype aligns cols =
243tableAnyRowToTexinfo itemtype aligns cols =
244− zipWithM alignedBlock aligns cols >>=
244+ zipWithM alignedBlock aligns cols >>=
245 return . (text itemtype $$) . foldl (\row item -> row $$
245 return . (text itemtype $$) . foldl (\row item -> row $$
246 (if isEmpty row then empty else text " @tab ") <> item) empty
246 (if isEmpty row then empty else text " @tab ") <> item) empty
247
247
@@ -358,8 +358,8 @@ inlineToTexinfo :: Inline -- ^ Inline to convert
358inlineToTexinfo (Emph lst) =
358inlineToTexinfo (Emph lst) =
359 inlineListToTexinfo lst >>= return . inCmd "emph"
359 inlineListToTexinfo lst >>= return . inCmd "emph"
360
360
361−inlineToTexinfo (Strong lst) =
361+inlineToTexinfo (Strong lst) =
362− inlineListToTexinfo lst >>= return . inCmd "strong"
362+ inlineListToTexinfo lst >>= return . inCmd "strong"
363
363
364inlineToTexinfo (Strikeout lst) = do
364inlineToTexinfo (Strikeout lst) = do
365 modify $ \st -> st{ stStrikeout = True }
365 modify $ \st -> st{ stStrikeout = True }
src/Text/Pandoc/Writers/Textile.hs+15−15
@@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19{- |
19{- |
20 Module : Text.Pandoc.Writers.Textile
20 Module : Text.Pandoc.Writers.Textile
21 Copyright : Copyright (C) 2010 John MacFarlane
21 Copyright : Copyright (C) 2010 John MacFarlane
22− License : GNU GPL, version 2 or above
22+ License : GNU GPL, version 2 or above
23
23
24 Maintainer : John MacFarlane <jgm@berkeley.edu>
24 Maintainer : John MacFarlane <jgm@berkeley.edu>
25 Stability : alpha
25 Stability : alpha
@@ -31,7 +31,7 @@ Textile: <http://thresholdstate.com/articles/4312/the-textile-reference-manual>
31-}
31-}
32module Text.Pandoc.Writers.Textile ( writeTextile ) where
32module Text.Pandoc.Writers.Textile ( writeTextile ) where
33import Text.Pandoc.Definition
33import Text.Pandoc.Definition
34−import Text.Pandoc.Shared
34+import Text.Pandoc.Shared
35import Text.Pandoc.Templates (renderTemplate)
35import Text.Pandoc.Templates (renderTemplate)
36import Text.Pandoc.XML ( escapeStringForXML )
36import Text.Pandoc.XML ( escapeStringForXML )
37import Data.List ( intercalate )
37import Data.List ( intercalate )
@@ -46,9 +46,9 @@ data WriterState = WriterState {
46
46
47-- | Convert Pandoc to Textile.
47-- | Convert Pandoc to Textile.
48writeTextile :: WriterOptions -> Pandoc -> String
48writeTextile :: WriterOptions -> Pandoc -> String
49−writeTextile opts document =
49+writeTextile opts document =
50− evalState (pandocToTextile opts document)
50+ evalState (pandocToTextile opts document)
51− (WriterState { stNotes = [], stListLevel = [], stUseTags = False })
51+ (WriterState { stNotes = [], stListLevel = [], stUseTags = False })
52
52
53-- | Return Textile representation of document.
53-- | Return Textile representation of document.
54pandocToTextile :: WriterOptions -> Pandoc -> State WriterState String
54pandocToTextile :: WriterOptions -> Pandoc -> State WriterState String
@@ -90,14 +90,14 @@ escapeCharForTextile x = case x of
90escapeStringForTextile :: String -> String
90escapeStringForTextile :: String -> String
91escapeStringForTextile = concatMap escapeCharForTextile
91escapeStringForTextile = concatMap escapeCharForTextile
92
92
93−-- | Convert Pandoc block element to Textile.
93+-- | Convert Pandoc block element to Textile.
94blockToTextile :: WriterOptions -- ^ Options
94blockToTextile :: WriterOptions -- ^ Options
95 -> Block -- ^ Block element
95 -> Block -- ^ Block element
96− -> State WriterState String
96+ -> State WriterState String
97
97
98blockToTextile _ Null = return ""
98blockToTextile _ Null = return ""
99
99
100−blockToTextile opts (Plain inlines) =
100+blockToTextile opts (Plain inlines) =
101 inlineListToTextile opts inlines
101 inlineListToTextile opts inlines
102
102
103blockToTextile opts (Para [Image txt (src,tit)]) = do
103blockToTextile opts (Para [Image txt (src,tit)]) = do
@@ -236,7 +236,7 @@ listItemToTextile opts items = do
236
236
237-- | Convert definition list item (label, list of blocks) to Textile.
237-- | Convert definition list item (label, list of blocks) to Textile.
238definitionListItemToTextile :: WriterOptions
238definitionListItemToTextile :: WriterOptions
239− -> ([Inline],[[Block]])
239+ -> ([Inline],[[Block]])
240 -> State WriterState String
240 -> State WriterState String
241definitionListItemToTextile opts (label, items) = do
241definitionListItemToTextile opts (label, items) = do
242 labelText <- inlineListToTextile opts label
242 labelText <- inlineListToTextile opts label
@@ -294,8 +294,8 @@ tableRowToTextile opts alignStrings rownum cols' = do
294 0 -> "header"
294 0 -> "header"
295 x | x `rem` 2 == 1 -> "odd"
295 x | x `rem` 2 == 1 -> "odd"
296 _ -> "even"
296 _ -> "even"
297− cols'' <- sequence $ zipWith
297+ cols'' <- sequence $ zipWith
298− (\alignment item -> tableItemToTextile opts celltype alignment item)
298+ (\alignment item -> tableItemToTextile opts celltype alignment item)
299 alignStrings cols'
299 alignStrings cols'
300 return $ "<tr class=\"" ++ rowclass ++ "\">\n" ++ unlines cols'' ++ "</tr>"
300 return $ "<tr class=\"" ++ rowclass ++ "\">\n" ++ unlines cols'' ++ "</tr>"
301
301
@@ -320,7 +320,7 @@ tableItemToTextile opts celltype align' item = do
320-- | Convert list of Pandoc block elements to Textile.
320-- | Convert list of Pandoc block elements to Textile.
321blockListToTextile :: WriterOptions -- ^ Options
321blockListToTextile :: WriterOptions -- ^ Options
322 -> [Block] -- ^ List of block elements
322 -> [Block] -- ^ List of block elements
323− -> State WriterState String
323+ -> State WriterState String
324blockListToTextile opts blocks =
324blockListToTextile opts blocks =
325 mapM (blockToTextile opts) blocks >>= return . vcat
325 mapM (blockToTextile opts) blocks >>= return . vcat
326
326
@@ -332,11 +332,11 @@ inlineListToTextile opts lst =
332-- | Convert Pandoc inline element to Textile.
332-- | Convert Pandoc inline element to Textile.
333inlineToTextile :: WriterOptions -> Inline -> State WriterState String
333inlineToTextile :: WriterOptions -> Inline -> State WriterState String
334
334
335−inlineToTextile opts (Emph lst) = do
335+inlineToTextile opts (Emph lst) = do
336 contents <- inlineListToTextile opts lst
336 contents <- inlineListToTextile opts lst
337 return $ if '_' `elem` contents
337 return $ if '_' `elem` contents
338 then "<em>" ++ contents ++ "</em>"
338 then "<em>" ++ contents ++ "</em>"
339− else "_" ++ contents ++ "_"
339+ else "_" ++ contents ++ "_"
340
340
341inlineToTextile opts (Strong lst) = do
341inlineToTextile opts (Strong lst) = do
342 contents <- inlineListToTextile opts lst
342 contents <- inlineListToTextile opts lst
@@ -377,7 +377,7 @@ inlineToTextile opts (Cite _ lst) = inlineListToTextile opts lst
377inlineToTextile _ (Code _ str) =
377inlineToTextile _ (Code _ str) =
378 return $ if '@' `elem` str
378 return $ if '@' `elem` str
379 then "<tt>" ++ escapeStringForXML str ++ "</tt>"
379 then "<tt>" ++ escapeStringForXML str ++ "</tt>"
380− else "@" ++ str ++ "@"
380+ else "@" ++ str ++ "@"
381
381
382inlineToTextile _ (Str str) = return $ escapeStringForTextile str
382inlineToTextile _ (Str str) = return $ escapeStringForTextile str
383
383