git.iko.soy/typeable/pandoc
on master help sign in
Use walk, walkM in place of bottomUp, bottomUpM when possible.
02a125dJohn MacFarlane
src/Text/Pandoc/PDF.hs+2−2
@@ -44,7 +44,7 @@ import Data.List (isInfixOf)
44import qualified Data.ByteString.Base64 as B64
44import qualified Data.ByteString.Base64 as B64
45import qualified Text.Pandoc.UTF8 as UTF8
45import qualified Text.Pandoc.UTF8 as UTF8
46import Text.Pandoc.Definition
46import Text.Pandoc.Definition
47−import Text.Pandoc.Generic (bottomUpM)
47+import Text.Pandoc.Walk (walkM)
48import Text.Pandoc.Shared (fetchItem, warn)
48import Text.Pandoc.Shared (fetchItem, warn)
49import Text.Pandoc.Options (WriterOptions(..))
49import Text.Pandoc.Options (WriterOptions(..))
50import Text.Pandoc.MIME (extensionFromMimeType)
50import Text.Pandoc.MIME (extensionFromMimeType)
@@ -73,7 +73,7 @@ handleImages :: String -- ^ source directory/base URL
73 -> FilePath -- ^ temp dir to store images
73 -> FilePath -- ^ temp dir to store images
74 -> Pandoc -- ^ document
74 -> Pandoc -- ^ document
75 -> IO Pandoc
75 -> IO Pandoc
76−handleImages baseURL tmpdir = bottomUpM (handleImage' baseURL tmpdir)
76+handleImages baseURL tmpdir = walkM (handleImage' baseURL tmpdir)
77
77
78handleImage' :: String
78handleImage' :: String
79 -> FilePath
79 -> FilePath
src/Text/Pandoc/Readers/LaTeX.hs+2−2
@@ -35,7 +35,7 @@ module Text.Pandoc.Readers.LaTeX ( readLaTeX,
35 ) where
35 ) where
36
36
37import Text.Pandoc.Definition
37import Text.Pandoc.Definition
38−import Text.Pandoc.Generic
38+import Text.Pandoc.Walk
39import Text.Pandoc.Shared
39import Text.Pandoc.Shared
40import Text.Pandoc.Options
40import Text.Pandoc.Options
41import Text.Pandoc.Biblio (processBiblio)
41import Text.Pandoc.Biblio (processBiblio)
@@ -815,7 +815,7 @@ keyvals :: LP [(String, String)]
815keyvals = try $ char '[' *> manyTill keyval (char ']')
815keyvals = try $ char '[' *> manyTill keyval (char ']')
816
816
817alltt :: String -> LP Blocks
817alltt :: String -> LP Blocks
818−alltt t = bottomUp strToCode <$> parseFromString blocks
818+alltt t = walk strToCode <$> parseFromString blocks
819 (substitute " " "\\ " $ substitute "%" "\\%" $
819 (substitute " " "\\ " $ substitute "%" "\\%" $
820 concat $ intersperse "\\\\\n" $ lines t)
820 concat $ intersperse "\\\\\n" $ lines t)
821 where strToCode (Str s) = Code nullAttr s
821 where strToCode (Str s) = Code nullAttr s
src/Text/Pandoc/Readers/MediaWiki.hs+2−2
@@ -42,7 +42,7 @@ import Text.Pandoc.Options
42import Text.Pandoc.Readers.HTML ( htmlTag, isBlockTag, isCommentTag )
42import Text.Pandoc.Readers.HTML ( htmlTag, isBlockTag, isCommentTag )
43import Text.Pandoc.XML ( fromEntities )
43import Text.Pandoc.XML ( fromEntities )
44import Text.Pandoc.Parsing hiding ( nested )
44import Text.Pandoc.Parsing hiding ( nested )
45−import Text.Pandoc.Generic ( bottomUp )
45+import Text.Pandoc.Walk ( walk )
46import Text.Pandoc.Shared ( stripTrailingNewlines, safeRead )
46import Text.Pandoc.Shared ( stripTrailingNewlines, safeRead )
47import Data.Monoid (mconcat, mempty)
47import Data.Monoid (mconcat, mempty)
48import Control.Applicative ((<$>), (<*), (*>), (<$))
48import Control.Applicative ((<$>), (<*), (*>), (<$))
@@ -342,7 +342,7 @@ preformatted = try $ do
342 spacesStr _ = False
342 spacesStr _ = False
343 if F.all spacesStr contents
343 if F.all spacesStr contents
344 then return mempty
344 then return mempty
345− else return $ B.para $ bottomUp strToCode contents
345+ else return $ B.para $ walk strToCode contents
346
346
347header :: MWParser Blocks
347header :: MWParser Blocks
348header = try $ do
348header = try $ do
src/Text/Pandoc/Shared.hs+1−1
@@ -518,7 +518,7 @@ isHeaderBlock _ = False
518
518
519-- | Shift header levels up or down.
519-- | Shift header levels up or down.
520headerShift :: Int -> Pandoc -> Pandoc
520headerShift :: Int -> Pandoc -> Pandoc
521−headerShift n = bottomUp shift
521+headerShift n = walk shift
522 where shift :: Block -> Block
522 where shift :: Block -> Block
523 shift (Header level attr inner) = Header (level + n) attr inner
523 shift (Header level attr inner) = Header (level + n) attr inner
524 shift x = x
524 shift x = x
src/Text/Pandoc/Writers/Docx.hs+6−5
@@ -45,6 +45,7 @@ import Text.Pandoc.Shared hiding (Element)
45import Text.Pandoc.Options
45import Text.Pandoc.Options
46import Text.Pandoc.Readers.TeXMath
46import Text.Pandoc.Readers.TeXMath
47import Text.Pandoc.Highlighting ( highlight )
47import Text.Pandoc.Highlighting ( highlight )
48+import Text.Pandoc.Walk
48import Text.Highlighting.Kate.Types ()
49import Text.Highlighting.Kate.Types ()
49import Text.XML.Light
50import Text.XML.Light
50import Text.TeXMath
51import Text.TeXMath
@@ -108,7 +109,7 @@ writeDocx :: WriterOptions -- ^ Writer options
108 -> IO BL.ByteString
109 -> IO BL.ByteString
109writeDocx opts doc@(Pandoc meta _) = do
110writeDocx opts doc@(Pandoc meta _) = do
110 let datadir = writerUserDataDir opts
111 let datadir = writerUserDataDir opts
111− let doc' = bottomUp (concatMap fixDisplayMath) doc
112+ let doc' = walk fixDisplayMath doc
112 refArchive <- liftM (toArchive . toLazy) $
113 refArchive <- liftM (toArchive . toLazy) $
113 case writerReferenceDocx opts of
114 case writerReferenceDocx opts of
114 Just f -> B.readFile f
115 Just f -> B.readFile f
@@ -810,17 +811,17 @@ stripLeadingTrailingSpace = go . reverse . go . reverse
810 where go (Space:xs) = xs
811 where go (Space:xs) = xs
811 go xs = xs
812 go xs = xs
812
813
813−fixDisplayMath :: Block -> [Block]
814+fixDisplayMath :: Block -> Block
814fixDisplayMath (Plain lst)
815fixDisplayMath (Plain lst)
815 | any isDisplayMath lst && not (all isDisplayMath lst) =
816 | any isDisplayMath lst && not (all isDisplayMath lst) =
816 -- chop into several paragraphs so each displaymath is its own
817 -- chop into several paragraphs so each displaymath is its own
817− map (Plain . stripLeadingTrailingSpace) $
818+ Div ("",["math"],[]) $ map (Plain . stripLeadingTrailingSpace) $
818 groupBy (\x y -> (isDisplayMath x && isDisplayMath y) ||
819 groupBy (\x y -> (isDisplayMath x && isDisplayMath y) ||
819 not (isDisplayMath x || isDisplayMath y)) lst
820 not (isDisplayMath x || isDisplayMath y)) lst
820fixDisplayMath (Para lst)
821fixDisplayMath (Para lst)
821 | any isDisplayMath lst && not (all isDisplayMath lst) =
822 | any isDisplayMath lst && not (all isDisplayMath lst) =
822 -- chop into several paragraphs so each displaymath is its own
823 -- chop into several paragraphs so each displaymath is its own
823− map (Para . stripLeadingTrailingSpace) $
824+ Div ("",["math"],[]) $ map (Para . stripLeadingTrailingSpace) $
824 groupBy (\x y -> (isDisplayMath x && isDisplayMath y) ||
825 groupBy (\x y -> (isDisplayMath x && isDisplayMath y) ||
825 not (isDisplayMath x || isDisplayMath y)) lst
826 not (isDisplayMath x || isDisplayMath y)) lst
826−fixDisplayMath x = [x]
827+fixDisplayMath x = x
src/Text/Pandoc/Writers/EPUB.hs+3−3
@@ -48,7 +48,7 @@ import qualified Text.Pandoc.Shared as Shared
48import Text.Pandoc.Builder (fromList, setMeta)
48import Text.Pandoc.Builder (fromList, setMeta)
49import Text.Pandoc.Options
49import Text.Pandoc.Options
50import Text.Pandoc.Definition
50import Text.Pandoc.Definition
51−import Text.Pandoc.Generic
51+import Text.Pandoc.Walk
52import Control.Monad.State
52import Control.Monad.State
53import Text.XML.Light hiding (ppTopElement)
53import Text.XML.Light hiding (ppTopElement)
54import Text.Pandoc.UUID
54import Text.Pandoc.UUID
@@ -116,7 +116,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
116
116
117 -- handle pictures
117 -- handle pictures
118 picsRef <- newIORef []
118 picsRef <- newIORef []
119− Pandoc _ blocks <- bottomUpM
119+ Pandoc _ blocks <- walkM
120 (transformInline opts' sourceDir picsRef) doc
120 (transformInline opts' sourceDir picsRef) doc
121 pics <- readIORef picsRef
121 pics <- readIORef picsRef
122 let readPicEntry entries (oldsrc, newsrc) = do
122 let readPicEntry entries (oldsrc, newsrc) = do
@@ -520,7 +520,7 @@ correlateRefs chapterHeaderLevel bs =
520-- Replace internal link references using the table produced
520-- Replace internal link references using the table produced
521-- by correlateRefs.
521-- by correlateRefs.
522replaceRefs :: [(String,String)] -> [Block] -> [Block]
522replaceRefs :: [(String,String)] -> [Block] -> [Block]
523−replaceRefs refTable = bottomUp replaceOneRef
523+replaceRefs refTable = walk replaceOneRef
524 where replaceOneRef x@(Link lab ('#':xs,tit)) =
524 where replaceOneRef x@(Link lab ('#':xs,tit)) =
525 case lookup xs refTable of
525 case lookup xs refTable of
526 Just url -> Link lab (url,tit)
526 Just url -> Link lab (url,tit)
src/Text/Pandoc/Writers/FB2.hs+6−2
@@ -45,7 +45,7 @@ import qualified Text.XML.Light.Cursor as XC
45import Text.Pandoc.Definition
45import Text.Pandoc.Definition
46import Text.Pandoc.Options (WriterOptions(..), HTMLMathMethod(..), def)
46import Text.Pandoc.Options (WriterOptions(..), HTMLMathMethod(..), def)
47import Text.Pandoc.Shared (orderedListMarkers)
47import Text.Pandoc.Shared (orderedListMarkers)
48−import Text.Pandoc.Generic (bottomUp)
48+import Text.Pandoc.Walk
49
49
50-- | Data to be written at the end of the document:
50-- | Data to be written at the end of the document:
51-- (foot)notes, URLs, references, images.
51-- (foot)notes, URLs, references, images.
@@ -423,6 +423,10 @@ indent = indentBlock
423 indentLines ins = let lns = split isLineBreak ins :: [[Inline]]
423 indentLines ins = let lns = split isLineBreak ins :: [[Inline]]
424 in intercalate [LineBreak] $ map ((Str spacer):) lns
424 in intercalate [LineBreak] $ map ((Str spacer):) lns
425
425
426+capitalize :: Inline -> Inline
427+capitalize (Str xs) = Str $ map toUpper xs
428+capitalize x = x
429+
426-- | Convert a Pandoc's Inline element to FictionBook XML representation.
430-- | Convert a Pandoc's Inline element to FictionBook XML representation.
427toXml :: Inline -> FBM [Content]
431toXml :: Inline -> FBM [Content]
428toXml (Str s) = return [txt s]
432toXml (Str s) = return [txt s]
@@ -432,7 +436,7 @@ toXml (Strong ss) = list `liftM` wrap "strong" ss
432toXml (Strikeout ss) = list `liftM` wrap "strikethrough" ss
436toXml (Strikeout ss) = list `liftM` wrap "strikethrough" ss
433toXml (Superscript ss) = list `liftM` wrap "sup" ss
437toXml (Superscript ss) = list `liftM` wrap "sup" ss
434toXml (Subscript ss) = list `liftM` wrap "sub" ss
438toXml (Subscript ss) = list `liftM` wrap "sub" ss
435−toXml (SmallCaps ss) = cMapM toXml $ bottomUp (map toUpper) ss
439+toXml (SmallCaps ss) = cMapM toXml $ walk capitalize ss
436toXml (Quoted SingleQuote ss) = do -- FIXME: should be language-specific
440toXml (Quoted SingleQuote ss) = do -- FIXME: should be language-specific
437 inner <- cMapM toXml ss
441 inner <- cMapM toXml ss
438 return $ [txt "‘"] ++ inner ++ [txt "’"]
442 return $ [txt "‘"] ++ inner ++ [txt "’"]
src/Text/Pandoc/Writers/LaTeX.hs+1−2
@@ -31,7 +31,6 @@ Conversion of 'Pandoc' format into LaTeX.
31module Text.Pandoc.Writers.LaTeX ( writeLaTeX ) where
31module Text.Pandoc.Writers.LaTeX ( writeLaTeX ) where
32import Text.Pandoc.Definition
32import Text.Pandoc.Definition
33import Text.Pandoc.Walk
33import Text.Pandoc.Walk
34−import Text.Pandoc.Generic
35import Text.Pandoc.Shared
34import Text.Pandoc.Shared
36import Text.Pandoc.Writers.Shared
35import Text.Pandoc.Writers.Shared
37import Text.Pandoc.Options
36import Text.Pandoc.Options
@@ -498,7 +497,7 @@ sectionHeader unnumbered ref level lst = do
498 txt <- inlineListToLaTeX lst
497 txt <- inlineListToLaTeX lst
499 let noNote (Note _) = Str ""
498 let noNote (Note _) = Str ""
500 noNote x = x
499 noNote x = x
501− let lstNoNotes = bottomUp noNote lst
500+ let lstNoNotes = walk noNote lst
502 let star = if unnumbered then text "*" else empty
501 let star = if unnumbered then text "*" else empty
503 -- footnotes in sections don't work unless you specify an optional
502 -- footnotes in sections don't work unless you specify an optional
504 -- argument: \section[mysec]{mysec\footnote{blah}}
503 -- argument: \section[mysec]{mysec\footnote{blah}}
src/Text/Pandoc/Writers/Markdown.hs+4−4
@@ -32,7 +32,7 @@ Markdown: <http://daringfireball.net/projects/markdown/>
32-}
32-}
33module Text.Pandoc.Writers.Markdown (writeMarkdown, writePlain) where
33module Text.Pandoc.Writers.Markdown (writeMarkdown, writePlain) where
34import Text.Pandoc.Definition
34import Text.Pandoc.Definition
35−import Text.Pandoc.Generic
35+import Text.Pandoc.Walk
36import Text.Pandoc.Templates (renderTemplate')
36import Text.Pandoc.Templates (renderTemplate')
37import Text.Pandoc.Shared
37import Text.Pandoc.Shared
38import Text.Pandoc.Writers.Shared
38import Text.Pandoc.Writers.Shared
@@ -82,7 +82,7 @@ writePlain opts document =
82 where document' = plainify document
82 where document' = plainify document
83
83
84plainify :: Pandoc -> Pandoc
84plainify :: Pandoc -> Pandoc
85−plainify = bottomUp go
85+plainify = walk go
86 where go :: Inline -> Inline
86 where go :: Inline -> Inline
87 go (Emph xs) = SmallCaps xs
87 go (Emph xs) = SmallCaps xs
88 go (Strong xs) = SmallCaps xs
88 go (Strong xs) = SmallCaps xs
@@ -643,13 +643,13 @@ inlineToMarkdown opts (Strikeout lst) = do
643 then "~~" <> contents <> "~~"
643 then "~~" <> contents <> "~~"
644 else "<s>" <> contents <> "</s>"
644 else "<s>" <> contents <> "</s>"
645inlineToMarkdown opts (Superscript lst) = do
645inlineToMarkdown opts (Superscript lst) = do
646− let lst' = bottomUp escapeSpaces lst
646+ let lst' = walk escapeSpaces lst
647 contents <- inlineListToMarkdown opts lst'
647 contents <- inlineListToMarkdown opts lst'
648 return $ if isEnabled Ext_superscript opts
648 return $ if isEnabled Ext_superscript opts
649 then "^" <> contents <> "^"
649 then "^" <> contents <> "^"
650 else "<sup>" <> contents <> "</sup>"
650 else "<sup>" <> contents <> "</sup>"
651inlineToMarkdown opts (Subscript lst) = do
651inlineToMarkdown opts (Subscript lst) = do
652− let lst' = bottomUp escapeSpaces lst
652+ let lst' = walk escapeSpaces lst
653 contents <- inlineListToMarkdown opts lst'
653 contents <- inlineListToMarkdown opts lst'
654 return $ if isEnabled Ext_subscript opts
654 return $ if isEnabled Ext_subscript opts
655 then "~" <> contents <> "~"
655 then "~" <> contents <> "~"
src/Text/Pandoc/Writers/ODT.hs+2−2
@@ -39,7 +39,7 @@ import Text.Pandoc.Shared ( stringify, readDataFile, fetchItem, warn )
39import Text.Pandoc.ImageSize ( imageSize, sizeInPoints )
39import Text.Pandoc.ImageSize ( imageSize, sizeInPoints )
40import Text.Pandoc.MIME ( getMimeType )
40import Text.Pandoc.MIME ( getMimeType )
41import Text.Pandoc.Definition
41import Text.Pandoc.Definition
42−import Text.Pandoc.Generic
42+import Text.Pandoc.Walk
43import Text.Pandoc.Writers.OpenDocument ( writeOpenDocument )
43import Text.Pandoc.Writers.OpenDocument ( writeOpenDocument )
44import Control.Monad (liftM)
44import Control.Monad (liftM)
45import Text.Pandoc.XML
45import Text.Pandoc.XML
@@ -63,7 +63,7 @@ writeODT opts doc@(Pandoc meta _) = do
63 -- handle pictures
63 -- handle pictures
64 picEntriesRef <- newIORef ([] :: [Entry])
64 picEntriesRef <- newIORef ([] :: [Entry])
65 let sourceDir = writerSourceDirectory opts
65 let sourceDir = writerSourceDirectory opts
66− doc' <- bottomUpM (transformPic sourceDir picEntriesRef) doc
66+ doc' <- walkM (transformPic sourceDir picEntriesRef) doc
67 let newContents = writeOpenDocument opts{writerWrapText = False} doc'
67 let newContents = writeOpenDocument opts{writerWrapText = False} doc'
68 epochtime <- floor `fmap` getPOSIXTime
68 epochtime <- floor `fmap` getPOSIXTime
69 let contentEntry = toEntry "content.xml" epochtime $ fromStringLazy newContents
69 let contentEntry = toEntry "content.xml" epochtime $ fromStringLazy newContents
src/Text/Pandoc/Writers/RTF.hs+2−2
@@ -34,7 +34,7 @@ import Text.Pandoc.Shared
34import Text.Pandoc.Writers.Shared
34import Text.Pandoc.Writers.Shared
35import Text.Pandoc.Readers.TeXMath
35import Text.Pandoc.Readers.TeXMath
36import Text.Pandoc.Templates (renderTemplate')
36import Text.Pandoc.Templates (renderTemplate')
37−import Text.Pandoc.Generic (bottomUpM)
37+import Text.Pandoc.Walk
38import Data.List ( isSuffixOf, intercalate )
38import Data.List ( isSuffixOf, intercalate )
39import Data.Char ( ord, chr, isDigit, toLower )
39import Data.Char ( ord, chr, isDigit, toLower )
40import System.FilePath ( takeExtension )
40import System.FilePath ( takeExtension )
@@ -70,7 +70,7 @@ rtfEmbedImage x = return x
70-- images embedded as encoded binary data.
70-- images embedded as encoded binary data.
71writeRTFWithEmbeddedImages :: WriterOptions -> Pandoc -> IO String
71writeRTFWithEmbeddedImages :: WriterOptions -> Pandoc -> IO String
72writeRTFWithEmbeddedImages options doc =
72writeRTFWithEmbeddedImages options doc =
73− writeRTF options `fmap` bottomUpM rtfEmbedImage doc
73+ writeRTF options `fmap` walkM rtfEmbedImage doc
74
74
75-- | Convert Pandoc to a string in rich text format.
75-- | Convert Pandoc to a string in rich text format.
76writeRTF :: WriterOptions -> Pandoc -> String
76writeRTF :: WriterOptions -> Pandoc -> String