git.iko.soy/typeable/pandoc
on master help sign in
Use query instead of queryWith.
commit9152fa1a95346e26bc290b3f5018b2eeb5d4e077 authorJohn MacFarlane <fiddlosopher@gmail.com> dateSat 10 Aug 2013, 18:13 (13 years ago) parent210d7b7
4 files changed+36−9
src/Text/Pandoc/Biblio.hs+3−2 src/Text/Pandoc/Shared.hs+27−2 src/Text/Pandoc/Writers/ConTeXt.hs+2−2 src/Text/Pandoc/Writers/LaTeX.hs+4−3
src/Text/Pandoc/Biblio.hs+3−2
@@ -36,6 +36,7 @@ import Text.CSL hiding ( Cite(..), Citation(..), endWithPunct )
3636import qualified Text.CSL as CSL ( Cite(..) )
3737import Text.Pandoc.Definition
3838import Text.Pandoc.Generic
39+import Text.Pandoc.Walk
3940import Text.Pandoc.Shared (stringify)
4041import Text.Parsec hiding (State)
4142import Control.Monad
@@ -48,7 +49,7 @@ processBiblio Nothing _ p = p
4849processBiblio _ [] p = p
4950processBiblio (Just style) r p =
5051 let p' = evalState (bottomUpM setHash p) 1
51− grps = queryWith getCitation p'
52+ grps = query getCitation p'
5253 result = citeproc procOpts style r (setNearNote style $
5354 map (map toCslCite) grps)
5455 cits_map = M.fromList $ zip grps (citations result)
@@ -121,7 +122,7 @@ isTextualCitation (c:_) = citationMode c == AuthorInText
121122isTextualCitation _ = False
122123
123124-- | Retrieve all citations from a 'Pandoc' docuument. To be used with
124−-- 'queryWith'.
125+-- 'query'.
125126getCitation :: Inline -> [[Citation]]
126127getCitation i | Cite t _ <- i = [t]
127128 | otherwise = []
src/Text/Pandoc/Shared.hs+27−2
@@ -1,4 +1,4 @@
1−{-# LANGUAGE DeriveDataTypeable, CPP #-}
1+{-# LANGUAGE DeriveDataTypeable, CPP, MultiParamTypeClasses #-}
22{-
33Copyright (C) 2006-2013 John MacFarlane <jgm@berkeley.edu>
44
@@ -79,6 +79,7 @@ module Text.Pandoc.Shared (
7979 ) where
8080
8181import Text.Pandoc.Definition
82+import Text.Pandoc.Walk
8283import Text.Pandoc.Generic
8384import Text.Pandoc.Builder (Blocks, ToMetaValue(..))
8485import qualified Text.Pandoc.Builder as B
@@ -105,6 +106,7 @@ import Text.HTML.TagSoup (renderTagsOptions, RenderOptions(..), Tag(..),
105106 renderOptions)
106107import qualified Data.ByteString as BS
107108import qualified Data.ByteString.Char8 as B8
109+import Text.Pandoc.Compat.Monoid
108110
109111#ifdef EMBED_DATA_FILES
110112import Text.Pandoc.Data (dataFiles)
@@ -383,7 +385,7 @@ consolidateInlines [] = []
383385
384386-- | Convert list of inlines to a string with formatting removed.
385387stringify :: [Inline] -> String
386−stringify = queryWith go
388+stringify = query go
387389 where go :: Inline -> [Char]
388390 go Space = " "
389391 go (Str x) = x
@@ -433,6 +435,29 @@ data Element = Blk Block
433435 -- lvl num attributes label contents
434436 deriving (Eq, Read, Show, Typeable, Data)
435437
438+instance Walkable Inline Element where
439+ walk f (Blk x) = Blk (walk f x)
440+ walk f (Sec lev nums attr ils elts) = Sec lev nums attr (walk f ils) (walk f elts)
441+ walkM f (Blk x) = Blk `fmap` walkM f x
442+ walkM f (Sec lev nums attr ils elts) = do
443+ ils' <- walkM f ils
444+ elts' <- walkM f elts
445+ return $ Sec lev nums attr ils' elts'
446+ query f (Blk x) = query f x
447+ query f (Sec _ _ _ ils elts) = query f ils <> query f elts
448+
449+instance Walkable Block Element where
450+ walk f (Blk x) = Blk (walk f x)
451+ walk f (Sec lev nums attr ils elts) = Sec lev nums attr (walk f ils) (walk f elts)
452+ walkM f (Blk x) = Blk `fmap` walkM f x
453+ walkM f (Sec lev nums attr ils elts) = do
454+ ils' <- walkM f ils
455+ elts' <- walkM f elts
456+ return $ Sec lev nums attr ils' elts'
457+ query f (Blk x) = query f x
458+ query f (Sec _ _ _ ils elts) = query f ils <> query f elts
459+
460+
436461-- | Convert Pandoc inline list to plain text identifier. HTML
437462-- identifiers must start with a letter, and may contain only
438463-- letters, digits, and the characters _-.
src/Text/Pandoc/Writers/ConTeXt.hs+2−2
@@ -33,7 +33,7 @@ import Text.Pandoc.Definition
3333import Text.Pandoc.Shared
3434import Text.Pandoc.Writers.Shared
3535import Text.Pandoc.Options
36−import Text.Pandoc.Generic (queryWith)
36+import Text.Pandoc.Walk (query)
3737import Text.Printf ( printf )
3838import Data.List ( intercalate, isPrefixOf )
3939import Control.Monad.State
@@ -326,7 +326,7 @@ inlineToConTeXt (Note contents) = do
326326 contents' <- blockListToConTeXt contents
327327 let codeBlock x@(CodeBlock _ _) = [x]
328328 codeBlock _ = []
329− let codeBlocks = queryWith codeBlock contents
329+ let codeBlocks = query codeBlock contents
330330 return $ if null codeBlocks
331331 then text "\\footnote{" <> nest 2 contents' <> char '}'
332332 else text "\\startbuffer " <> nest 2 contents' <>
src/Text/Pandoc/Writers/LaTeX.hs+4−3
@@ -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.Walk
3334import Text.Pandoc.Generic
3435import Text.Pandoc.Shared
3536import Text.Pandoc.Writers.Shared
@@ -86,7 +87,7 @@ pandocToLaTeX options (Pandoc meta blocks) = do
8687 -- see if there are internal links
8788 let isInternalLink (Link _ ('#':xs,_)) = [xs]
8889 isInternalLink _ = []
89− modify $ \s -> s{ stInternalLinks = queryWith isInternalLink blocks }
90+ modify $ \s -> s{ stInternalLinks = query isInternalLink blocks }
9091 let template = writerTemplate options
9192 -- set stBook depending on documentclass
9293 let bookClasses = ["memoir","book","report","scrreprt","scrbook"]
@@ -248,9 +249,9 @@ elementToBeamer slideLevel (Sec lvl _num (ident,classes,kvs) tit elts)
248249 let hasCode (Code _ _) = [True]
249250 hasCode _ = []
250251 opts <- gets stOptions
251− let fragile = not $ null $ queryWith hasCodeBlock elts ++
252+ let fragile = not $ null $ query hasCodeBlock elts ++
252253 if writerListings opts
253− then queryWith hasCode elts
254+ then query hasCode elts
254255 else []
255256 let allowframebreaks = "allowframebreaks" `elem` classes
256257 let optionslist = ["fragile" | fragile] ++