pandoc-lens 0.2.1 → 0.3
raw patch · 2 files changed
+59/−15 lines, 2 filesdep ~lensPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: lens
API changes (from Hackage documentation)
+ Text.Pandoc.Lens: blockInlines :: Traversal' Block Inline
+ Text.Pandoc.Lens: data Pandoc :: *
Files
- Text/Pandoc/Lens.hs +56/−13
- pandoc-lens.cabal +3/−2
Text/Pandoc/Lens.hs view
@@ -2,14 +2,22 @@ {-# 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.+ module Text.Pandoc.Lens ( -- * Documents- body+ Pandoc+ , body , meta -- * Blocks -- | Prisms are provided for the constructors of 'Block' -- as well as a 'Plated' instance. , Block+ , blockInlines , _Plain , _Para , _CodeBlock@@ -55,7 +63,7 @@ -- | A traversal focusing on a particular metadata value of a document meta :: String -> Traversal' Pandoc MetaValue-meta m = metaL . _Wrapped' . ix m+meta name = metaL . _Wrapped' . ix name where metaL :: Lens' Pandoc Meta metaL = lens (\(Pandoc m _)->m) (\(Pandoc _ a) m->Pandoc m a)@@ -120,6 +128,30 @@ f Null = Just () f _ = Nothing +instance Plated Block where+ plate f blk =+ case blk of+ BlockQuote blks -> BlockQuote <$> traverse f blks+ OrderedList attrs blks -> OrderedList attrs <$> traverseOf (each . each) f blks+ BulletList blks -> BulletList <$> traverseOf (each . each) f blks+ DefinitionList blks -> DefinitionList <$> traverseOf (each . _2 . each . each) f blks+ Table a b c hdrs rows -> Table a b c <$> traverseOf (each . each) f hdrs+ <*> traverseOf (each . each . each) f rows+ Div attrs blks -> Div attrs <$> traverseOf each f blks+ _ -> pure blk++-- | Traverse over the 'Inline' children of a 'Block'+blockInlines :: Traversal' Block Inline+blockInlines f blk =+ case blk of+ Plain inls -> Plain <$> traverse f inls+ Para inls -> Para <$> traverse f inls+ DefinitionList xs -> DefinitionList <$> traverseOf (each . _1 . each) f xs+ Header n attr inls -> Header n attr <$> traverse f inls+ Table capt a b c d -> Table <$> traverse f capt+ <*> pure a <*> pure b <*> pure c <*> pure d+ _ -> pure blk+ -- | A prism on a 'Str' 'Inline' _Str :: Prism' Inline String _Str = prism' Str f@@ -204,21 +236,32 @@ f (Span _ s) = Just s f _ = Nothing -instance Plated Inline-instance Plated Block+instance Plated Inline where+ plate f inl =+ case inl of+ Emph cs -> Emph <$> traverseOf each f cs+ Strong cs -> Strong <$> traverseOf each f cs+ Strikeout cs -> Strikeout <$> traverseOf each f cs+ Superscript cs -> Superscript <$> traverseOf each f cs+ Subscript cs -> Subscript <$> traverseOf each f cs+ SmallCaps cs -> SmallCaps <$> traverseOf each f cs+ Quoted q cs -> Quoted q <$> traverseOf each f cs+ Cite cit cs -> Cite cit <$> traverseOf each f cs+ Span attrs cs -> Span attrs <$> traverseOf each f cs+ _ -> pure inl -- | An object that has attributes class HasAttr a where- -- | A traversal over the attributes of an object- attributes :: Traversal' a Attr+ -- | A traversal over the attributes of an object+ attributes :: Traversal' a Attr instance HasAttr Block where- attributes f (CodeBlock a s) = fmap (\a'->CodeBlock a' s) (f a)- attributes f (Header n a s) = fmap (\a'->Header n a' s) (f a)- attributes f (Div a s) = fmap (\a'->Div a' s) (f a)- attributes _ x = pure x+ attributes f (CodeBlock a s) = fmap (\a'->CodeBlock a' s) (f a)+ attributes f (Header n a s) = fmap (\a'->Header n a' s) (f a)+ attributes f (Div a s) = fmap (\a'->Div a' s) (f a)+ attributes _ x = pure x instance HasAttr Inline where- attributes f (Code a s) = fmap (\a'->Code a' s) (f a)- attributes f (Span a s) = fmap (\a'->Span a' s) (f a)- attributes _ x = pure x+ attributes f (Code a s) = fmap (\a'->Code a' s) (f a)+ attributes f (Span a s) = fmap (\a'->Span a' s) (f a)+ attributes _ x = pure x
pandoc-lens.cabal view
@@ -1,5 +1,5 @@ name: pandoc-lens-version: 0.2.1+version: 0.3 synopsis: Lenses for Pandoc documents description: Lenses for Pandoc documents homepage: http://github.com/bgamari/pandoc-lens@@ -18,8 +18,9 @@ library exposed-modules: Text.Pandoc.Lens+ ghc-options: -Wall -fno-warn-orphans build-depends: base >=4.7 && <4.8, containers >=0.5 && <0.6, pandoc-types >=1.12 && <1.13,- lens >=4.2 && <4.4+ lens >=4.2 && <4.7 default-language: Haskell2010