pandoc-types 1.17.4.2 → 1.17.5
raw patch · 7 files changed
+108/−96 lines, 7 filesdep ~aesondep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: aeson, base
API changes (from Hackage documentation)
+ Text.Pandoc.Builder: instance Text.Pandoc.Builder.ToMetaValue GHC.Base.String
Files
- Text/Pandoc/Arbitrary.hs +59/−78
- Text/Pandoc/Builder.hs +9/−8
- Text/Pandoc/Definition.hs +1/−1
- Text/Pandoc/Walk.hs +3/−3
- changelog +12/−0
- pandoc-types.cabal +5/−5
- test/test-pandoc-types.hs +19/−1
Text/Pandoc/Arbitrary.hs view
@@ -4,7 +4,8 @@ module Text.Pandoc.Arbitrary () where import Test.QuickCheck-import Control.Monad (forM, liftM, liftM2)+import Control.Applicative (Applicative ((<*>), pure), (<$>))+import Control.Monad (forM) import Text.Pandoc.Definition import Text.Pandoc.Builder @@ -20,107 +21,88 @@ return (id',classes,keyvals) instance Arbitrary Inlines where- arbitrary = liftM (fromList :: [Inline] -> Inlines) arbitrary+ arbitrary = (fromList :: [Inline] -> Inlines) <$> arbitrary instance Arbitrary Blocks where- arbitrary = liftM (fromList :: [Block] -> Blocks) arbitrary+ arbitrary = (fromList :: [Block] -> Blocks) <$> arbitrary instance Arbitrary Inline where arbitrary = resize 3 $ arbInline 2 arbInlines :: Int -> Gen [Inline] arbInlines n = listOf1 (arbInline n) `suchThat` (not . startsWithSpace)- where startsWithSpace (Space:_) = True- startsWithSpace _ = False+ where startsWithSpace (Space:_) = True+ startsWithSpace (SoftBreak:_) = True+ -- Note: no LineBreak, similarly to Text.Pandoc.Builder (trimInlines)+ 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, liftM Str realString)- , (60, return Space)- , (10, liftM2 Code arbAttr realString)+arbInline n = frequency $ [ (60, Str <$> realString)+ , (40, pure Space)+ , (10, pure SoftBreak)+ , (10, pure LineBreak)+ , (10, Code <$> arbAttr <*> realString) , (5, elements [ RawInline (Format "html") "<a id=\"eek\">" , RawInline (Format "latex") "\\my{command}" ]) ] ++ [ 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 <- arbAttr- x2 <- arbInlines (n-1)- return $ Span x1 x2)- , (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))+ 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))) ] instance Arbitrary Block where arbitrary = resize 3 $ arbBlock 2 arbBlock :: Int -> Gen Block-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)))+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)))) , (2, elements [ RawBlock (Format "html") "<div>\n*&*\n</div>" , RawBlock (Format "latex") "\\begin[opt]{env}\nhi\n{\\end{env}" ])- , (5, do x1 <- choose (1 :: Int, 6)- x2 <- arbInlines (n-1)- return (Header x1 nullAttr x2))- , (2, return HorizontalRule)+ , (5, Header <$> choose (1 :: Int, 6)+ <*> pure nullAttr+ <*> arbInlines (n-1))+ , (2, pure 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)- , (5, do x1 <- arbAttr- x2 <- listOf1 $ arbBlock (n-1)- return $ Div x1 x2)+ 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))) , (2, do rs <- choose (1 :: Int, 4) cs <- choose (1 :: Int, 4)- 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))+ 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))) ] instance Arbitrary Pandoc where- arbitrary = resize 8 $ liftM2 Pandoc arbitrary arbitrary+ arbitrary = resize 8 (Pandoc <$> arbitrary <*> arbitrary) instance Arbitrary CitationMode where arbitrary@@ -133,13 +115,12 @@ instance Arbitrary Citation where 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)+ = Citation <$> listOf (elements $ ['a'..'z'] ++ ['0'..'9'] ++ ['_'])+ <*> arbInlines 1+ <*> arbInlines 1+ <*> arbitrary+ <*> arbitrary+ <*> arbitrary instance Arbitrary MathType where arbitrary@@ -160,7 +141,7 @@ instance Arbitrary Meta where arbitrary = do (x1 :: Inlines) <- arbitrary- (x2 :: [Inlines]) <- liftM (filter (not . isNull)) arbitrary+ (x2 :: [Inlines]) <- filter (not . isNull) <$> arbitrary (x3 :: Inlines) <- arbitrary return $ setMeta "title" x1 $ setMeta "author" x2
Text/Pandoc/Builder.hs view
@@ -277,6 +277,9 @@ instance ToMetaValue Bool where toMetaValue = MetaBool +instance ToMetaValue String where+ toMetaValue = MetaString+ instance ToMetaValue a => ToMetaValue [a] where toMetaValue = MetaList . map toMetaValue @@ -474,21 +477,19 @@ 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- (map toList headers') (map (map toList) rows)+ Table (toList caption) aligns widths (sanitise headers) (map sanitise rows) where (aligns, widths) = unzip cellspecs- numcols = case (headers:rows) of- [] -> 0- xs -> maximum (map length xs)- headers' = if null headers- then replicate numcols mempty- else headers+ 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
Text/Pandoc/Definition.hs view
@@ -84,7 +84,7 @@ #if MIN_VERSION_base(4,8,0) import Control.DeepSeq #else-import Data.Monoid+import Data.Monoid (Monoid (mappend, mempty)) import Control.Applicative ((<$>), (<*>)) import Control.DeepSeq.Generics #endif
Text/Pandoc/Walk.hs view
@@ -93,14 +93,14 @@ module Text.Pandoc.Walk (Walkable(..)) where-import Control.Applicative ()+import Control.Applicative (Applicative ((<*>), pure), (<$>)) import Control.Monad ((>=>)) import Data.Functor.Identity (Identity (runIdentity)) import Text.Pandoc.Definition import qualified Data.Traversable as T-import Data.Traversable ()+import Data.Traversable (Traversable) import qualified Data.Foldable as F-import Data.Foldable ()+import Data.Foldable (Foldable) #if MIN_VERSION_base(4,8,0) import Data.Monoid ((<>)) #else
changelog view
@@ -1,3 +1,15 @@+[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.
pandoc-types.cabal view
@@ -1,5 +1,5 @@ Name: pandoc-types-Version: 1.17.4.2+Version: 1.17.5 Synopsis: Types for representing a structured document Description: @Text.Pandoc.Definition@ defines the 'Pandoc' data structure, which is used by pandoc to represent@@ -46,12 +46,12 @@ Text.Pandoc.JSON Text.Pandoc.Arbitrary Other-modules: Paths_pandoc_types- Build-depends: base >= 4 && < 5,+ Build-depends: base >= 4.5 && < 5, containers >= 0.3, syb >= 0.1 && < 0.8, ghc-prim >= 0.2, bytestring >= 0.9 && < 0.11,- aeson >= 0.6.2 && < 1.4,+ aeson >= 0.6.2 && < 1.5, transformers >= 0.2 && < 0.6, QuickCheck >= 2 if !impl(ghc >= 8.0)@@ -69,7 +69,7 @@ build-depends: base, pandoc-types, syb,- aeson >= 0.6.2 && < 1.4,+ aeson >= 0.6.2 && < 1.5, containers >= 0.3, bytestring >= 0.9 && < 0.11, test-framework >= 0.3 && < 0.9,@@ -85,6 +85,6 @@ main-is: bench.hs hs-source-dirs: benchmark build-depends: pandoc-types,- base >= 4.2 && < 5,+ base >= 4.5 && < 5, criterion >= 1.0 && < 1.5 ghc-options: -rtsopts -Wall -fno-warn-unused-do-bind -O2
test/test-pandoc-types.hs view
@@ -3,6 +3,7 @@ import Text.Pandoc.Arbitrary () import Text.Pandoc.Definition import Text.Pandoc.Walk+import Text.Pandoc.Builder (simpleTable, singleton) import Data.Generics import Data.List (tails) import Test.HUnit (Assertion, assertEqual, assertFailure)@@ -362,7 +363,23 @@ t_null :: (Block, ByteString) t_null = (Null, [s|{"t":"Null"}|]) +-- headers and rows are truncated or padded to a consistent number of+-- cells in order to avoid syntax errors after conversion, see+-- jgm/pandoc#4059. this test uses `simpleTable` therefore it cannot+-- test truncation+t_tableSan :: Test+t_tableSan = testCase "table sanitisation" $ assertion+ where assertion = assertEqual err expected generated+ err = "sanitisation error"+ headers = [singleton Null, singleton Null]+ generated = simpleTable headers [[mempty], []]+ expected = singleton (Table+ []+ [AlignDefault, AlignDefault]+ [0.0, 0.0]+ [[Null], [Null]] [[[], []], [[], []]]) + tests :: [Test] tests = [ testGroup "Walk"@@ -438,7 +455,8 @@ , testEncodeDecode "Null" t_null ] ]- ]+ ],+ t_tableSan ]