git.iko.soy/typeable/pandoc
on master help sign in
Use functions from Text.Pandoc.Generic instead of processWith(M).
commit10d85f8b0b31f117f79e53d2c50cf20d0fd0fab1 authorJohn MacFarlane <jgm@berkeley.edu> dateFri 24 Dec 2010, 13:39 (16 years ago) parentb950503
10 files changed+31−20
MakeManPage.hs+3−3 src/Text/Pandoc.hs+3 src/Text/Pandoc/Biblio.hs+6−5 src/Text/Pandoc/Parsing.hs+2−1 src/Text/Pandoc/Readers/Markdown.hs+2−1 src/Text/Pandoc/Shared.hs+5−4 src/Text/Pandoc/Writers/EPUB.hs+2−1 src/Text/Pandoc/Writers/LaTeX.hs+2−1 src/Text/Pandoc/Writers/Markdown.hs+4−3 src/Text/Pandoc/Writers/ODT.hs+2−1
MakeManPage.hs+3−3
@@ -14,8 +14,8 @@ main = do
1414 let opts = defaultWriterOptions{ writerStandalone = True
1515 , writerTemplate = manTemplate }
1616 let manPage = writeMan opts $
17− processWith (concatMap removeLinks) $
18− processWith capitalizeHeaders $
17+ bottomUp (concatMap removeLinks) $
18+ bottomUp capitalizeHeaders $
1919 Pandoc meta newBlocks
2020 B.writeFile ("man" </> "man1" </> "pandoc.1") $ fromString manPage
2121
@@ -24,7 +24,7 @@ removeLinks (Link l _) = l
2424removeLinks x = [x]
2525
2626capitalizeHeaders :: Block -> Block
27−capitalizeHeaders (Header 1 xs) = Header 1 $ processWith capitalize xs
27+capitalizeHeaders (Header 1 xs) = Header 1 $ bottomUp capitalize xs
2828capitalizeHeaders x = x
2929
3030capitalize :: Inline -> Inline
src/Text/Pandoc.hs+3
@@ -57,6 +57,8 @@ module Text.Pandoc
5757 (
5858 -- * Definitions
5959 module Text.Pandoc.Definition
60+ -- * Generics
61+ , module Text.Pandoc.Generic
6062 -- * Lists of readers and writers
6163 , readers
6264 , writers
@@ -106,6 +108,7 @@ module Text.Pandoc
106108 ) where
107109
108110import Text.Pandoc.Definition
111+import Text.Pandoc.Generic
109112import Text.Pandoc.Readers.Markdown
110113import Text.Pandoc.Readers.RST
111114import Text.Pandoc.Readers.LaTeX
src/Text/Pandoc/Biblio.hs+6−5
@@ -36,6 +36,7 @@ import qualified Data.Map as M
3636import Text.CSL hiding ( Cite(..), Citation(..) )
3737import qualified Text.CSL as CSL ( Cite(..) )
3838import Text.Pandoc.Definition
39+import Text.Pandoc.Generic
3940import Text.Pandoc.Shared (stringify)
4041import Text.ParserCombinators.Parsec
4142import Control.Monad
@@ -47,7 +48,7 @@ processBiblio cslfile r p
4748 = if null r then return p
4849 else do
4950 csl <- readCSLFile cslfile
50− p' <- processWithM setHash p
51+ p' <- bottomUpM setHash p
5152 let (nts,grps) = if styleClass csl == "note"
5253 then let cits = queryWith getCite p'
5354 ncits = map (queryWith getCite) $ queryWith getNote p'
@@ -58,7 +59,7 @@ processBiblio cslfile r p
5859 map (map toCslCite) grps)
5960 cits_map = M.fromList $ zip grps (citations result)
6061 biblioList = map (renderPandoc' csl) (bibliography result)
61− Pandoc m b = processWith (procInlines $ processCite csl cits_map) p'
62+ Pandoc m b = bottomUp (procInlines $ processCite csl cits_map) p'
6263 return . generateNotes nts . Pandoc m $ b ++ biblioList
6364
6465-- | Substitute 'Cite' elements with formatted citations.
@@ -99,7 +100,7 @@ getCite i | Cite _ _ <- i = [i]
99100getNoteCitations :: [Inline] -> Pandoc -> [[Citation]]
100101getNoteCitations needNote
101102 = let mvCite i = if i `elem` needNote then Note [Para [i]] else i
102− setNote = processWith mvCite
103+ setNote = bottomUp mvCite
103104 getCits = concat . flip (zipWith $ setCiteNoteNum) [1..] .
104105 map (queryWith getCite) . queryWith getNote . setNote
105106 in queryWith getCitation . getCits
@@ -109,7 +110,7 @@ setHash (Citation i p s cm nn _)
109110 = hashUnique `fmap` newUnique >>= return . Citation i p s cm nn
110111
111112generateNotes :: [Inline] -> Pandoc -> Pandoc
112−generateNotes needNote = processWith (mvCiteInNote needNote)
113+generateNotes needNote = bottomUp (mvCiteInNote needNote)
113114
114115procInlines :: ([Inline] -> [Inline]) -> Block -> Block
115116procInlines f b
@@ -147,7 +148,7 @@ mvCiteInNote is = procInlines mvCite
147148 , endWithPunct o = Cite c (initInline o) : checkPt xs
148149 | x:xs <- i = x : checkPt xs
149150 | otherwise = []
150− checkNt = processWith $ procInlines checkPt
151+ checkNt = bottomUp $ procInlines checkPt
151152
152153setCiteNoteNum :: [Inline] -> Int -> [Inline]
153154setCiteNoteNum ((Cite cs o):xs) n = Cite (setCitationNoteNum n cs) o : setCiteNoteNum xs n
src/Text/Pandoc/Parsing.hs+2−1
@@ -72,6 +72,7 @@ module Text.Pandoc.Parsing ( (>>~),
7272where
7373
7474import Text.Pandoc.Definition
75+import Text.Pandoc.Generic
7576import qualified Text.Pandoc.UTF8 as UTF8 (putStrLn)
7677import Text.ParserCombinators.Parsec
7778import Text.Pandoc.CharacterReferences ( characterReference )
@@ -655,7 +656,7 @@ type NoteTable = [(String, String)]
655656newtype Key = Key [Inline] deriving (Show, Read, Eq, Ord)
656657
657658toKey :: [Inline] -> Key
658−toKey = Key . processWith lowercase
659+toKey = Key . bottomUp lowercase
659660 where lowercase :: Inline -> Inline
660661 lowercase (Str xs) = Str (map toLower xs)
661662 lowercase (Math t xs) = Math t (map toLower xs)
src/Text/Pandoc/Readers/Markdown.hs+2−1
@@ -35,6 +35,7 @@ import Data.Ord ( comparing )
3535import Data.Char ( isAlphaNum )
3636import Data.Maybe
3737import Text.Pandoc.Definition
38+import Text.Pandoc.Generic
3839import Text.Pandoc.Shared
3940import Text.Pandoc.Parsing
4041import Text.Pandoc.Readers.LaTeX ( rawLaTeXInline, rawLaTeXEnvironment' )
@@ -189,7 +190,7 @@ parseMarkdown = do
189190 handleExampleRef z = z
190191 if M.null examples
191192 then return doc
192− else return $ processWith handleExampleRef doc
193+ else return $ bottomUp handleExampleRef doc
193194
194195--
195196-- initial pass for references and notes
src/Text/Pandoc/Shared.hs+5−4
@@ -71,6 +71,7 @@ module Text.Pandoc.Shared (
7171 ) where
7272
7373import Text.Pandoc.Definition
74+import Text.Pandoc.Generic
7475import qualified Text.Pandoc.UTF8 as UTF8 (readFile)
7576import Data.Char ( toLower, isLower, isUpper, isAlpha, isAscii,
7677 isLetter, isDigit )
@@ -79,7 +80,7 @@ import Network.URI ( isAllowedInURI, escapeURIString, unEscapeString )
7980import Codec.Binary.UTF8.String ( encodeString, decodeString )
8081import System.Directory
8182import System.FilePath ( (</>) )
82−import Data.Generics (Typeable, Data, everywhere', mkT)
83+import Data.Generics (Typeable, Data)
8384import qualified Control.Monad.State as S
8485import Paths_pandoc (getDataFileName)
8586
@@ -257,8 +258,8 @@ normalizeSpaces = cleanup . dropWhile isSpaceOrEmpty
257258-- combining adjacent 'Str's and 'Emph's, remove 'Null's and
258259-- empty elements, etc.
259260normalize :: Pandoc -> Pandoc
260−normalize = everywhere' (mkT normalizeInlines) .
261− everywhere' (mkT normalizeBlocks)
261+normalize = topDown normalizeInlines .
262+ topDown normalizeBlocks
262263
263264normalizeBlocks :: [Block] -> [Block]
264265normalizeBlocks (Null : xs) = normalizeBlocks xs
@@ -404,7 +405,7 @@ isHeaderBlock _ = False
404405
405406-- | Shift header levels up or down.
406407headerShift :: Int -> Pandoc -> Pandoc
407−headerShift n = processWith shift
408+headerShift n = bottomUp shift
408409 where shift :: Block -> Block
409410 shift (Header level inner) = Header (level + n) inner
410411 shift x = x
src/Text/Pandoc/Writers/EPUB.hs+2−1
@@ -39,6 +39,7 @@ import Codec.Archive.Zip
3939import System.Time
4040import Text.Pandoc.Shared hiding ( Element )
4141import Text.Pandoc.Definition
42+import Text.Pandoc.Generic
4243import Control.Monad (liftM)
4344import Text.XML.Light hiding (ppTopElement)
4445import Text.Pandoc.UUID
@@ -69,7 +70,7 @@ writeEPUB mbStylesheet opts doc@(Pandoc meta _) = do
6970
7071 -- handle pictures
7172 picsRef <- newIORef []
72− Pandoc _ blocks <- liftM (processWith transformBlock) $ processWithM
73+ Pandoc _ blocks <- liftM (bottomUp transformBlock) $ bottomUpM
7374 (transformInlines (writerHTMLMathMethod opts) sourceDir picsRef) doc
7475 pics <- readIORef picsRef
7576 let readPicEntry (oldsrc, newsrc) = readEntry [] oldsrc >>= \e ->
src/Text/Pandoc/Writers/LaTeX.hs+2−1
@@ -30,6 +30,7 @@ Conversion of 'Pandoc' format into LaTeX.
3030-}
3131module Text.Pandoc.Writers.LaTeX ( writeLaTeX ) where
3232import Text.Pandoc.Definition
33+import Text.Pandoc.Generic
3334import Text.Pandoc.Shared
3435import Text.Pandoc.Templates
3536import Text.Printf ( printf )
@@ -217,7 +218,7 @@ blockToLaTeX (Header level lst) = do
217218 txt <- inlineListToLaTeX lst'
218219 let noNote (Note _) = Str ""
219220 noNote x = x
220− let lstNoNotes = processWith noNote lst'
221+ let lstNoNotes = bottomUp noNote lst'
221222 -- footnotes in sections don't work unless you specify an optional
222223 -- argument: \section[mysec]{mysec\footnote{blah}}
223224 optional <- if lstNoNotes == lst'
src/Text/Pandoc/Writers/Markdown.hs+4−3
@@ -32,6 +32,7 @@ Markdown: <http://daringfireball.net/projects/markdown/>
3232-}
3333module Text.Pandoc.Writers.Markdown (writeMarkdown, writePlain) where
3434import Text.Pandoc.Definition
35+import Text.Pandoc.Generic
3536import Text.Pandoc.Templates (renderTemplate)
3637import Text.Pandoc.Shared
3738import Text.Pandoc.Parsing hiding (blankline)
@@ -64,7 +65,7 @@ writePlain opts document =
6465 where document' = plainify document
6566
6667plainify :: Pandoc -> Pandoc
67−plainify = processWith go
68+plainify = bottomUp go
6869 where go :: Inline -> Inline
6970 go (Emph xs) = SmallCaps xs
7071 go (Strong xs) = SmallCaps xs
@@ -402,11 +403,11 @@ inlineToMarkdown opts (Strikeout lst) = do
402403 contents <- inlineListToMarkdown opts lst
403404 return $ "~~" <> contents <> "~~"
404405inlineToMarkdown opts (Superscript lst) = do
405− let lst' = processWith escapeSpaces lst
406+ let lst' = bottomUp escapeSpaces lst
406407 contents <- inlineListToMarkdown opts lst'
407408 return $ "^" <> contents <> "^"
408409inlineToMarkdown opts (Subscript lst) = do
409− let lst' = processWith escapeSpaces lst
410+ let lst' = bottomUp escapeSpaces lst
410411 contents <- inlineListToMarkdown opts lst'
411412 return $ "~" <> contents <> "~"
412413inlineToMarkdown opts (SmallCaps lst) = inlineListToMarkdown opts lst
src/Text/Pandoc/Writers/ODT.hs+2−1
@@ -37,6 +37,7 @@ import System.Time
3737import Paths_pandoc ( getDataFileName )
3838import Text.Pandoc.Shared ( WriterOptions(..) )
3939import Text.Pandoc.Definition
40+import Text.Pandoc.Generic
4041import Text.Pandoc.Writers.OpenDocument ( writeOpenDocument )
4142import System.Directory
4243import Control.Monad (liftM)
@@ -63,7 +64,7 @@ writeODT mbRefOdt opts doc = do
6364 -- handle pictures
6465 picEntriesRef <- newIORef ([] :: [Entry])
6566 let sourceDir = writerSourceDirectory opts
66− doc' <- processWithM (transformPic sourceDir picEntriesRef) doc
67+ doc' <- bottomUpM (transformPic sourceDir picEntriesRef) doc
6768 let newContents = writeOpenDocument opts{writerWrapText = False} doc'
6869 (TOD epochtime _) <- getClockTime
6970 let contentEntry = toEntry "content.xml" epochtime $ fromString newContents