Skip to content

Commit a4caa40

Browse files
committed
Fixed an issue where JSON parsing of SaveFormat was overly restrictive (#42)
1 parent dbd3556 commit a4caa40

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
pandoc-plot uses [Semantic Versioning](http://semver.org/spec/v2.0.0.html)
44

5+
## Release 1.4.2
6+
7+
* Fixed an issue where the parsing of default save format from configuration was overly restrictive (#42).
8+
59
## Release 1.4.1
610

711
* Don't automatically defer javascript scripts when creating interactive figures (#39).

src/Text/Pandoc/Filter/Plot/Monad/Types.hs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ where
3434
import Data.Char (toLower)
3535
import Data.List (intersperse)
3636
import Data.String (IsString (..))
37-
import Data.Text (Text, pack)
38-
import Data.Yaml (FromJSON, ToJSON (toJSON))
37+
import Data.Text (Text, pack, unpack)
38+
import Data.Yaml (FromJSON(..), ToJSON (toJSON), withText)
3939
import GHC.Generics (Generic)
4040
import System.FilePath (splitFileName)
4141
import System.Info (os)
@@ -229,12 +229,16 @@ instance IsString SaveFormat where
229229
mconcat
230230
[ s,
231231
" is not one of the valid save formats : ",
232-
mconcat $ intersperse ", " $ show <$> saveFormats
232+
mconcat $ intersperse ", " $ show <$> saveFormats,
233+
" (and lowercase variations). "
233234
]
234235
where
235236
saveFormats = enumFromTo minBound maxBound :: [SaveFormat]
236237

237-
instance FromJSON SaveFormat
238+
-- | Use the IsString instance to parse JSON so that the parsing is flexible
239+
-- with respect to uppercase/lowercase (#42)
240+
instance FromJSON SaveFormat where
241+
parseJSON = withText "SaveFormat" (pure . fromString . unpack)
238242

239243
instance ToJSON SaveFormat where
240244
toJSON = toJSON . extension

0 commit comments

Comments
 (0)