using-the-pandoc-api.md: switch from String to Text

Fixed examples that would no longer compile with current library
versions, as the API now uses Text instead of String in most places.
This commit is contained in:
Albert Krewinkel 2021-06-08 12:35:55 +02:00
parent 39afd4297f
commit e66960fe4f
No known key found for this signature in database
GPG key ID: 388DC0B21F631124

View file

@ -139,7 +139,7 @@ report :: PandocMonad m => LogMessage -> m ()
-- | Fetch an image or other item from the local filesystem or the net. -- | Fetch an image or other item from the local filesystem or the net.
-- Returns raw content and maybe mime type. -- Returns raw content and maybe mime type.
fetchItem :: PandocMonad m fetchItem :: PandocMonad m
=> String => Text
-> m (B.ByteString, Maybe MimeType) -> m (B.ByteString, Maybe MimeType)
-- Set the resource path searched by 'fetchItem'. -- Set the resource path searched by 'fetchItem'.
@ -213,8 +213,8 @@ of the Monoid typeclass and can easily be concatenated:
import Text.Pandoc.Builder import Text.Pandoc.Builder
mydoc :: Pandoc mydoc :: Pandoc
mydoc = doc $ header 1 (text "Hello!") mydoc = doc $ header 1 (text (T.pack "Hello!"))
<> para (emph (text "hello world") <> text ".") <> para (emph (text (T.pack "hello world")) <> text (T.pack "."))
main :: IO () main :: IO ()
main = print mydoc main = print mydoc
@ -261,16 +261,16 @@ import qualified Data.Text as T
import Data.List (intersperse) import Data.List (intersperse)
data Station = Station{ data Station = Station{
address :: String address :: T.Text
, name :: String , name :: T.Text
, cardsAccepted :: [String] , cardsAccepted :: [T.Text]
} deriving Show } deriving Show
instance FromJSON Station where instance FromJSON Station where
parseJSON (Object v) = Station <$> parseJSON (Object v) = Station <$>
v .: "street_address" <*> v .: "street_address" <*>
v .: "station_name" <*> v .: "station_name" <*>
(words <$> (v .:? "cards_accepted" .!= "")) (T.words <$> (v .:? "cards_accepted" .!= ""))
parseJSON _ = mzero parseJSON _ = mzero
createLetter :: [Station] -> Pandoc createLetter :: [Station] -> Pandoc
@ -328,7 +328,7 @@ users to override the system defaults. If you want to disable
this behavior, use `setUserDataDir Nothing`. this behavior, use `setUserDataDir Nothing`.
To render a template, use `renderTemplate'`, which takes two To render a template, use `renderTemplate'`, which takes two
arguments, a template (String) and a context (any instance arguments, a template (Text) and a context (any instance
of ToJSON). If you want to create a context from the metadata of ToJSON). If you want to create a context from the metadata
part of a Pandoc document, use `metaToJSON'` from part of a Pandoc document, use `metaToJSON'` from
[Text.Pandoc.Writers.Shared]. If you also want to incorporate [Text.Pandoc.Writers.Shared]. If you also want to incorporate
@ -426,7 +426,7 @@ concatenated together. Here's an example that returns a
list of the URLs linked to in a document: list of the URLs linked to in a document:
```haskell ```haskell
listURLs :: Pandoc -> [String] listURLs :: Pandoc -> [Text]
listURLs = query urls listURLs = query urls
where urls (Link _ _ (src, _)) = [src] where urls (Link _ _ (src, _)) = [src]
urls _ = [] urls _ = []