Skip to content

Commit fecbdda

Browse files
committed
Write new Format and Formats types, some helper functions
A new Format type enumerates exactly what formats Pandoc can recognize in some way (input, output, raw content). A new Formats type and related functions can be used in future IfFormatBlock and IfFormatInline blocks, and are used to implement the castsTo function that writers can use to determine when they can include raw content in their output.
1 parent 8e9ca37 commit fecbdda

File tree

4 files changed

+435
-0
lines changed

4 files changed

+435
-0
lines changed

pandoc-types.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Library
4747
Text.Pandoc.Builder
4848
Text.Pandoc.JSON
4949
Text.Pandoc.Arbitrary
50+
Text.Pandoc.Format
5051
Other-modules: Paths_pandoc_types
5152
Autogen-modules: Paths_pandoc_types
5253
Build-depends: base >= 4.5 && < 5,

src/Text/Pandoc/Arbitrary.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ where
66
import Test.QuickCheck
77
import Control.Applicative (Applicative ((<*>), pure), (<$>))
88
import Control.Monad (forM)
9+
import qualified Data.Set as Set
910
import Data.Text (Text)
1011
import qualified Data.Text as T
1112
import Text.Pandoc.Definition
1213
import Text.Pandoc.Builder
14+
import qualified Text.Pandoc.Format as F
1315

1416
realString :: Gen Text
1517
realString = fmap T.pack $ resize 8 $ listOf $ frequency [ (9, elements [' '..'\127'])
@@ -398,3 +400,10 @@ instance Arbitrary ListNumberDelim where
398400
2 -> return OneParen
399401
3 -> return TwoParens
400402
_ -> error "FATAL ERROR: Arbitrary instance, logic bug"
403+
404+
instance Arbitrary F.Format where
405+
arbitrary = arbitraryBoundedEnum
406+
407+
instance Arbitrary F.Formats where
408+
arbitrary = F.exactly <$> arbitrary
409+
shrink (F.Formats s) = F.exactly <$> shrink (Set.toList s)

0 commit comments

Comments
 (0)