packages feed

pandoc-lens 0.3.3 → 0.4.0

raw patch · 2 files changed

+134/−10 lines, 2 files

Files

Text/Pandoc/Lens.hs view
@@ -1,12 +1,11 @@ {-# LANGUAGE RankNTypes #-} {-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE TemplateHaskell #-}  -- | This provides a variety of optics for traversing and -- destructuring Pandoc documents. ----- Note that both @Inline@ and @Block@ have @Plated@ instances which--- are useful for traversing the AST.+-- Note that both 'Inline', 'Block', and 'MetaValue' have 'Plated' instances+-- which are useful for traversing the AST.  module Text.Pandoc.Lens     ( -- * Documents@@ -22,9 +21,12 @@     , _Para     , _CodeBlock     , _BlockQuote+    , _OrderedList     , _BulletList     , _DefinitionList+    , _Header     , _HorizontalRule+    , _Div     , _Null       -- * Inlines       -- | Prisms are provided for the constructors of 'Inline'@@ -37,17 +39,27 @@     , _Superscript     , _Subscript     , _SmallCaps-    -- , _Quoted-    -- , _Cite+    , _Quoted+    , _Cite     , _Code     , _Space     , _LineBreak-    -- , _Math-    -- , _RawInline-    -- , _Link-    -- , _Image+    , _Math+    , _RawInline+    , _Link+    , _Image     , _Note     , _Span+      -- * Metadata+      -- | Prisms are provided for the constructors of 'MetaValue'+      -- as well as a 'Plated' instance.+    , MetaValue+    , _MetaMap+    , _MetaList+    , _MetaBool+    , _MetaString+    , _MetaInlines+    , _MetaBlocks       -- * Attributes     , HasAttr(..)     ) where@@ -101,6 +113,13 @@     f _                  = Nothing  -- | A prism on the items of a bullet list 'Block'+_OrderedList :: Prism' Block (ListAttributes, [[Block]])+_OrderedList = prism' (uncurry OrderedList) f+  where+    f (OrderedList x y)  = Just (x, y)+    f _                  = Nothing++-- | A prism on the items of a bullet list 'Block' _BulletList :: Prism' Block [[Block]] _BulletList = prism' BulletList f   where@@ -114,6 +133,13 @@     f (DefinitionList x) = Just x     f _                  = Nothing +-- | A prism on a 'Header' 'Block'+_Header :: Prism' Block (Int, [Inline])+_Header = prism' (\(a,b) -> Header a nullAttr b) f+  where+    f (Header a _ b)   = Just (a, b)+    f _                = Nothing+ -- | A prism on a 'HorizontalRule' 'Block' _HorizontalRule :: Prism' Block () _HorizontalRule = prism' (const HorizontalRule) f@@ -121,6 +147,13 @@     f HorizontalRule     = Just ()     f _                  = Nothing +-- | A prism on a 'Div' 'Block'+_Div :: Prism' Block [Block]+_Div = prism' (Div nullAttr) f+  where+    f (Div _ a)    = Just a+    f _            = Nothing+ -- | A prism on a 'Null' 'Block' _Null :: Prism' Block () _Null = prism' (const Null) f@@ -201,6 +234,20 @@     f (SmallCaps s) = Just s     f _             = Nothing +-- | A prism on a 'Quoted' 'Inline'+_Quoted :: Prism' Inline (QuoteType, [Inline])+_Quoted = prism' (uncurry Quoted) f+  where+    f (Quoted a b)  = Just (a,b)+    f _             = Nothing++-- | A prism on a 'Cite' 'Inline'+_Cite :: Prism' Inline ([Citation], [Inline])+_Cite = prism' (uncurry Cite) f+  where+    f (Cite a b)  = Just (a,b)+    f _           = Nothing+ -- | A prism on the body of a 'Code' 'Inline' _Code :: Prism' Inline String _Code = prism' (Code nullAttr) f@@ -222,6 +269,34 @@     f LineBreak = Just ()     f _         = Nothing +-- | A prism on a 'Math' 'Inline'+_Math :: Prism' Inline (MathType, String)+_Math = prism' (uncurry Math) f+  where+    f (Math a b) = Just (a, b)+    f _          = Nothing++-- | A prism on a 'RawInline' 'Inline'+_RawInline :: Prism' Inline (Format, String)+_RawInline = prism' (uncurry RawInline) f+  where+    f (RawInline a b) = Just (a, b)+    f _               = Nothing++-- | A prism on a 'Link' 'Inline'+_Link :: Prism' Inline ([Inline], Target)+_Link = prism' (uncurry Link) f+  where+    f (Link a b) = Just (a, b)+    f _          = Nothing++-- | A prism on a 'Image' 'Inline'+_Image :: Prism' Inline ([Inline], Target)+_Image = prism' (uncurry Image) f+  where+    f (Image a b) = Just (a, b)+    f _           = Nothing+ -- | A prism on a 'Note' 'Inline' _Note :: Prism' Inline [Block] _Note = prism' Note f@@ -249,6 +324,55 @@         Cite cit cs    -> Cite cit <$> traverseOf each f cs         Span attrs cs  -> Span attrs <$> traverseOf each f cs         _              -> pure inl++-- | A prism on a piece of 'MetaMap' metadata+_MetaMap :: Prism' MetaValue (Map String MetaValue)+_MetaMap = prism' MetaMap f+  where+    f (MetaMap x) = Just x+    f _           = Nothing++-- | A prism on a piece of 'MetaList' metadata+_MetaList :: Prism' MetaValue [MetaValue]+_MetaList = prism' MetaList f+  where+    f (MetaList x) = Just x+    f _            = Nothing++-- | A prism on a piece of 'MetaBool' metadata+_MetaBool :: Prism' MetaValue Bool+_MetaBool = prism' MetaBool f+  where+    f (MetaBool x) = Just x+    f _            = Nothing++-- | A prism on a piece of 'MetaString' metadata+_MetaString :: Prism' MetaValue String+_MetaString = prism' MetaString f+  where+    f (MetaString x) = Just x+    f _              = Nothing++-- | A prism on a piece of 'MetaInlines' metadata+_MetaInlines :: Prism' MetaValue [Inline]+_MetaInlines = prism' MetaInlines f+  where+    f (MetaInlines x) = Just x+    f _               = Nothing++-- | A prism on a piece of 'MetaBlocks' metadata+_MetaBlocks :: Prism' MetaValue [Block]+_MetaBlocks = prism' MetaBlocks f+  where+    f (MetaBlocks x) = Just x+    f _              = Nothing++instance Plated MetaValue where+    plate f inl =+      case inl of+        MetaMap cs  -> MetaMap <$> traverseOf each f cs+        MetaList cs -> MetaList <$> traverseOf each f cs+        _           -> pure inl  -- | An object that has attributes class HasAttr a where
pandoc-lens.cabal view
@@ -1,5 +1,5 @@ name:                pandoc-lens-version:             0.3.3+version:             0.4.0 synopsis:            Lenses for Pandoc documents description:         Lenses for Pandoc documents homepage:            http://github.com/bgamari/pandoc-lens