git.iko.soy/typeable/pandoc
on master help sign in
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.

commite66960fe4f3e49d33eefe56ff05ac4007a800cc5 authorAlbert Krewinkel <albert@zeitkraut.de> dateTue 8 Jun 2021, 12:35 (5 years ago) parent39afd42
1 file changed+9−9
doc/using-the-pandoc-api.md+9−9
doc/using-the-pandoc-api.md+9−9
@@ -139,7 +139,7 @@ report :: PandocMonad m => LogMessage -> m ()
139139-- | Fetch an image or other item from the local filesystem or the net.
140140-- Returns raw content and maybe mime type.
141141fetchItem :: PandocMonad m
142− => String
142+ => Text
143143 -> m (B.ByteString, Maybe MimeType)
144144
145145-- Set the resource path searched by 'fetchItem'.
@@ -213,8 +213,8 @@ of the Monoid typeclass and can easily be concatenated:
213213import Text.Pandoc.Builder
214214
215215mydoc :: Pandoc
216−mydoc = doc $ header 1 (text "Hello!")
217− <> para (emph (text "hello world") <> text ".")
216+mydoc = doc $ header 1 (text (T.pack "Hello!"))
217+ <> para (emph (text (T.pack "hello world")) <> text (T.pack "."))
218218
219219main :: IO ()
220220main = print mydoc
@@ -261,16 +261,16 @@ import qualified Data.Text as T
261261import Data.List (intersperse)
262262
263263data Station = Station{
264− address :: String
265− , name :: String
266− , cardsAccepted :: [String]
264+ address :: T.Text
265+ , name :: T.Text
266+ , cardsAccepted :: [T.Text]
267267 } deriving Show
268268
269269instance FromJSON Station where
270270 parseJSON (Object v) = Station <$>
271271 v .: "street_address" <*>
272272 v .: "station_name" <*>
273− (words <$> (v .:? "cards_accepted" .!= ""))
273+ (T.words <$> (v .:? "cards_accepted" .!= ""))
274274 parseJSON _ = mzero
275275
276276createLetter :: [Station] -> Pandoc
@@ -328,7 +328,7 @@ users to override the system defaults. If you want to disable
328328this behavior, use `setUserDataDir Nothing`.
329329
330330To render a template, use `renderTemplate'`, which takes two
331−arguments, a template (String) and a context (any instance
331+arguments, a template (Text) and a context (any instance
332332of ToJSON). If you want to create a context from the metadata
333333part of a Pandoc document, use `metaToJSON'` from
334334[Text.Pandoc.Writers.Shared]. If you also want to incorporate
@@ -426,7 +426,7 @@ concatenated together. Here's an example that returns a
426426list of the URLs linked to in a document:
427427
428428```haskell
429−listURLs :: Pandoc -> [String]
429+listURLs :: Pandoc -> [Text]
430430listURLs = query urls
431431 where urls (Link _ _ (src, _)) = [src]
432432 urls _ = []