Skip to content

Commit

Permalink
Added Walkable instances for Citation.
Browse files Browse the repository at this point in the history
This address pandoc #1269 -- previously `walk` did not enter
into Citation prefixes and suffixes.
  • Loading branch information
jgm committed Apr 30, 2014
1 parent 257d254 commit 9c6e1ad
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions Text/Pandoc/Walk.hs
Expand Up @@ -108,7 +108,7 @@ instance Walkable Inline Inline where
walk f (Superscript xs) = f $ Superscript (walk f xs)
walk f (SmallCaps xs) = f $ SmallCaps (walk f xs)
walk f (Quoted qt xs) = f $ Quoted qt (walk f xs)
walk f (Cite cs xs) = f $ Cite cs (walk f xs)
walk f (Cite cs xs) = f $ Cite (walk f cs) (walk f xs)
walk f (Code attr s) = f $ Code attr s
walk f Space = f Space
walk f LineBreak = f LineBreak
Expand All @@ -127,7 +127,9 @@ instance Walkable Inline Inline where
walkM f (Superscript xs)= Superscript <$> walkM f xs >>= f
walkM f (SmallCaps xs) = SmallCaps <$> walkM f xs >>= f
walkM f (Quoted qt xs) = Quoted qt <$> walkM f xs >>= f
walkM f (Cite cs xs) = Cite cs <$> walkM f xs >>= f
walkM f (Cite cs xs) = do cs' <- walkM f cs
xs' <- walkM f xs
f $ Cite cs' xs'
walkM f (Code attr s) = f $ Code attr s
walkM f Space = f Space
walkM f LineBreak = f LineBreak
Expand All @@ -146,7 +148,7 @@ instance Walkable Inline Inline where
query f (Superscript xs)= f (Superscript xs) <> query f xs
query f (SmallCaps xs) = f (SmallCaps xs) <> query f xs
query f (Quoted qt xs) = f (Quoted qt xs) <> query f xs
query f (Cite cs xs) = f (Cite cs xs) <> query f xs
query f (Cite cs xs) = f (Cite cs xs) <> query f cs <> query f xs
query f (Code attr s) = f (Code attr s)
query f Space = f Space
query f LineBreak = f LineBreak
Expand Down Expand Up @@ -261,7 +263,7 @@ instance Walkable Block Inline where
walk f (Superscript xs)= Superscript (walk f xs)
walk f (SmallCaps xs) = SmallCaps (walk f xs)
walk f (Quoted qt xs) = Quoted qt (walk f xs)
walk f (Cite cs xs) = Cite cs (walk f xs)
walk f (Cite cs xs) = Cite (walk f cs) (walk f xs)
walk f (Code attr s) = Code attr s
walk f Space = Space
walk f LineBreak = LineBreak
Expand All @@ -280,7 +282,9 @@ instance Walkable Block Inline where
walkM f (Superscript xs)= Superscript <$> walkM f xs
walkM f (SmallCaps xs) = SmallCaps <$> walkM f xs
walkM f (Quoted qt xs) = Quoted qt <$> walkM f xs
walkM f (Cite cs xs) = Cite cs <$> walkM f xs
walkM f (Cite cs xs) = do cs' <- walkM f cs
xs' <- walkM f xs
return $ Cite cs' xs'
walkM f (Code attr s) = return $ Code attr s
walkM f Space = return $ Space
walkM f LineBreak = return $ LineBreak
Expand All @@ -299,7 +303,7 @@ instance Walkable Block Inline where
query f (Superscript xs)= query f xs
query f (SmallCaps xs) = query f xs
query f (Quoted qt xs) = query f xs
query f (Cite cs xs) = query f xs
query f (Cite cs xs) = query f cs <> query f xs
query f (Code attr s) = mempty
query f Space = mempty
query f LineBreak = mempty
Expand Down Expand Up @@ -388,6 +392,26 @@ instance Walkable Block MetaValue where
query f (MetaBlocks bs) = query f bs
query f (MetaMap m) = query f m

instance Walkable Inline Citation where
walk f (Citation id' pref suff mode notenum hash) =
Citation id' (walk f pref) (walk f suff) mode notenum hash
walkM f (Citation id' pref suff mode notenum hash) =
do pref' <- walkM f pref
suff' <- walkM f suff
return $ Citation id' pref' suff' mode notenum hash
query f (Citation id' pref suff mode notenum hash) =
query f pref <> query f suff

instance Walkable Block Citation where
walk f (Citation id' pref suff mode notenum hash) =
Citation id' (walk f pref) (walk f suff) mode notenum hash
walkM f (Citation id' pref suff mode notenum hash) =
do pref' <- walkM f pref
suff' <- walkM f suff
return $ Citation id' pref' suff' mode notenum hash
query f (Citation id' pref suff mode notenum hash) =
query f pref <> query f suff

instance Walkable a b => Walkable a [b] where
walk f xs = map (walk f) xs
walkM f xs = mapM (walkM f) xs
Expand Down

0 comments on commit 9c6e1ad

Please sign in to comment.