pandoc-types 1.17.6.1 → 1.19
raw patch · 11 files changed
+480/−741 lines, 11 filesdep +deepseq-genericsdep −criteriondep −semigroupsdep −transformersdep ~HUnitdep ~QuickCheckdep ~aesonPVP ok
version bump matches the API change (PVP)
Dependencies added: deepseq-generics
Dependencies removed: criterion, semigroups, transformers
Dependency ranges changed: HUnit, QuickCheck, aeson, base, string-qq, syb
API changes (from Hackage documentation)
- Text.Pandoc.Builder: instance GHC.Base.Semigroup (Text.Pandoc.Builder.Many Text.Pandoc.Definition.Block)
- Text.Pandoc.Builder: instance GHC.Base.Semigroup Text.Pandoc.Builder.Inlines
- Text.Pandoc.Builder: instance Text.Pandoc.Builder.ToMetaValue GHC.Base.String
- Text.Pandoc.Builder: instance Text.Pandoc.Builder.ToMetaValue a => Text.Pandoc.Builder.ToMetaValue (Data.Map.Internal.Map GHC.Base.String a)
- Text.Pandoc.Definition: instance GHC.Base.Semigroup Text.Pandoc.Definition.Meta
- Text.Pandoc.Definition: instance GHC.Base.Semigroup Text.Pandoc.Definition.Pandoc
- Text.Pandoc.JSON: instance Text.Pandoc.JSON.ToJSONFilter a => Text.Pandoc.JSON.ToJSONFilter (GHC.Maybe.Maybe Text.Pandoc.Definition.Format -> a)
- Text.Pandoc.JSON: instance Text.Pandoc.Walk.Walkable [a] Text.Pandoc.Definition.Pandoc => Text.Pandoc.JSON.ToJSONFilter (a -> GHC.Types.IO [a])
- Text.Pandoc.JSON: instance Text.Pandoc.Walk.Walkable [a] Text.Pandoc.Definition.Pandoc => Text.Pandoc.JSON.ToJSONFilter (a -> [a])
- Text.Pandoc.Walk: instance Text.Pandoc.Walk.Walkable [Text.Pandoc.Definition.Block] Text.Pandoc.Definition.Block
- Text.Pandoc.Walk: instance Text.Pandoc.Walk.Walkable [Text.Pandoc.Definition.Block] Text.Pandoc.Definition.Citation
- Text.Pandoc.Walk: instance Text.Pandoc.Walk.Walkable [Text.Pandoc.Definition.Block] Text.Pandoc.Definition.Inline
- Text.Pandoc.Walk: instance Text.Pandoc.Walk.Walkable [Text.Pandoc.Definition.Block] Text.Pandoc.Definition.Meta
- Text.Pandoc.Walk: instance Text.Pandoc.Walk.Walkable [Text.Pandoc.Definition.Block] Text.Pandoc.Definition.MetaValue
- Text.Pandoc.Walk: instance Text.Pandoc.Walk.Walkable [Text.Pandoc.Definition.Block] Text.Pandoc.Definition.Pandoc
- Text.Pandoc.Walk: instance Text.Pandoc.Walk.Walkable [Text.Pandoc.Definition.Block] [Text.Pandoc.Definition.Block]
- Text.Pandoc.Walk: instance Text.Pandoc.Walk.Walkable [Text.Pandoc.Definition.Inline] Text.Pandoc.Definition.Block
- Text.Pandoc.Walk: instance Text.Pandoc.Walk.Walkable [Text.Pandoc.Definition.Inline] Text.Pandoc.Definition.Citation
- Text.Pandoc.Walk: instance Text.Pandoc.Walk.Walkable [Text.Pandoc.Definition.Inline] Text.Pandoc.Definition.Inline
- Text.Pandoc.Walk: instance Text.Pandoc.Walk.Walkable [Text.Pandoc.Definition.Inline] Text.Pandoc.Definition.Meta
- Text.Pandoc.Walk: instance Text.Pandoc.Walk.Walkable [Text.Pandoc.Definition.Inline] Text.Pandoc.Definition.MetaValue
- Text.Pandoc.Walk: instance Text.Pandoc.Walk.Walkable [Text.Pandoc.Definition.Inline] Text.Pandoc.Definition.Pandoc
- Text.Pandoc.Walk: instance Text.Pandoc.Walk.Walkable [Text.Pandoc.Definition.Inline] [Text.Pandoc.Definition.Inline]
- Text.Pandoc.Walk: queryBlock :: (Walkable a Citation, Walkable a [Block], Walkable a [Inline], Monoid c) => (a -> c) -> Block -> c
- Text.Pandoc.Walk: queryCitation :: (Walkable a [Inline], Monoid c) => (a -> c) -> Citation -> c
- Text.Pandoc.Walk: queryInline :: (Walkable a Citation, Walkable a [Block], Walkable a [Inline], Monoid c) => (a -> c) -> Inline -> c
- Text.Pandoc.Walk: queryMetaValue :: (Walkable a MetaValue, Walkable a [Block], Walkable a [Inline], Monoid c) => (a -> c) -> MetaValue -> c
- Text.Pandoc.Walk: queryPandoc :: (Walkable a Meta, Walkable a [Block], Monoid c) => (a -> c) -> Pandoc -> c
- Text.Pandoc.Walk: walkBlockM :: (Walkable a [Block], Walkable a [Inline], Monad m, Applicative m, Functor m) => (a -> m a) -> Block -> m Block
- Text.Pandoc.Walk: walkCitationM :: (Walkable a [Inline], Monad m, Applicative m, Functor m) => (a -> m a) -> Citation -> m Citation
- Text.Pandoc.Walk: walkInlineM :: (Walkable a Citation, Walkable a [Block], Walkable a [Inline], Monad m, Applicative m, Functor m) => (a -> m a) -> Inline -> m Inline
- Text.Pandoc.Walk: walkMetaValueM :: (Walkable a MetaValue, Walkable a [Block], Walkable a [Inline], Monad f, Applicative f, Functor f) => (a -> f a) -> MetaValue -> f MetaValue
- Text.Pandoc.Walk: walkPandocM :: (Walkable a Meta, Walkable a [Block], Monad m, Applicative m, Functor m) => (a -> m a) -> Pandoc -> m Pandoc
+ Text.Pandoc.Builder: instance Text.Pandoc.Builder.ToMetaValue a => Text.Pandoc.Builder.ToMetaValue (Data.Map.Base.Map GHC.Base.String a)
+ Text.Pandoc.JSON: instance Data.Data.Data a => Text.Pandoc.JSON.ToJSONFilter (a -> GHC.Types.IO [a])
+ Text.Pandoc.JSON: instance Data.Data.Data a => Text.Pandoc.JSON.ToJSONFilter (a -> [a])
+ Text.Pandoc.JSON: instance Text.Pandoc.JSON.ToJSONFilter a => Text.Pandoc.JSON.ToJSONFilter (GHC.Base.Maybe Text.Pandoc.Definition.Format -> a)
- Text.Pandoc.Builder: (<>) :: Semigroup a => a -> a -> a
+ Text.Pandoc.Builder: (<>) :: Monoid m => m -> m -> m
- Text.Pandoc.Definition: MetaMap :: Map String MetaValue -> MetaValue
+ Text.Pandoc.Definition: MetaMap :: (Map String MetaValue) -> MetaValue
- Text.Pandoc.Walk: walkM :: (Walkable a b, Monad m, Applicative m, Functor m) => (a -> m a) -> b -> m b
+ Text.Pandoc.Walk: walkM :: (Walkable a b, Monad m, Functor m) => (a -> m a) -> b -> m b
Files
- LICENSE +1/−1
- Text/Pandoc/Arbitrary.hs +78/−188
- Text/Pandoc/Builder.hs +30/−28
- Text/Pandoc/Definition.hs +35/−19
- Text/Pandoc/Generic.hs +6/−2
- Text/Pandoc/JSON.hs +8/−6
- Text/Pandoc/Walk.hs +294/−267
- benchmark/bench.hs +0/−39
- changelog +4/−102
- pandoc-types.cabal +17/−28
- test/test-pandoc-types.hs +7/−61
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2006-2019, John MacFarlane+Copyright (c) 2006-2016, John MacFarlane All rights reserved.
Text/Pandoc/Arbitrary.hs view
@@ -1,11 +1,10 @@ {-# OPTIONS_GHC -fno-warn-orphans #-}-{-# LANGUAGE FlexibleInstances, ScopedTypeVariables #-}+{-# LANGUAGE TypeSynonymInstances, FlexibleInstances, ScopedTypeVariables #-} -- provides Arbitrary instance for Pandoc types module Text.Pandoc.Arbitrary () where import Test.QuickCheck-import Control.Applicative (Applicative ((<*>), pure), (<$>))-import Control.Monad (forM)+import Control.Monad (forM, liftM, liftM2) import Text.Pandoc.Definition import Text.Pandoc.Builder @@ -16,216 +15,106 @@ arbAttr :: Gen Attr arbAttr = do id' <- elements ["","loc"]- classes' <- elements [[],["haskell"],["c","numberLines"]]+ classes <- elements [[],["haskell"],["c","numberLines"]] keyvals <- elements [[],[("start","22")],[("a","11"),("b_2","a b c")]]- return (id',classes',keyvals)+ return (id',classes,keyvals) instance Arbitrary Inlines where- arbitrary = (fromList :: [Inline] -> Inlines) <$> arbitrary- shrink = fmap fromList . ((++) <$> shrink <*> flattenShrinkInlines) . toList- where flattenShrinkInlines (x:xs) =- let x' = flattenInline x- in (if null x' then [] else [x' ++ xs]) ++ [x:xs' | xs' <- flattenShrinkInlines xs]- flattenShrinkInlines [] = []- flattenInline :: Inline -> [Inline]- flattenInline (Str _) = []- flattenInline (Emph ils) = ils- flattenInline (Strong ils) = ils- flattenInline (Strikeout ils) = ils- flattenInline (Superscript ils) = ils- flattenInline (Subscript ils) = ils- flattenInline (SmallCaps ils) = ils- flattenInline (Quoted _ ils) = ils- flattenInline (Cite _ ils) = ils- flattenInline Code{} = []- flattenInline Space = []- flattenInline SoftBreak = []- flattenInline LineBreak = []- flattenInline Math{} = []- flattenInline RawInline{} = []- flattenInline (Link _ ils _) = ils- flattenInline (Image _ ils _) = ils- flattenInline Note{} = []- flattenInline (Span _ ils) = ils+ arbitrary = liftM (fromList :: [Inline] -> Inlines) arbitrary instance Arbitrary Blocks where- arbitrary = (fromList :: [Block] -> Blocks) <$> arbitrary- shrink = fmap fromList . ((++) <$> shrink <*> flattenShrinkBlocks) . toList- where flattenShrinkBlocks (x:xs) =- let x' = flattenBlock x- in (if null x' then [] else [x' ++ xs]) ++ [x:xs' | xs' <- flattenShrinkBlocks xs]- flattenShrinkBlocks [] = []- flattenBlock :: Block -> [Block]- flattenBlock Plain{} = []- flattenBlock Para{} = []- flattenBlock (LineBlock lns) = [Para x | x <- lns]- flattenBlock CodeBlock{} = []- flattenBlock RawBlock{} = []- flattenBlock (BlockQuote blks) = blks- flattenBlock (OrderedList _ blksList) = concat blksList- flattenBlock (BulletList blksList) = concat blksList- flattenBlock (DefinitionList defs) = concat [Para ils:concat blks | (ils, blks) <- defs]- flattenBlock (Header _ _ ils) = [Para ils]- flattenBlock HorizontalRule = []- flattenBlock (Table caption _ _ cells rows) = Para caption : concat (concat $ cells:rows)- flattenBlock (Div _ blks) = blks- flattenBlock Null = []--shrinkInlineList :: [Inline] -> [[Inline]]-shrinkInlineList = fmap toList . shrink . fromList--shrinkInlinesList :: [[Inline]] -> [[[Inline]]]-shrinkInlinesList = fmap (fmap toList) . shrink . fmap fromList--shrinkBlockList :: [Block] -> [[Block]]-shrinkBlockList = fmap toList . shrink . fromList--shrinkBlocksList :: [[Block]] -> [[[Block]]]-shrinkBlocksList = fmap (fmap toList) . shrink . fmap fromList+ arbitrary = liftM (fromList :: [Block] -> Blocks) arbitrary instance Arbitrary Inline where arbitrary = resize 3 $ arbInline 2- shrink (Str s) = Str <$> shrink s- shrink (Emph ils) = Emph <$> shrinkInlineList ils- shrink (Strong ils) = Strong <$> shrinkInlineList ils- shrink (Strikeout ils) = Strikeout <$> shrinkInlineList ils- shrink (Superscript ils) = Superscript <$> shrinkInlineList ils- shrink (Subscript ils) = Subscript <$> shrinkInlineList ils- shrink (SmallCaps ils) = SmallCaps <$> shrinkInlineList ils- shrink (Quoted qtype ils) = Quoted qtype <$> shrinkInlineList ils- shrink (Cite cits ils) = (Cite cits <$> shrinkInlineList ils)- ++ (flip Cite ils <$> shrink cits)- shrink (Code attr s) = (Code attr <$> shrink s)- ++ (flip Code s <$> shrink attr)- shrink Space = []- shrink SoftBreak = []- shrink LineBreak = []- shrink (Math mtype s) = Math mtype <$> shrink s- shrink (RawInline fmt s) = RawInline fmt <$> shrink s- shrink (Link attr ils target) = [Link attr ils' target | ils' <- shrinkInlineList ils]- ++ [Link attr ils target' | target' <- shrink target]- ++ [Link attr' ils target | attr' <- shrink attr]- shrink (Image attr ils target) = [Image attr ils' target | ils' <- shrinkInlineList ils]- ++ [Image attr ils target' | target' <- shrink target]- ++ [Image attr' ils target | attr' <- shrink attr]- shrink (Note blks) = Note <$> shrinkBlockList blks- shrink (Span attr s) = (Span attr <$> shrink s)- ++ (flip Span s <$> shrink attr) arbInlines :: Int -> Gen [Inline] arbInlines n = listOf1 (arbInline n) `suchThat` (not . startsWithSpace)- where startsWithSpace (Space:_) = True- startsWithSpace (SoftBreak:_) = True- -- Note: no LineBreak, similarly to Text.Pandoc.Builder (trimInlines)- startsWithSpace _ = False+ where startsWithSpace (Space:_) = True+ startsWithSpace _ = False -- restrict to 3 levels of nesting max; otherwise we get -- bogged down in indefinitely large structures arbInline :: Int -> Gen Inline-arbInline n = frequency $ [ (60, Str <$> realString)- , (40, pure Space)- , (10, pure SoftBreak)- , (10, pure LineBreak)- , (10, Code <$> arbAttr <*> realString)+arbInline n = frequency $ [ (60, liftM Str realString)+ , (60, return Space)+ , (10, liftM2 Code arbAttr realString) , (5, elements [ RawInline (Format "html") "<a id=\"eek\">" , RawInline (Format "latex") "\\my{command}" ])- ] ++ [ x | n > 1, x <- nesters]- where nesters = [ (10, Emph <$> arbInlines (n-1))- , (10, Strong <$> arbInlines (n-1))- , (10, Strikeout <$> arbInlines (n-1))- , (10, Superscript <$> arbInlines (n-1))- , (10, Subscript <$> arbInlines (n-1))- , (10, SmallCaps <$> arbInlines (n-1))- , (10, Span <$> arbAttr <*> arbInlines (n-1))- , (10, Quoted <$> arbitrary <*> arbInlines (n-1))- , (10, Math <$> arbitrary <*> realString)- , (10, Link <$> arbAttr <*> arbInlines (n-1) <*> ((,) <$> realString <*> realString))- , (10, Image <$> arbAttr <*> arbInlines (n-1) <*> ((,) <$> realString <*> realString))- , (2, Cite <$> arbitrary <*> arbInlines 1)- , (2, Note <$> resize 3 (listOf1 $ arbBlock (n-1)))+ ] ++ [ x | x <- nesters, n > 1]+ where nesters = [ (10, liftM Emph $ arbInlines (n-1))+ , (10, liftM Strong $ arbInlines (n-1))+ , (10, liftM Strikeout $ arbInlines (n-1))+ , (10, liftM Superscript $ arbInlines (n-1))+ , (10, liftM Subscript $ arbInlines (n-1))+ , (10, liftM SmallCaps $ arbInlines (n-1))+ , (10, do x1 <- arbitrary+ x2 <- arbInlines (n-1)+ return $ Quoted x1 x2)+ , (10, do x1 <- arbitrary+ x2 <- realString+ return $ Math x1 x2)+ , (10, do x0 <- arbAttr+ x1 <- arbInlines (n-1)+ x3 <- realString+ x2 <- realString+ return $ Link x0 x1 (x2,x3))+ , (10, do x0 <- arbAttr+ x1 <- arbInlines (n-1)+ x3 <- realString+ x2 <- realString+ return $ Image x0 x1 (x2,x3))+ , (2, liftM2 Cite arbitrary (arbInlines 1))+ , (2, liftM Note $ resize 3 $ listOf1 $ arbBlock (n-1)) ] instance Arbitrary Block where arbitrary = resize 3 $ arbBlock 2- shrink (Plain ils) = Plain <$> shrinkInlineList ils- shrink (Para ils) = Para <$> shrinkInlineList ils- shrink (LineBlock lns) = LineBlock <$> shrinkInlinesList lns- shrink (CodeBlock attr s) = (CodeBlock attr <$> shrink s)- ++ (flip CodeBlock s <$> shrink attr)- shrink (RawBlock fmt s) = RawBlock fmt <$> shrink s- shrink (BlockQuote blks) = BlockQuote <$> shrinkBlockList blks- shrink (OrderedList listAttrs blksList) = OrderedList listAttrs <$> shrinkBlocksList blksList- shrink (BulletList blksList) = BulletList <$> shrinkBlocksList blksList- shrink (DefinitionList defs) = DefinitionList <$> shrinkDefinitionList defs- where shrinkDefinition (ils, blksList) = [(ils', blksList) | ils' <- shrinkInlineList ils]- ++ [(ils, blksList') | blksList' <- shrinkBlocksList blksList]- shrinkDefinitionList (x:xs) = [xs]- ++ [x':xs | x' <- shrinkDefinition x]- ++ [x:xs' | xs' <- shrinkDefinitionList xs]- shrinkDefinitionList [] = []- shrink (Header n attr ils) = (Header n attr <$> shrinkInlineList ils)- ++ (flip (Header n) ils <$> shrink attr)- shrink HorizontalRule = []- shrink (Table caption aligns widths cells rows) =- -- TODO: shrink number of columns- -- Shrink header contents- [Table caption aligns widths cells' rows | cells' <- shrinkRow cells] ++- -- Shrink number of rows and row contents- [Table caption aligns widths cells rows' | rows' <- shrinkRows rows] ++- -- Shrink caption- [Table caption' aligns widths cells rows | caption' <- shrinkInlineList caption]- where -- Shrink row contents without reducing the number of columns- shrinkRow :: [TableCell] -> [[TableCell]]- shrinkRow (x:xs) = [x':xs | x' <- shrinkBlockList x]- ++ [x:xs' | xs' <- shrinkRow xs]- shrinkRow [] = []- shrinkRows :: [[TableCell]] -> [[[TableCell]]]- shrinkRows (x:xs) = [xs] -- Shrink number of rows- ++ [x':xs | x' <- shrinkRow x] -- Shrink row contents- ++ [x:xs' | xs' <- shrinkRows xs]- shrinkRows [] = []- shrink (Div attr blks) = (Div attr <$> shrinkBlockList blks)- ++ (flip Div blks <$> shrink attr)- shrink Null = [] arbBlock :: Int -> Gen Block-arbBlock n = frequency $ [ (10, Plain <$> arbInlines (n-1))- , (15, Para <$> arbInlines (n-1))- , (5, CodeBlock <$> arbAttr <*> realString)- , (3, LineBlock <$>- ((:) <$>- arbInlines ((n - 1) `mod` 3) <*>- forM [1..((n - 1) `div` 3)] (const (arbInlines 3))))+arbBlock n = frequency $ [ (10, liftM Plain $ arbInlines (n-1))+ , (15, liftM Para $ arbInlines (n-1))+ , (5, liftM2 CodeBlock arbAttr realString)+ , (3, liftM LineBlock $+ liftM2 (:)+ (arbInlines $ (n - 1) `mod` 3)+ (forM [1..((n - 1) `div` 3)]+ (const $ arbInlines 3))) , (2, elements [ RawBlock (Format "html") "<div>\n*&*\n</div>" , RawBlock (Format "latex") "\\begin[opt]{env}\nhi\n{\\end{env}" ])- , (5, Header <$> choose (1 :: Int, 6)- <*> pure nullAttr- <*> arbInlines (n-1))- , (2, pure HorizontalRule)- ] ++ [x | n > 0, x <- nesters]- where nesters = [ (5, BlockQuote <$> listOf1 (arbBlock (n-1)))- , (5, OrderedList <$> ((,,) <$> (arbitrary `suchThat` (> 0))- <*> arbitrary- <*> arbitrary)- <*> listOf1 (listOf1 $ arbBlock (n-1)))- , (5, BulletList <$> listOf1 (listOf1 $ arbBlock (n-1)))- , (5, DefinitionList <$> listOf1 ((,) <$> arbInlines (n-1)- <*> listOf1 (listOf1 $ arbBlock (n-1))))- , (5, Div <$> arbAttr <*> listOf1 (arbBlock (n-1)))+ , (5, do x1 <- choose (1 :: Int, 6)+ x2 <- arbInlines (n-1)+ return (Header x1 nullAttr x2))+ , (2, return HorizontalRule)+ ] ++ [x | x <- nesters, n > 0]+ where nesters = [ (5, liftM BlockQuote $ listOf1 $ arbBlock (n-1))+ , (5, do x2 <- arbitrary+ x3 <- arbitrary+ x1 <- arbitrary `suchThat` (> 0)+ x4 <- listOf1 $ listOf1 $ arbBlock (n-1)+ return $ OrderedList (x1,x2,x3) x4 )+ , (5, liftM BulletList $ (listOf1 $ listOf1 $ arbBlock (n-1)))+ , (5, do items <- listOf1 $ do+ x1 <- listOf1 $ listOf1 $ arbBlock (n-1)+ x2 <- arbInlines (n-1)+ return (x2,x1)+ return $ DefinitionList items) , (2, do rs <- choose (1 :: Int, 4) cs <- choose (1 :: Int, 4)- Table <$> arbInlines (n-1)- <*> vector cs- <*> vectorOf cs (elements [0, 0.25])- <*> vectorOf cs (listOf $ arbBlock (n-1))- <*> vectorOf rs (vectorOf cs $ listOf $ arbBlock (n-1)))+ x1 <- arbInlines (n-1)+ x2 <- vector cs+ x3 <- vectorOf cs $ elements [0, 0.25]+ x4 <- vectorOf cs $ listOf $ arbBlock (n-1)+ x5 <- vectorOf rs $ vectorOf cs+ $ listOf $ arbBlock (n-1)+ return (Table x1 x2 x3 x4 x5)) ] instance Arbitrary Pandoc where- arbitrary = resize 8 (Pandoc <$> arbitrary <*> arbitrary)+ arbitrary = resize 8 $ liftM2 Pandoc arbitrary arbitrary instance Arbitrary CitationMode where arbitrary@@ -238,12 +127,13 @@ instance Arbitrary Citation where arbitrary- = Citation <$> listOf (elements $ ['a'..'z'] ++ ['0'..'9'] ++ ['_'])- <*> arbInlines 1- <*> arbInlines 1- <*> arbitrary- <*> arbitrary- <*> arbitrary+ = do x1 <- listOf $ elements $ ['a'..'z'] ++ ['0'..'9'] ++ ['_']+ x2 <- arbInlines 1+ x3 <- arbInlines 1+ x4 <- arbitrary+ x5 <- arbitrary+ x6 <- arbitrary+ return (Citation x1 x2 x3 x4 x5 x6) instance Arbitrary MathType where arbitrary@@ -264,12 +154,12 @@ instance Arbitrary Meta where arbitrary = do (x1 :: Inlines) <- arbitrary- (x2 :: [Inlines]) <- filter (not . isNull) <$> arbitrary+ (x2 :: [Inlines]) <- liftM (filter (not . isNull)) arbitrary (x3 :: Inlines) <- arbitrary return $ setMeta "title" x1 $ setMeta "author" x2 $ setMeta "date" x3- nullMeta+ $ nullMeta instance Arbitrary Alignment where arbitrary
Text/Pandoc/Builder.hs view
@@ -1,8 +1,8 @@-{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, DeriveDataTypeable,- GeneralizedNewtypeDeriving, CPP, StandaloneDeriving, DeriveGeneric,- DeriveTraversable #-}+{-# LANGUAGE TypeSynonymInstances, FlexibleInstances, MultiParamTypeClasses,+ DeriveDataTypeable, GeneralizedNewtypeDeriving, CPP, StandaloneDeriving,+ DeriveGeneric, DeriveTraversable #-} {--Copyright (C) 2010-2019 John MacFarlane+Copyright (C) 2010-2016 John MacFarlane All rights reserved. @@ -36,7 +36,7 @@ {- | Module : Text.Pandoc.Builder- Copyright : Copyright (C) 2010-2019 John MacFarlane+ Copyright : Copyright (C) 2010-2016 John MacFarlane License : BSD3 Maintainer : John MacFarlane <jgm@berkeley.edu>@@ -166,6 +166,7 @@ where import Text.Pandoc.Definition import Data.String+import Data.Monoid import qualified Data.Map as M import Data.Sequence (Seq, (|>), viewr, viewl, ViewR(..), ViewL(..)) import qualified Data.Sequence as Seq@@ -176,8 +177,18 @@ import Data.Data import Control.Arrow ((***)) import GHC.Generics (Generic)-import Data.Semigroup (Semigroup(..)) +#if MIN_VERSION_base(4,5,0)+-- (<>) is defined in Data.Monoid+#else+infixr 6 <>++-- | An infix synonym for 'mappend'.+(<>) :: Monoid m => m -> m -> m+(<>) = mappend+{-# INLINE (<>) #-}+#endif+ newtype Many a = Many { unMany :: Seq a } deriving (Data, Ord, Eq, Typeable, Foldable, Traversable, Functor, Show, Read) @@ -198,15 +209,15 @@ type Inlines = Many Inline type Blocks = Many Block -deriving instance Semigroup Blocks deriving instance Monoid Blocks -instance Semigroup Inlines where- (Many xs) <> (Many ys) =+instance Monoid Inlines where+ mempty = Many mempty+ (Many xs) `mappend` (Many ys) = case (viewr xs, viewl ys) of (EmptyR, _) -> Many ys (_, EmptyL) -> Many xs- (xs' :> x, y :< ys') -> Many (meld <> ys')+ (xs' :> x, y :< ys') -> Many (meld `mappend` ys') where meld = case (x, y) of (Space, Space) -> xs' |> Space (Space, SoftBreak) -> xs' |> SoftBreak@@ -223,9 +234,6 @@ (LineBreak, SoftBreak) -> xs' |> LineBreak (SoftBreak, SoftBreak) -> xs' |> SoftBreak _ -> xs' |> x |> y-instance Monoid Inlines where- mempty = Many mempty- mappend = (<>) instance IsString Inlines where fromString = text@@ -266,9 +274,6 @@ instance ToMetaValue Bool where toMetaValue = MetaBool -instance {-# OVERLAPPING #-} ToMetaValue String where- toMetaValue = MetaString- instance ToMetaValue a => ToMetaValue [a] where toMetaValue = MetaList . map toMetaValue @@ -305,7 +310,8 @@ text :: String -> Inlines text = fromList . map conv . breakBySpaces where breakBySpaces = groupBy sameCategory- sameCategory x y = is_space x == is_space y+ sameCategory x y = (is_space x && is_space y) ||+ (not $ is_space x || is_space y) conv xs | all is_space xs = if any is_newline xs then SoftBreak@@ -465,30 +471,26 @@ horizontalRule :: Blocks horizontalRule = singleton HorizontalRule --- | Table builder. Rows and headers will be padded or truncated to the size of--- @cellspecs@ table :: Inlines -- ^ Caption -> [(Alignment, Double)] -- ^ Column alignments and fractional widths -> [Blocks] -- ^ Headers -> [[Blocks]] -- ^ Rows -> Blocks table caption cellspecs headers rows = singleton $- Table (toList caption) aligns widths (sanitise headers) (map sanitise rows)+ Table (toList caption) aligns widths+ (map toList headers) (map (map toList) rows) where (aligns, widths) = unzip cellspecs- sanitise = map toList . pad mempty numcols- numcols = length cellspecs- pad element upTo list = take upTo (list ++ repeat element) -- | A simple table without a caption. simpleTable :: [Blocks] -- ^ Headers -> [[Blocks]] -- ^ Rows -> Blocks-simpleTable headers rows =- table mempty (replicate numcols defaults) headers rows+simpleTable headers = table mempty (mapConst defaults headers) headers where defaults = (AlignDefault, 0)- numcols = case headers:rows of- [] -> 0- xs -> maximum (map length xs) divWith :: Attr -> Blocks -> Blocks divWith attr = singleton . Div attr . toList++mapConst :: Functor f => b -> f a -> f b+mapConst = fmap . const+
Text/Pandoc/Definition.hs view
@@ -1,8 +1,8 @@ {-# LANGUAGE OverloadedStrings, DeriveDataTypeable, DeriveGeneric,- FlexibleContexts, GeneralizedNewtypeDeriving, PatternGuards, CPP #-}+FlexibleContexts, GeneralizedNewtypeDeriving, PatternGuards, CPP #-} {--Copyright (c) 2006-2019, John MacFarlane+Copyright (c) 2006-2016, John MacFarlane All rights reserved. @@ -36,7 +36,7 @@ {- | Module : Text.Pandoc.Definition- Copyright : Copyright (C) 2006-2019 John MacFarlane+ Copyright : Copyright (C) 2006-2016 John MacFarlane License : BSD3 Maintainer : John MacFarlane <jgm@berkeley.edu>@@ -81,32 +81,33 @@ import GHC.Generics (Generic) import Data.String import Data.Char (toLower)+#if MIN_VERSION_base(4,8,0) import Control.DeepSeq+#else+import Data.Monoid+import Control.Applicative ((<$>), (<*>))+import Control.DeepSeq.Generics+#endif import Paths_pandoc_types (version) import Data.Version (Version, versionBranch)-import Data.Semigroup (Semigroup(..)) data Pandoc = Pandoc Meta [Block] deriving (Eq, Ord, Read, Show, Typeable, Data, Generic) -instance Semigroup Pandoc where- (Pandoc m1 bs1) <> (Pandoc m2 bs2) =- Pandoc (m1 <> m2) (bs1 <> bs2) instance Monoid Pandoc where mempty = Pandoc mempty mempty- mappend = (<>)+ (Pandoc m1 bs1) `mappend` (Pandoc m2 bs2) =+ Pandoc (m1 `mappend` m2) (bs1 `mappend` bs2) -- | Metadata for the document: title, authors, date. newtype Meta = Meta { unMeta :: M.Map String MetaValue } deriving (Eq, Ord, Show, Read, Typeable, Data, Generic) -instance Semigroup Meta where- (Meta m1) <> (Meta m2) = Meta (M.union m1 m2)+instance Monoid Meta where+ mempty = Meta (M.empty)+ (Meta m1) `mappend` (Meta m2) = Meta (M.union m1 m2) -- note: M.union is left-biased, so if there are fields in both m1 -- and m2, m1 wins.-instance Monoid Meta where- mempty = Meta M.empty- mappend = (<>) data MetaValue = MetaMap (M.Map String MetaValue) | MetaList [MetaValue]@@ -167,8 +168,7 @@ | AlignCenter | AlignDefault deriving (Eq, Ord, Show, Read, Typeable, Data, Generic) --- | List attributes. The first element of the triple is the--- start number of the list.+-- | List attributes. type ListAttributes = (Int, ListNumberStyle, ListNumberDelim) -- | Style of list numbers.@@ -286,10 +286,10 @@ -- ToJSON/FromJSON instances. We do this by hand instead of deriving -- from generics, so we can have more control over the format. -taggedNoContent :: String -> Value+taggedNoContent :: [Char] -> Value taggedNoContent x = object [ "t" .= x ] -tagged :: ToJSON a => String -> a -> Value+tagged :: ToJSON a => [Char] -> a -> Value tagged x y = object [ "t" .= x, "c" .= y ] instance FromJSON MetaValue where@@ -523,12 +523,12 @@ "DefinitionList" -> DefinitionList <$> v .: "c" "Header" -> do (n, attr, ils) <- v .: "c" return $ Header n attr ils- "HorizontalRule" -> return HorizontalRule+ "HorizontalRule" -> return $ HorizontalRule "Table" -> do (cpt, align, wdths, hdr, rows) <- v .: "c" return $ Table cpt align wdths hdr rows "Div" -> do (attr, blks) <- v .: "c" return $ Div attr blks- "Null" -> return Null+ "Null" -> return $ Null _ -> mempty parseJSON _ = mempty instance ToJSON Block where@@ -574,6 +574,7 @@ ] -- Instances for deepseq+#if MIN_VERSION_base(4,8,0) instance NFData MetaValue instance NFData Meta instance NFData Citation@@ -587,6 +588,21 @@ instance NFData ListNumberStyle instance NFData Block instance NFData Pandoc+#else+instance NFData MetaValue where rnf = genericRnf+instance NFData Meta where rnf = genericRnf+instance NFData Citation where rnf = genericRnf+instance NFData Alignment where rnf = genericRnf+instance NFData Inline where rnf = genericRnf+instance NFData MathType where rnf = genericRnf+instance NFData Format where rnf = genericRnf+instance NFData CitationMode where rnf = genericRnf+instance NFData QuoteType where rnf = genericRnf+instance NFData ListNumberDelim where rnf = genericRnf+instance NFData ListNumberStyle where rnf = genericRnf+instance NFData Block where rnf = genericRnf+instance NFData Pandoc where rnf = genericRnf+#endif pandocTypesVersion :: Version pandocTypesVersion = version
Text/Pandoc/Generic.hs view
@@ -1,6 +1,6 @@ {-# LANGUAGE CPP #-} {--Copyright (c) 2006-2019, John MacFarlane+Copyright (c) 2006-2016, John MacFarlane All rights reserved. @@ -34,7 +34,7 @@ {- | Module : Text.Pandoc.Generic- Copyright : Copyright (C) 2006-2019 John MacFarlane+ Copyright : Copyright (C) 2006-2010 John MacFarlane License : BSD3 Maintainer : John MacFarlane <jgm@berkeley.edu>@@ -120,6 +120,10 @@ module Text.Pandoc.Generic where import Data.Generics+#if MIN_VERSION_base(4,8,0)+#else+import Data.Monoid+#endif -- | Applies a transformation on @a@s to matching elements in a @b@, -- moving from the bottom of the structure up.
Text/Pandoc/JSON.hs view
@@ -1,6 +1,6 @@ {-# LANGUAGE FlexibleInstances, FlexibleContexts #-} {--Copyright (c) 2013-2019, John MacFarlane+Copyright (c) 2013-2016, John MacFarlane All rights reserved. @@ -34,7 +34,7 @@ {- | Module : Text.Pandoc.JSON- Copyright : Copyright (C) 2013-2019 John MacFarlane+ Copyright : Copyright (C) 2013-2016 John MacFarlane License : BSD3 Maintainer : John MacFarlane <jgm@berkeley.edu>@@ -74,7 +74,9 @@ where import Text.Pandoc.Definition import Text.Pandoc.Walk+import Text.Pandoc.Generic import Data.Maybe (listToMaybe)+import Data.Data import qualified Data.ByteString.Lazy as BL import Data.Aeson import System.Environment (getArgs)@@ -111,14 +113,14 @@ (walkM f :: Pandoc -> IO Pandoc) . either error id . eitherDecode' >>= BL.putStr . encode -instance (Walkable [a] Pandoc) => ToJSONFilter (a -> [a]) where+instance Data a => ToJSONFilter (a -> [a]) where toJSONFilter f = BL.getContents >>=- BL.putStr . encode . (walk (concatMap f) :: Pandoc -> Pandoc) .+ BL.putStr . encode . (bottomUp (concatMap f) :: Pandoc -> Pandoc) . either error id . eitherDecode' -instance (Walkable [a] Pandoc) => ToJSONFilter (a -> IO [a]) where+instance Data a => ToJSONFilter (a -> IO [a]) where toJSONFilter f = BL.getContents >>=- (walkM (fmap concat . mapM f) :: Pandoc -> IO Pandoc) .+ (bottomUpM (fmap concat . mapM f) :: Pandoc -> IO Pandoc) . either error id . eitherDecode' >>= BL.putStr . encode
Text/Pandoc/Walk.hs view
@@ -1,14 +1,15 @@-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE CPP #-}+{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, ScopedTypeVariables, CPP #-} #if MIN_VERSION_base(4,9,0)-{-# OPTIONS_GHC -fno-warn-redundant-constraints -O2 #-}+{-# OPTIONS_GHC -fno-warn-redundant-constraints #-} #endif+#if MIN_VERSION_base(4,8,0) #define OVERLAPS {-# OVERLAPPING #-}+#else+{-# LANGUAGE OverlappingInstances #-}+#define OVERLAPS+#endif {--Copyright (c) 2013-2019, John MacFarlane+Copyright (c) 2013-2016, John MacFarlane All rights reserved. @@ -42,7 +43,7 @@ {- | Module : Text.Pandoc.Walk- Copyright : Copyright (C) 2013-2019 John MacFarlane+ Copyright : Copyright (C) 2013 John MacFarlane License : BSD3 Maintainer : John MacFarlane <jgm@berkeley.edu>@@ -86,48 +87,35 @@ -} -module Text.Pandoc.Walk- ( Walkable(..)- , queryBlock- , queryCitation- , queryInline- , queryMetaValue- , queryPandoc- , walkBlockM- , walkCitationM- , walkInlineM- , walkMetaValueM- , walkPandocM- )+module Text.Pandoc.Walk (Walkable(..)) where-import Control.Applicative (Applicative ((<*>), pure), (<$>))-import Control.Monad ((>=>))-import Data.Functor.Identity (Identity (runIdentity))+import Control.Applicative ((<$>)) import Text.Pandoc.Definition import qualified Data.Traversable as T import Data.Traversable (Traversable) import qualified Data.Foldable as F import Data.Foldable (Foldable)+#if MIN_VERSION_base(4,8,0) import Data.Monoid ((<>))+#else+import Data.Monoid+#endif class Walkable a b where -- | @walk f x@ walks the structure @x@ (bottom up) and replaces every -- occurrence of an @a@ with the result of applying @f@ to it. walk :: (a -> a) -> b -> b- walk f = runIdentity . walkM (return . f) -- | A monadic version of 'walk'.- walkM :: (Monad m, Applicative m, Functor m) => (a -> m a) -> b -> m b+ walkM :: (Monad m, Functor m) => (a -> m a) -> b -> m b -- | @query f x@ walks the structure @x@ (bottom up) and applies @f@ -- to every @a@, appending the results. query :: Monoid c => (a -> c) -> b -> c- {-# MINIMAL walkM, query #-} instance (Foldable t, Traversable t, Walkable a b) => Walkable a (t b) where walk f = T.fmapDefault (walk f) walkM f = T.mapM (walkM f) query f = F.foldMap (query f) --- Walk pairs by handling both elements, then combine the results. instance OVERLAPS (Walkable a b, Walkable a c) => Walkable a (b,c) where walk f (x,y) = (walk f x, walk f y)@@ -137,287 +125,326 @@ query f (x,y) = mappend (query f x) (query f y) instance Walkable Inline Inline where- walkM f x = walkInlineM f x >>= f- query f x = f x <> queryInline f x+ walk f (Str xs) = f $ Str xs+ walk f (Emph xs) = f $ Emph (walk f xs)+ walk f (Strong xs) = f $ Strong (walk f xs)+ walk f (Strikeout xs) = f $ Strikeout (walk f xs)+ walk f (Subscript xs) = f $ Subscript (walk f xs)+ 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 (walk f cs) (walk f xs)+ walk f (Code attr s) = f $ Code attr s+ walk f Space = f Space+ walk f SoftBreak = f SoftBreak+ walk f LineBreak = f LineBreak+ walk f (Math mt s) = f (Math mt s)+ walk f (RawInline t s) = f $ RawInline t s+ walk f (Link atr xs t) = f $ Link atr (walk f xs) t+ walk f (Image atr xs t) = f $ Image atr (walk f xs) t+ walk f (Note bs) = f $ Note (walk f bs)+ walk f (Span attr xs) = f $ Span attr (walk f xs) -instance OVERLAPS- Walkable [Inline] [Inline] where- walkM f = T.traverse (walkInlineM f) >=> f- query f inlns = f inlns <> mconcat (map (queryInline f) inlns)+ walkM f (Str xs) = f $ Str xs+ walkM f (Emph xs) = Emph <$> walkM f xs >>= f+ walkM f (Strong xs) = Strong <$> walkM f xs >>= f+ walkM f (Strikeout xs) = Strikeout <$> walkM f xs >>= f+ walkM f (Subscript xs) = Subscript <$> walkM f xs >>= f+ 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) = 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 SoftBreak = f SoftBreak+ walkM f LineBreak = f LineBreak+ walkM f (Math mt s) = f (Math mt s)+ walkM f (RawInline t s) = f $ RawInline t s+ walkM f (Link atr xs t) = Link atr <$> walkM f xs >>= f . ($ t)+ walkM f (Image atr xs t)= Image atr <$> walkM f xs >>= f . ($ t)+ walkM f (Note bs) = Note <$> walkM f bs >>= f+ walkM f (Span attr xs) = Span attr <$> walkM f xs >>= f -instance Walkable [Inline] Inline where- walkM = walkInlineM- query = queryInline+ query f (Str xs) = f (Str xs)+ query f (Emph xs) = f (Emph xs) <> query f xs+ query f (Strong xs) = f (Strong xs) <> query f xs+ query f (Strikeout xs) = f (Strikeout xs) <> query f xs+ query f (Subscript xs) = f (Subscript xs) <> query f xs+ 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 cs <> query f xs+ query f (Code attr s) = f (Code attr s)+ query f Space = f Space+ query f SoftBreak = f SoftBreak+ query f LineBreak = f LineBreak+ query f (Math mt s) = f (Math mt s)+ query f (RawInline t s) = f (RawInline t s)+ query f (Link atr xs t) = f (Link atr xs t) <> query f xs+ query f (Image atr xs t)= f (Image atr xs t) <> query f xs+ query f (Note bs) = f (Note bs) <> query f bs+ query f (Span attr xs) = f (Span attr xs) <> query f xs instance Walkable Inline Block where- walkM = walkBlockM- query = queryBlock+ walk f (Para xs) = Para $ walk f xs+ walk f (Plain xs) = Plain $ walk f xs+ walk f (LineBlock xs) = LineBlock $ walk f xs+ walk _ (CodeBlock attr s) = CodeBlock attr s+ walk _ (RawBlock t s) = RawBlock t s+ walk f (BlockQuote bs) = BlockQuote $ walk f bs+ walk f (OrderedList a cs) = OrderedList a $ walk f cs+ walk f (BulletList cs) = BulletList $ walk f cs+ walk f (DefinitionList xs) = DefinitionList $ walk f xs+ walk f (Header lev attr xs) = Header lev attr $ walk f xs+ walk _ HorizontalRule = HorizontalRule+ walk f (Table capt as ws hs rs) = Table (walk f capt) as ws (walk f hs) (walk f rs)+ walk f (Div attr bs) = Div attr (walk f bs)+ walk _ Null = Null -instance Walkable [Inline] Block where- walkM = walkBlockM- query = queryBlock+ walkM f (Para xs) = Para <$> walkM f xs+ walkM f (Plain xs) = Plain <$> walkM f xs+ walkM f (LineBlock xs) = LineBlock <$> walkM f xs+ walkM _ (CodeBlock attr s) = return $ CodeBlock attr s+ walkM _ (RawBlock t s) = return $ RawBlock t s+ walkM f (BlockQuote bs) = BlockQuote <$> walkM f bs+ walkM f (OrderedList a cs) = OrderedList a <$> walkM f cs+ walkM f (BulletList cs) = BulletList <$> walkM f cs+ walkM f (DefinitionList xs) = DefinitionList <$> walkM f xs+ walkM f (Header lev attr xs) = Header lev attr <$> walkM f xs+ walkM _ HorizontalRule = return HorizontalRule+ walkM f (Table capt as ws hs rs) = do+ capt' <- walkM f capt+ hs' <- walkM f hs+ rs' <- walkM f rs+ return $ Table capt' as ws hs' rs'+ walkM f (Div attr bs) = Div attr <$> (walkM f bs)+ walkM _ Null = return Null + query f (Para xs) = query f xs+ query f (Plain xs) = query f xs+ query f (LineBlock xs) = query f xs+ query _ (CodeBlock _ _) = mempty+ query _ (RawBlock _ _) = mempty+ query f (BlockQuote bs) = query f bs+ query f (OrderedList _ cs) = query f cs+ query f (BulletList cs) = query f cs+ query f (DefinitionList xs) = query f xs+ query f (Header _ _ xs) = query f xs+ query _ HorizontalRule = mempty+ query f (Table capt _ _ hs rs) = query f capt <> query f hs <> query f rs+ query f (Div _ bs) = query f bs+ query _ Null = mempty+ instance Walkable Block Block where- walkM f x = walkBlockM f x >>= f- query f x = f x <> queryBlock f x+ walk f (Para xs) = f $ Para $ walk f xs+ walk f (Plain xs) = f $ Plain $ walk f xs+ walk f (LineBlock xs) = f $ LineBlock $ walk f xs+ walk f (CodeBlock attr s) = f $ CodeBlock attr s+ walk f (RawBlock t s) = f $ RawBlock t s+ walk f (BlockQuote bs) = f $ BlockQuote $ walk f bs+ walk f (OrderedList a cs) = f $ OrderedList a $ walk f cs+ walk f (BulletList cs) = f $ BulletList $ walk f cs+ walk f (DefinitionList xs) = f $ DefinitionList $ walk f xs+ walk f (Header lev attr xs) = f $ Header lev attr $ walk f xs+ walk f HorizontalRule = f $ HorizontalRule+ walk f (Table capt as ws hs rs) = f $ Table (walk f capt) as ws (walk f hs)+ (walk f rs)+ walk f (Div attr bs) = f $ Div attr (walk f bs)+ walk _ Null = Null -instance Walkable [Block] Block where- walkM = walkBlockM- query = queryBlock+ walkM f (Para xs) = Para <$> walkM f xs >>= f+ walkM f (Plain xs) = Plain <$> walkM f xs >>= f+ walkM f (LineBlock xs) = LineBlock <$> walkM f xs >>= f+ walkM f (CodeBlock attr s) = f $ CodeBlock attr s+ walkM f (RawBlock t s) = f $ RawBlock t s+ walkM f (BlockQuote bs) = BlockQuote <$> walkM f bs >>= f+ walkM f (OrderedList a cs) = OrderedList a <$> walkM f cs >>= f+ walkM f (BulletList cs) = BulletList <$> walkM f cs >>= f+ walkM f (DefinitionList xs) = DefinitionList <$> walkM f xs >>= f+ walkM f (Header lev attr xs) = Header lev attr <$> walkM f xs >>= f+ walkM f HorizontalRule = f $ HorizontalRule+ walkM f (Table capt as ws hs rs) = do capt' <- walkM f capt+ hs' <- walkM f hs+ rs' <- walkM f rs+ f $ Table capt' as ws hs' rs'+ walkM f (Div attr bs) = Div attr <$> walkM f bs >>= f+ walkM f Null = f Null -instance OVERLAPS- Walkable [Block] [Block] where- walkM f = T.traverse (walkBlockM f) >=> f- query f blks = f blks <> mconcat (map (queryBlock f) blks)+ query f (Para xs) = f (Para xs) <> query f xs+ query f (Plain xs) = f (Plain xs) <> query f xs+ query f (LineBlock xs) = f (LineBlock xs) <> query f xs+ query f (CodeBlock attr s) = f $ CodeBlock attr s+ query f (RawBlock t s) = f $ RawBlock t s+ query f (BlockQuote bs) = f (BlockQuote bs) <> query f bs+ query f (OrderedList a cs) = f (OrderedList a cs) <> query f cs+ query f (BulletList cs) = f (BulletList cs) <> query f cs+ query f (DefinitionList xs) = f (DefinitionList xs) <> query f xs+ query f (Header lev attr xs) = f (Header lev attr xs) <> query f xs+ query f HorizontalRule = f $ HorizontalRule+ query f (Table capt as ws hs rs) = f (Table capt as ws hs rs) <>+ query f capt <> query f hs <> query f rs+ query f (Div attr bs) = f (Div attr bs) <> query f bs+ query f Null = f Null instance Walkable Block Inline where- walkM = walkInlineM- query = queryInline+ walk _ (Str xs) = Str xs+ walk f (Emph xs) = Emph (walk f xs)+ walk f (Strong xs) = Strong (walk f xs)+ walk f (Strikeout xs) = Strikeout (walk f xs)+ walk f (Subscript xs) = Subscript (walk f xs)+ 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 (walk f cs) (walk f xs)+ walk _ (Code attr s) = Code attr s+ walk _ Space = Space+ walk _ SoftBreak = SoftBreak+ walk _ LineBreak = LineBreak+ walk _ (Math mt s) = Math mt s+ walk _ (RawInline t s) = RawInline t s+ walk f (Link atr xs t) = Link atr (walk f xs) t+ walk f (Image atr xs t)= Image atr (walk f xs) t+ walk f (Note bs) = Note (walk f bs)+ walk f (Span attr xs) = Span attr (walk f xs) -instance Walkable [Block] Inline where- walkM = walkInlineM- query = queryInline+ walkM _ (Str xs) = return $ Str xs+ walkM f (Emph xs) = Emph <$> walkM f xs+ walkM f (Strong xs) = Strong <$> walkM f xs+ walkM f (Strikeout xs) = Strikeout <$> walkM f xs+ walkM f (Subscript xs) = Subscript <$> walkM f xs+ 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) = do cs' <- walkM f cs+ xs' <- walkM f xs+ return $ Cite cs' xs'+ walkM _ (Code attr s) = return $ Code attr s+ walkM _ Space = return $ Space+ walkM _ SoftBreak = return $ SoftBreak+ walkM _ LineBreak = return $ LineBreak+ walkM _ (Math mt s) = return $ Math mt s+ walkM _ (RawInline t s) = return $ RawInline t s+ walkM f (Link atr xs t) = (\lab -> Link atr lab t) <$> walkM f xs+ walkM f (Image atr xs t)= (\lab -> Image atr lab t) <$> walkM f xs+ walkM f (Note bs) = Note <$> walkM f bs+ walkM f (Span attr xs) = Span attr <$> walkM f xs ------ Walk Pandoc----instance Walkable Block Pandoc where- walkM = walkPandocM- query = queryPandoc+ query _ (Str _) = mempty+ query f (Emph xs) = query f xs+ query f (Strong xs) = query f xs+ query f (Strikeout xs) = query f xs+ query f (Subscript xs) = query f xs+ query f (Superscript xs)= query f xs+ query f (SmallCaps xs) = query f xs+ query f (Quoted _ xs) = query f xs+ query f (Cite cs xs) = query f cs <> query f xs+ query _ (Code _ _) = mempty+ query _ Space = mempty+ query _ SoftBreak = mempty+ query _ LineBreak = mempty+ query _ (Math _ _) = mempty+ query _ (RawInline _ _) = mempty+ query f (Link _ xs _) = query f xs+ query f (Image _ xs _) = query f xs+ query f (Note bs) = query f bs+ query f (Span _ xs) = query f xs -instance Walkable [Block] Pandoc where- walkM = walkPandocM- query = queryPandoc+instance Walkable Block Pandoc where+ walk f (Pandoc m bs) = Pandoc (walk f m) (walk f bs)+ walkM f (Pandoc m bs) = do m' <- walkM f m+ bs' <- walkM f bs+ return $ Pandoc m' bs'+ query f (Pandoc m bs) = query f m <> query f bs instance Walkable Inline Pandoc where- walkM = walkPandocM- query = queryPandoc--instance Walkable [Inline] Pandoc where- walkM = walkPandocM- query = queryPandoc+ walk f (Pandoc m bs) = Pandoc (walk f m) (walk f bs)+ walkM f (Pandoc m bs) = do m' <- walkM f m+ bs' <- walkM f bs+ return $ Pandoc m' bs'+ query f (Pandoc m bs) = query f m <> query f bs instance Walkable Pandoc Pandoc where+ walk f = f walkM f = f query f = f ------ Walk Meta--- instance Walkable Meta Meta where+ walk f = f walkM f = f query f = f instance Walkable Inline Meta where- walkM f (Meta metamap) = Meta <$> walkM f metamap- query f (Meta metamap) = query f metamap--instance Walkable [Inline] Meta where+ walk f (Meta metamap) = Meta $ walk f metamap walkM f (Meta metamap) = Meta <$> walkM f metamap query f (Meta metamap) = query f metamap instance Walkable Block Meta where- walkM f (Meta metamap) = Meta <$> walkM f metamap- query f (Meta metamap) = query f metamap--instance Walkable [Block] Meta where+ walk f (Meta metamap) = Meta $ walk f metamap walkM f (Meta metamap) = Meta <$> walkM f metamap query f (Meta metamap) = query f metamap ------ Walk MetaValue--- instance Walkable Inline MetaValue where- walkM = walkMetaValueM- query = queryMetaValue+ walk f (MetaList xs) = MetaList $ walk f xs+ walk _ (MetaBool b) = MetaBool b+ walk _ (MetaString s) = MetaString s+ walk f (MetaInlines xs) = MetaInlines $ walk f xs+ walk f (MetaBlocks bs) = MetaBlocks $ walk f bs+ walk f (MetaMap m) = MetaMap $ walk f m -instance Walkable [Inline] MetaValue where- walkM = walkMetaValueM- query = queryMetaValue+ walkM f (MetaList xs) = MetaList <$> walkM f xs+ walkM _ (MetaBool b) = return $ MetaBool b+ walkM _ (MetaString s) = return $ MetaString s+ walkM f (MetaInlines xs) = MetaInlines <$> walkM f xs+ walkM f (MetaBlocks bs) = MetaBlocks <$> walkM f bs+ walkM f (MetaMap m) = MetaMap <$> walkM f m + query f (MetaList xs) = query f xs+ query _ (MetaBool _) = mempty+ query _ (MetaString _) = mempty+ query f (MetaInlines xs) = query f xs+ query f (MetaBlocks bs) = query f bs+ query f (MetaMap m) = query f m+ instance Walkable Block MetaValue where- walkM = walkMetaValueM- query = queryMetaValue+ walk f (MetaList xs) = MetaList $ walk f xs+ walk _ (MetaBool b) = MetaBool b+ walk _ (MetaString s) = MetaString s+ walk f (MetaInlines xs) = MetaInlines $ walk f xs+ walk f (MetaBlocks bs) = MetaBlocks $ walk f bs+ walk f (MetaMap m) = MetaMap $ walk f m -instance Walkable [Block] MetaValue where- walkM = walkMetaValueM- query = queryMetaValue+ walkM f (MetaList xs) = MetaList <$> walkM f xs+ walkM _ (MetaBool b) = return $ MetaBool b+ walkM _ (MetaString s) = return $ MetaString s+ walkM f (MetaInlines xs) = MetaInlines <$> walkM f xs+ walkM f (MetaBlocks bs) = MetaBlocks <$> walkM f bs+ walkM f (MetaMap m) = MetaMap <$> walkM f m ------ Walk Citation----instance Walkable Inline Citation where- walkM = walkCitationM- query = queryCitation+ query f (MetaList xs) = query f xs+ query _ (MetaBool _) = mempty+ query _ (MetaString _) = mempty+ query f (MetaInlines xs) = query f xs+ query f (MetaBlocks bs) = query f bs+ query f (MetaMap m) = query f m -instance Walkable [Inline] Citation where- walkM = walkCitationM- query = queryCitation+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 _ pref suff _ _ _) =+ query f pref <> query f suff instance Walkable Block Citation where- walkM = walkCitationM- query = queryCitation--instance Walkable [Block] Citation where- walkM = walkCitationM- query = queryCitation---- | Helper method to walk to elements nested below @'Inline'@ nodes.------ When walking an inline with this function, only the contents of the traversed--- inline element may change. The element itself, i.e. its constructor, cannot--- be changed.-walkInlineM :: (Walkable a Citation, Walkable a [Block],- Walkable a [Inline], Monad m, Applicative m, Functor m)- => (a -> m a) -> Inline -> m Inline-walkInlineM _ (Str xs) = return (Str xs)-walkInlineM f (Emph xs) = Emph <$> walkM f xs-walkInlineM f (Strong xs) = Strong <$> walkM f xs-walkInlineM f (Strikeout xs) = Strikeout <$> walkM f xs-walkInlineM f (Subscript xs) = Subscript <$> walkM f xs-walkInlineM f (Superscript xs) = Superscript <$> walkM f xs-walkInlineM f (SmallCaps xs) = SmallCaps <$> walkM f xs-walkInlineM f (Quoted qt xs) = Quoted qt <$> walkM f xs-walkInlineM f (Link atr xs t) = Link atr <$> walkM f xs <*> pure t-walkInlineM f (Image atr xs t) = Image atr <$> walkM f xs <*> pure t-walkInlineM f (Note bs) = Note <$> walkM f bs-walkInlineM f (Span attr xs) = Span attr <$> walkM f xs-walkInlineM f (Cite cs xs) = Cite <$> walkM f cs <*> walkM f xs-walkInlineM _ LineBreak = return LineBreak-walkInlineM _ SoftBreak = return SoftBreak-walkInlineM _ Space = return Space-walkInlineM _ x@Code {} = return x-walkInlineM _ x@Math {} = return x-walkInlineM _ x@RawInline {} = return x---- | Perform a query on elements nested below an @'Inline'@ element by--- querying nested lists of @Inline@s, @Block@s, or @Citation@s.-queryInline :: (Walkable a Citation, Walkable a [Block],- Walkable a [Inline], Monoid c)- => (a -> c) -> Inline -> c-queryInline _ (Str _) = mempty-queryInline f (Emph xs) = query f xs-queryInline f (Strong xs) = query f xs-queryInline f (Strikeout xs) = query f xs-queryInline f (Subscript xs) = query f xs-queryInline f (Superscript xs)= query f xs-queryInline f (SmallCaps xs) = query f xs-queryInline f (Quoted _ xs) = query f xs-queryInline f (Cite cs xs) = query f cs <> query f xs-queryInline _ (Code _ _) = mempty-queryInline _ Space = mempty-queryInline _ SoftBreak = mempty-queryInline _ LineBreak = mempty-queryInline _ (Math _ _) = mempty-queryInline _ (RawInline _ _) = mempty-queryInline f (Link _ xs _) = query f xs-queryInline f (Image _ xs _) = query f xs-queryInline f (Note bs) = query f bs-queryInline f (Span _ xs) = query f xs----- | Helper method to walk to elements nested below @'Block'@ nodes.------ When walking a block with this function, only the contents of the traversed--- block element may change. The element itself, i.e. its constructor, its @'Attr'@,--- and its raw text value, will remain unchanged.-walkBlockM :: (Walkable a [Block], Walkable a [Inline], Monad m,- Applicative m, Functor m)- => (a -> m a) -> Block -> m Block-walkBlockM f (Para xs) = Para <$> walkM f xs-walkBlockM f (Plain xs) = Plain <$> walkM f xs-walkBlockM f (LineBlock xs) = LineBlock <$> walkM f xs-walkBlockM f (BlockQuote xs) = BlockQuote <$> walkM f xs-walkBlockM f (OrderedList a cs) = OrderedList a <$> walkM f cs-walkBlockM f (BulletList cs) = BulletList <$> walkM f cs-walkBlockM f (DefinitionList xs) = DefinitionList <$> walkM f xs-walkBlockM f (Header lev attr xs) = Header lev attr <$> walkM f xs-walkBlockM f (Div attr bs') = Div attr <$> walkM f bs'-walkBlockM _ x@CodeBlock {} = return x-walkBlockM _ x@RawBlock {} = return x-walkBlockM _ HorizontalRule = return HorizontalRule-walkBlockM _ Null = return Null-walkBlockM f (Table capt as ws hs rs) = do capt' <- walkM f capt- hs' <- walkM f hs- rs' <- walkM f rs- return $ Table capt' as ws hs' rs'---- | Perform a query on elements nested below a @'Block'@ element by--- querying all directly nested lists of @Inline@s or @Block@s.-queryBlock :: (Walkable a Citation, Walkable a [Block],- Walkable a [Inline], Monoid c)- => (a -> c) -> Block -> c-queryBlock f (Para xs) = query f xs-queryBlock f (Plain xs) = query f xs-queryBlock f (LineBlock xs) = query f xs-queryBlock _ (CodeBlock _ _) = mempty-queryBlock _ (RawBlock _ _) = mempty-queryBlock f (BlockQuote bs) = query f bs-queryBlock f (OrderedList _ cs) = query f cs-queryBlock f (BulletList cs) = query f cs-queryBlock f (DefinitionList xs) = query f xs-queryBlock f (Header _ _ xs) = query f xs-queryBlock _ HorizontalRule = mempty-queryBlock f (Table capt _ _ hs rs) = query f capt <> query f hs <> query f rs-queryBlock f (Div _ bs) = query f bs-queryBlock _ Null = mempty---- | Helper method to walk to elements nested below @'MetaValue'@ nodes.------ When walking a meta value with this function, only the contents of the--- traversed meta value element may change. @MetaBool@ and @MetaString@ will--- always remain unchanged.-walkMetaValueM :: (Walkable a MetaValue, Walkable a [Block],- Walkable a [Inline], Monad f, Applicative f, Functor f)- => (a -> f a) -> MetaValue -> f MetaValue-walkMetaValueM f (MetaList xs) = MetaList <$> walkM f xs-walkMetaValueM _ (MetaBool b) = return $ MetaBool b-walkMetaValueM _ (MetaString s) = return $ MetaString s-walkMetaValueM f (MetaInlines xs) = MetaInlines <$> walkM f xs-walkMetaValueM f (MetaBlocks bs) = MetaBlocks <$> walkM f bs-walkMetaValueM f (MetaMap m) = MetaMap <$> walkM f m---- | Perform a query on elements nested below a @'MetaValue'@ element by--- querying all directly nested lists of @Inline@s, list of @Block@s, or--- lists or maps of @MetaValue@s.-queryMetaValue :: (Walkable a MetaValue, Walkable a [Block],- Walkable a [Inline], Monoid c)- => (a -> c) -> MetaValue -> c-queryMetaValue f (MetaList xs) = query f xs-queryMetaValue _ (MetaBool _) = mempty-queryMetaValue _ (MetaString _) = mempty-queryMetaValue f (MetaInlines xs) = query f xs-queryMetaValue f (MetaBlocks bs) = query f bs-queryMetaValue f (MetaMap m) = query f m---- | Helper method to walk to elements nested below @'Citation'@ nodes.------ The non-inline contents of a citation will remain unchanged during traversal.--- Only the inline contents, viz. the citation's prefix and postfix, will be--- traversed further and can thus be changed during this operation.-walkCitationM :: (Walkable a [Inline], Monad m, Applicative m, Functor m)- => (a -> m a) -> Citation -> m Citation-walkCitationM f (Citation id' pref suff mode notenum hash) =+ 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---- | Perform a query on elements nested below a @'Citation'@ element by--- querying the prefix and postfix @Inline@ lists.-queryCitation :: (Walkable a [Inline], Monoid c)- => (a -> c) -> Citation -> c-queryCitation f (Citation _ pref suff _ _ _) = query f pref <> query f suff---- | Helper method to walk the components of a Pandoc element.-walkPandocM :: (Walkable a Meta, Walkable a [Block], Monad m,- Applicative m, Functor m)- => (a -> m a) -> Pandoc -> m Pandoc-walkPandocM f (Pandoc m bs) = do m' <- walkM f m- bs' <- walkM f bs- return $ Pandoc m' bs'---- | Query a pandoc element by recursing first into its @'Meta'@ data--- and then append the result of recursing into the list of @'Block'@s.-queryPandoc :: (Walkable a Meta, Walkable a [Block], Monoid c)- => (a -> c) -> Pandoc -> c-queryPandoc f (Pandoc m bs) = query f m <> query f bs+ query f (Citation _ pref suff _ _ _) =+ query f pref <> query f suff
− benchmark/bench.hs
@@ -1,39 +0,0 @@-{-# LANGUAGE OverloadedStrings #-}--import Criterion.Main (bench, defaultMain, nf)-import Text.Pandoc.Definition (Pandoc, Inline (Str))-import Text.Pandoc.Walk (walk)-import Text.Pandoc.Builder--main :: IO ()-main =- defaultMain [- bench "simple walk" $ nf (walk prependZeroWidthSpace) mydoc- , bench "walk concatMap" $ nf (walk $ concatMap prependZeroWidthSpace') mydoc- , bench "walk lists" $ nf (walk prependZeroWidthSpace'') mydoc- ]--prependZeroWidthSpace :: Inline -> Inline-prependZeroWidthSpace (Str s) = Str ('\8203' : s)-prependZeroWidthSpace x = x--prependZeroWidthSpace' :: Inline -> [Inline]-prependZeroWidthSpace' (Str s) = [Str ('\8203' : s)]-prependZeroWidthSpace' x = [x]--prependZeroWidthSpace'' :: [Inline] -> [Inline]-prependZeroWidthSpace'' (Str s : xs) =- Str ('\8203' : s) : prependZeroWidthSpace'' xs-prependZeroWidthSpace'' (x : xs) =- x : prependZeroWidthSpace'' xs-prependZeroWidthSpace'' [] = []--mydoc :: Pandoc-mydoc = setTitle "My title" $ doc $- mconcat $ replicate 50 $- para "This is the first paragraph" <>- para ("And " <> emph "another" <> ".") <>- bulletList [ para "item one" <> para "continuation"- , plain ("item two and a " <>- link "/url" "go to url" "link")- ]
changelog view
@@ -1,108 +1,10 @@-[1.17.6.1]--- * Relax version bound for string-qq.--[1.17.6]-- * Walk: export walk and query helpers (Albert Krewinkel) [API change].- The `walk*M` and `query*` functions are helpful when defining new- `Walkable` instances.- * Allow QuickCheck 2.13.- * Document meaning of Int in ListAttributes (#45).- * Update copyright year spans to include 2019 (Albert Krewinkel).- * Remove CPP instructions for GHC versions < 7.10 (Albert Krewinkel).- * update list of GHC versions used for testing (Albert Krewinkel).- * Fix compiler and hlint warnings (Pete Ryland).--[1.17.5.4]-- * Put NFData in scope for ghc < 7.10.- * Reduce deepseq lower bound for ghc < 7.10.--[1.17.5.3]-- * For ghc < 7.10, constrain deepseq-generics to >= 0.2, which no- longer exprots NFData from deepseq. Add deepseq dependency.--[1.17.5.2]-- * Bump upper bound for deepseq-generics, QuickCheck, criterion.- * Implement QuickCheck shrinking for Inlines and Blocks (Alexander Krotov).--[1.17.5.1]-- * Declare the ToMetaValue instance for String as OVERLAPPING (#46).--[1.17.5]--- * Bump upper bounds for aeson, base.- * Allow building on older ghc versions (George Wilson).- * Text.Pandoc.Arbitrary: generate SoftBreaks and LineBreaks- (Alexander Krotov).- * Pad table rows up to maximum row length, to guarantee that- all rows have the same number of columns- (see jgm/pandoc#4059, Francesco Occhipinti).- * Make String an instance of ToMetaValue (Alexander Krotov).--[1.17.4.2]-- * Fix compiler warnings.--[1.17.4.1]-- * Import Semigroups when needed rather than using CPP.- * Bump criterion upper bound.--[1.17.4]-- * Add Semigroup instances for Pandoc, Meta, Inlines, Blocks- (if base >= 4.9). This is needed for the library to compile- with ghc 8.4.- * Bumped criterion upper bound.--[1.17.3.1]-- * Bumped upper bounds for criterion and QuickCheck.--[1.17.3]-- * Added Walkable instances for `[Inline] Inline` and `[Block] Block`.--[1.17.2]+[1.19] - * Provide default implementation for walk (Albert Krewinkel).- The implementations for `walk` and `walkM` are very similar, so a- default method is provided which implements the former in terms of the- latter. This change should not affect performance, as the `Identity`- functor, which is used in the default definition, is a newtype that- should be eliminated at compile time. (This requires a dependency- on transformers for ghc 7.8.x.)- * Force optimizations when compiling Walk module (Albert Krewinkel).- * Add `Applicative m` to the context of walkM (Albert Krewinkel).- The acceptance of AMP makes this a natural change.- * Add `Walkable [Block]` and `Walkable [Inline]` instances (Albert- Krewinkel).- * Factored out duplicate code in Walk.- * Added benchmark.- * Text.Pandoc.JSON: Use `walk` instead of `bottomUp` in the- `ToJSONFilter` instance for `a -> [a]`. Note that behavior will be- slightly different, since bottomUp's treatment of a function `[a] -> [a]`- is to apply it to each sublist of a list, while walk applies it only to- maximal sublists. Usually the latter behavior is what is wanted, and the- former can be simulated when needed. But there may be existing filters- that need to be rewritten in light of the new behavior.+ * Reverted PageBreak addition, pending further discussion. -[1.17.1]+[1.18] - * Better consistency in simpleTable and table (jgm/pandoc#3648).- If `headers` is empty, we populate it with empty cells, using the rows- to determine number of columns. We also ensure that there are numcols- alignments and column widths.- * Make sure Div and Span occur in Arbitrary instances.- * Bump dependency upper bounds.- * Removed unused mapConst.+ * Added PageBreak Inline element (Hubert Plociniczak). [1.17.0.5]
pandoc-types.cabal view
@@ -1,5 +1,5 @@ Name: pandoc-types-Version: 1.17.6.1+Version: 1.19 Synopsis: Types for representing a structured document Description: @Text.Pandoc.Definition@ defines the 'Pandoc' data structure, which is used by pandoc to represent@@ -22,18 +22,17 @@ @Text.Pandoc.JSON@ provides functions for serializing and deserializing a @Pandoc@ structure to and from JSON. -Homepage: https://pandoc.org/+Homepage: http://johnmacfarlane.net/pandoc License: BSD3 License-file: LICENSE Author: John MacFarlane Maintainer: jgm@berkeley.edu Bug-Reports: https://github.com/jgm/pandoc-types/issues-Copyright: (c) 2006-2019 John MacFarlane+Copyright: (c) 2006-2015 John MacFarlane Category: Text Build-type: Simple Cabal-version: >=1.8-Tested-With: GHC == 7.10.3, GHC == 8.0.1, GHC == 8.2.2, GHC == 8.4.2,- GHC == 8.6.5+Tested-With: GHC == 7.8.4, GHC == 7.10.3, GHC == 8.0.1 Extra-Source-Files: changelog Source-repository head type: git@@ -47,18 +46,17 @@ Text.Pandoc.JSON Text.Pandoc.Arbitrary Other-modules: Paths_pandoc_types- Build-depends: base >= 4.5 && < 5,+ Build-depends: base >= 4 && < 5, containers >= 0.3,- deepseq >= 1.4.1 && < 1.5,- syb >= 0.1 && < 0.8,+ syb >= 0.1 && < 0.7, ghc-prim >= 0.2, bytestring >= 0.9 && < 0.11,- aeson >= 0.6.2 && < 1.5,- transformers >= 0.2 && < 0.6,- QuickCheck >= 2.4 && < 2.14- if !impl(ghc >= 8.0)- Build-depends: semigroups == 0.18.*- ghc-options: -Wall+ aeson >= 0.6.2 && < 1.2,+ QuickCheck >= 2+ if impl(ghc < 7.10)+ Build-depends: deepseq-generics >= 0.1 && < 0.2+ else+ Build-depends: deepseq >= 1.4.1 && < 1.5 test-suite test-pandoc-types type: exitcode-stdio-1.0@@ -67,22 +65,13 @@ build-depends: base, pandoc-types, syb,- aeson >= 0.6.2 && < 1.5,+ aeson >= 0.6.2 && < 1.2, containers >= 0.3, bytestring >= 0.9 && < 0.11, test-framework >= 0.3 && < 0.9, test-framework-hunit >= 0.2 && < 0.4, test-framework-quickcheck2 >= 0.2.9 && < 0.4,- QuickCheck >= 2.4 && < 2.14,- HUnit >= 1.2 && < 1.7,- string-qq >= 0.0.2 && < 0.1- ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -O2--benchmark benchmark-pandoc-types- type: exitcode-stdio-1.0- main-is: bench.hs- hs-source-dirs: benchmark- build-depends: pandoc-types,- base >= 4.5 && < 5,- criterion >= 1.0 && < 1.6- ghc-options: -rtsopts -Wall -fno-warn-unused-do-bind -O2+ QuickCheck >= 2.4 && < 2.10,+ HUnit >= 1.2 && < 1.6,+ string-qq == 0.0.2+ ghc-options: -threaded -rtsopts -with-rtsopts=-N
test/test-pandoc-types.hs view
@@ -1,12 +1,11 @@ {-# LANGUAGE OverloadedStrings, QuasiQuotes, FlexibleContexts, CPP #-} -import Text.Pandoc.Arbitrary () import Text.Pandoc.Definition import Text.Pandoc.Walk-import Text.Pandoc.Builder (singleton, plain, text, simpleTable)+import Text.Pandoc.Arbitrary() import Data.Generics-import Data.List (tails) import Test.HUnit (Assertion, assertEqual, assertFailure)+import Text.Pandoc.Arbitrary () import Data.Char (toUpper) import Data.Aeson (FromJSON, ToJSON, encode, decode) import Test.Framework@@ -15,68 +14,39 @@ import qualified Data.Map as M import Data.String.QQ import Data.ByteString.Lazy (ByteString)-import qualified Data.Monoid as Monoid+#if MIN_VERSION_base(4,8,0)+#else+import Data.Monoid+#endif p_walk :: (Typeable a, Walkable a Pandoc) => (a -> a) -> Pandoc -> Bool p_walk f d = everywhere (mkT f) d == walk f d -p_walkList :: (Typeable a, Walkable [a] Pandoc)- => ([a] -> [a]) -> Pandoc -> Bool-p_walkList f d = everywhere (mkT f) d == walk (foldr g []) d- where g x ys = f (x:ys)- p_query :: (Eq a, Typeable a1, Monoid a, Walkable a1 Pandoc) => (a1 -> a) -> Pandoc -> Bool p_query f d = everything mappend (mempty `mkQ` f) d == query f d -p_queryList :: (Eq a, Typeable a1, Monoid a, Walkable [a1] Pandoc)- => ([a1] -> a) -> Pandoc -> Bool-p_queryList f d = everything mappend (mempty `mkQ` f) d ==- query (mconcat . map f . tails) d- inlineTrans :: Inline -> Inline inlineTrans (Str xs) = Str $ map toUpper xs inlineTrans (Emph xs) = Strong xs inlineTrans x = x -inlinesTrans :: [Inline] -> [Inline]-inlinesTrans ys | all whitespaceInline ys = []- where- whitespaceInline Space = True- whitespaceInline LineBreak = True- whitespaceInline SoftBreak = True- whitespaceInline (Str "") = True- whitespaceInline _ = False-inlinesTrans ys = ys- blockTrans :: Block -> Block blockTrans (Plain xs) = Para xs blockTrans (BlockQuote xs) = Div ("",["special"],[]) xs blockTrans x = x -blocksTrans :: [Block] -> [Block]-blocksTrans [CodeBlock {}] = []-blocksTrans [BlockQuote xs] = xs-blocksTrans [Div _ xs] = xs-blocksTrans xs = xs- inlineQuery :: Inline -> String inlineQuery (Str xs) = xs inlineQuery _ = "" -inlinesQuery :: [Inline] -> Monoid.Sum Int-inlinesQuery = Monoid.Sum . length- blockQuery :: Block -> [Int] blockQuery (Header lev _ _) = [lev] blockQuery _ = [] -blocksQuery :: [Block] -> Monoid.Sum Int-blocksQuery = Monoid.Sum . length - prop_roundtrip :: Pandoc -> Bool prop_roundtrip doc = case decode $ encode doc :: (Maybe Pandoc) of Just doc' -> doc == doc'@@ -359,26 +329,7 @@ t_null :: (Block, ByteString) t_null = (Null, [s|{"t":"Null"}|]) --- headers and rows are padded to a consistent number of--- cells in order to avoid syntax errors after conversion, see--- jgm/pandoc#4059.-t_tableSan :: Test-t_tableSan = testCase "table sanitisation" assertion- where assertion = assertEqual err expected generated- err = "sanitisation error"- generated = simpleTable- [plain (text "foo"), plain (text "bar")]- [[mempty]- ,[]]- expected = singleton (Table- []- [AlignDefault, AlignDefault]- [0.0, 0.0]- [[Plain [Str "foo"]],- [Plain [Str "bar"]]]- [[[], []], [[], []]]) - tests :: [Test] tests = [ testGroup "Walk"@@ -386,10 +337,6 @@ , testProperty "p_walk blockTrans" (p_walk blockTrans) , testProperty "p_query inlineQuery" (p_query inlineQuery) , testProperty "p_query blockQuery" (p_query blockQuery)- , testProperty "p_walkList inlinesTrans" (p_walkList inlinesTrans)- , testProperty "p_queryList inlinesQuery" (p_queryList inlinesQuery)- , testProperty "p_walkList blocksTrans" (p_walkList blocksTrans)- , testProperty "p_queryList blocksQuery" (p_queryList blocksQuery) ] , testGroup "JSON" [ testGroup "encoding/decoding properties"@@ -454,8 +401,7 @@ , testEncodeDecode "Null" t_null ] ]- ],- t_tableSan+ ] ]