-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCommonPrelude.hs
51 lines (44 loc) · 1.38 KB
/
CommonPrelude.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{-# LANGUAGE CPP #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -Wno-orphans #-}
module CommonPrelude (
module X,
-- * Text Utilities
Text,
-- * Useful operators for monads and functors
($>),
(<&>),
(>=>),
(<|>),
)
where
import Control.Applicative ((<|>))
import Control.Monad ((>=>))
import Data.ByteString.Builder (toLazyByteString)
import Data.Functor (($>), (<&>))
import Data.Text (Text, unpack)
import Data.Time (Day)
import Djot (Doc, renderHtml)
import Djot.Djot (RenderOptions (RenderOptions))
import Language.Haskell.TH.Syntax (Lift (..), liftData)
import Lucid (ToHtml (..))
import Prelude as X
#if !MIN_VERSION_aeson(2,2,0)
import Data.Aeson (FromJSON (parseJSON), withText)
import Network.URI (URI, parseURI)
#endif
instance Lift Day where
lift = liftData
instance ToHtml Doc where
toHtmlRaw = toHtmlRaw . toLazyByteString . renderHtml (RenderOptions False)
toHtml = toHtml . toLazyByteString . renderHtml (RenderOptions False)
#if !MIN_VERSION_aeson(2,2,0)
-- The reason we don't specify the aeson version is that nixpkgs defaults to a
-- lower version, which is _fine_ except if we enforce >=2.2.0.0 then we get
-- build errors with various HLS plugins and this is just very tedious.
instance FromJSON URI where
parseJSON = withText "URI" $ \(unpack -> t) ->
case parseURI t of
Just uri -> pure uri
Nothing -> fail $ "invalid uri: " <> t
#endif