pandoc-types 1.22 → 1.22.1
raw patch · 5 files changed
+83/−11 lines, 5 filesdep ~aesondep ~transformersPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: aeson, transformers
API changes (from Hackage documentation)
- Text.Pandoc.Builder: instance GHC.Base.Monoid (Text.Pandoc.Builder.Many Text.Pandoc.Definition.Block)
- Text.Pandoc.Builder: instance GHC.Base.Semigroup (Text.Pandoc.Builder.Many Text.Pandoc.Definition.Block)
+ Text.Pandoc.Builder: instance GHC.Base.Monoid Text.Pandoc.Builder.Blocks
+ Text.Pandoc.Builder: instance GHC.Base.Semigroup Text.Pandoc.Builder.Blocks
+ Text.Pandoc.Builder: simpleFigure :: Inlines -> Text -> Text -> Blocks
+ Text.Pandoc.Builder: simpleFigureWith :: Attr -> Inlines -> Text -> Text -> Blocks
+ Text.Pandoc.Definition: pattern SimpleFigure :: Attr -> [Inline] -> Target -> Block
Files
- changelog +19/−0
- pandoc-types.cabal +6/−6
- src/Text/Pandoc/Builder.hs +10/−0
- src/Text/Pandoc/Definition.hs +32/−3
- test/test-pandoc-types.hs +16/−2
changelog view
@@ -1,3 +1,22 @@+[1.22.1]++ * Text.Pandoc.Builder: add simpleFigure, simpleFigureWith,+ and the SimpleFigure bidirectional pattern synonym+ (Aner Lucero) [API change].++ * Allow bytestring 0.11 (Alexander Batischev).++ * Update stack resolver to lts-18.10++ * Allow aeson 2+. Tested with aeson 2.0.1.0.++ * Allow transformers 0.6.++ * Fix incorrect table ColWidth documentation (#85, Nils Carlson).+ The documentation stated that the ColWidth represented the width+ of the column as a fraction of the table width when in represents+ a percentage of the text width.+ [1.22] * Deprecate isNull from Builder: null can serve just as well (#67).
pandoc-types.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 Name: pandoc-types-version: 1.22+version: 1.22.1 Synopsis: Types for representing a structured document Description: @Text.Pandoc.Definition@ defines the 'Pandoc' data structure, which is used by pandoc to represent@@ -55,9 +55,9 @@ deepseq >= 1.4.1 && < 1.5, syb >= 0.1 && < 0.8, ghc-prim >= 0.2,- bytestring >= 0.9 && < 0.11,- aeson >= 0.6.2 && < 1.6,- transformers >= 0.2 && < 0.6,+ bytestring >= 0.9 && < 0.12,+ aeson >= 0.6.2 && < 2.1,+ transformers >= 0.2 && < 0.7, QuickCheck >= 2.10 && < 2.15 if !impl(ghc >= 8.0) Build-depends: semigroups == 0.18.*@@ -71,10 +71,10 @@ build-depends: base, pandoc-types, syb,- aeson >= 0.6.2 && < 1.6,+ aeson >= 0.6.2 && < 2.1, containers >= 0.3, text,- bytestring >= 0.9 && < 0.11,+ bytestring >= 0.9 && < 0.12, test-framework >= 0.3 && < 0.9, test-framework-hunit >= 0.2 && < 0.4, test-framework-quickcheck2 >= 0.2.9 && < 0.4,
src/Text/Pandoc/Builder.hs view
@@ -1,6 +1,7 @@ {-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, DeriveDataTypeable, GeneralizedNewtypeDeriving, CPP, StandaloneDeriving, DeriveGeneric, DeriveTraversable, OverloadedStrings, PatternGuards #-}+ {- Copyright (C) 2010-2019 John MacFarlane @@ -170,6 +171,8 @@ , caption , simpleCaption , emptyCaption+ , simpleFigureWith+ , simpleFigure , divWith -- * Table processing , normalizeTableHead@@ -565,6 +568,13 @@ emptyCaption :: Caption emptyCaption = simpleCaption mempty++simpleFigureWith :: Attr -> Inlines -> Text -> Text -> Blocks+simpleFigureWith attr figureCaption url title =+ para $ imageWith attr url ("fig:" <> title) figureCaption++simpleFigure :: Inlines -> Text -> Text -> Blocks+simpleFigure = simpleFigureWith nullAttr divWith :: Attr -> Blocks -> Blocks divWith attr = singleton . Div attr . toList
src/Text/Pandoc/Definition.hs view
@@ -1,6 +1,6 @@ {-# LANGUAGE OverloadedStrings, DeriveDataTypeable, DeriveGeneric, FlexibleContexts, GeneralizedNewtypeDeriving, PatternGuards, CPP,- TemplateHaskell #-}+ TemplateHaskell , PatternSynonyms, ViewPatterns #-} {- Copyright (c) 2006-2019, John MacFarlane@@ -57,6 +57,7 @@ , docAuthors , docDate , Block(..)+ , pattern SimpleFigure , Inline(..) , ListAttributes , ListNumberStyle(..)@@ -99,6 +100,7 @@ import Paths_pandoc_types (version) import Data.Version (Version, versionBranch) import Data.Semigroup (Semigroup(..))+import Control.Arrow (second) data Pandoc = Pandoc Meta [Block] deriving (Eq, Ord, Read, Show, Typeable, Data, Generic)@@ -224,8 +226,7 @@ | AlignCenter | AlignDefault deriving (Eq, Ord, Show, Read, Typeable, Data, Generic) --- | The width of a table column, as a fraction of the total table--- width.+-- | The width of a table column, as a percentage of the text width. data ColWidth = ColWidth Double | ColWidthDefault deriving (Eq, Ord, Show, Read, Typeable, Data, Generic) @@ -311,6 +312,34 @@ -- | Link target (URL, title). type Target = (Text, Text)++isFigureTarget :: Target -> Maybe Target+isFigureTarget tgt+ | (src, Just tit) <- second (T.stripPrefix "fig:") tgt = Just (src, tit)+ | otherwise = Nothing++-- | Bidirectional patter synonym+--+-- It can pass as a Block constructor+--+-- >>> SimpleFigure nullAttr [] (T.pack "", T.pack "title")+-- Para [Image ("",[],[]) [] ("","fig:title")]+--+--+-- It can be used to pattern match+-- >>> let img = Para [Image undefined undefined (undefined, T.pack "title")]+-- >>> case img of { SimpleFigure _ _ _ -> True; _ -> False }+-- False+-- >>> let fig = Para [Image undefined undefined (undefined, T.pack "fig:title")]+-- >>> case fig of { SimpleFigure _ _ tit -> snd tit; _ -> T.pack "" }+-- "title"+pattern SimpleFigure :: Attr -> [Inline] -> Target -> Block+pattern SimpleFigure attr figureCaption tgt <-+ Para [Image attr figureCaption+ (isFigureTarget -> Just tgt)] where+ SimpleFigure attr figureCaption tgt =+ Para [Image attr figureCaption (second ("fig:" <>) tgt)]+ -- | Type of math element (display or inline). data MathType = DisplayMath | InlineMath deriving (Show, Eq, Ord, Read, Typeable, Data, Generic)
test/test-pandoc-types.hs view
@@ -5,7 +5,8 @@ import Text.Pandoc.Walk import Text.Pandoc.Builder (singleton, plain, text, simpleTable, table, emptyCell, normalizeTableHead, normalizeTableBody, normalizeTableFoot,- emptyCaption)+ emptyCaption, simpleFigureWith)+import qualified Text.Pandoc.Builder as Builder import Data.Generics import Data.List (tails) import Test.HUnit (Assertion, assertEqual, assertFailure)@@ -13,7 +14,7 @@ import Test.Framework import Test.Framework.Providers.QuickCheck2 (testProperty) import Test.Framework.Providers.HUnit (testCase)-import Test.QuickCheck (forAll, choose, Property, Arbitrary, Testable)+import Test.QuickCheck (forAll, choose, Property, Arbitrary, Testable, arbitrary, Gen) import qualified Data.Map as M import Data.Text (Text) import qualified Data.Text as T@@ -642,6 +643,17 @@ (tf finalHeads) generated = table emptyCaption spec (th initialHeads) [initialTB] (tf initialHeads) +p_figureRepresentation :: Property+p_figureRepresentation = forAll (arbitrary :: Gen [Inline]) (\figureCaption ->+ simpleFigureWith+ ("", [], [])+ (Builder.fromList figureCaption)+ "url"+ "title" ==+ Builder.fromList+ [Para [Image ("", [], []) figureCaption ("url", "fig:title") ]]+ )+ tests :: [Test] tests = [ testGroup "Walk"@@ -744,6 +756,8 @@ ] , t_tableSan , t_tableNormExample+ , testGroup "Figure"+ [ testProperty "p_figureRepresentation figure representation" p_figureRepresentation ] ]