From 7046cef26398acc6f1f1252533ed7591bd5118a8 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 22 Dec 2011 00:33:38 -0800 Subject: Changed types of highlighting functions. * highlightLaTeX, highlightHtml now return Maybe, not Either. * This is because h-k's higdlightAs no longer returns an Either. --- src/Text/Pandoc/Highlighting.hs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/Text/Pandoc/Highlighting.hs') diff --git a/src/Text/Pandoc/Highlighting.hs b/src/Text/Pandoc/Highlighting.hs index b7d29aa61..282c13930 100644 --- a/src/Text/Pandoc/Highlighting.hs +++ b/src/Text/Pandoc/Highlighting.hs @@ -48,7 +48,7 @@ highlight :: ([FormatOption] -> String -> [SourceLine] -> a) -- ^ Formatter -> Bool -- ^ True if inline -> Attr -- ^ Attributes of the Code or CodeBlock -> String -- ^ Raw contents of the Code or CodeBlock - -> Either String a -- ^ An error or the formatted result + -> Maybe a -- ^ Maybe the formatted result highlight formatter inline (_, classes, keyvals) rawCode = let firstNum = case reads (fromMaybe "1" $ lookup "startFrom" keyvals) of ((n,_):_) -> n @@ -61,25 +61,25 @@ highlight formatter inline (_, classes, keyvals) rawCode = addBirdTracks = "literate" `elem` classes lcLanguages = map (map toLower) languages in case find (\c -> (map toLower c) `elem` lcLanguages) classes of - Nothing -> Left "Unknown or unsupported language" - Just language -> case highlightAs language rawCode of - Left err -> Left err - Right hl -> Right $ formatter fmtOpts language - $ if addBirdTracks - then map ((OtherTok,"> "):) hl - else hl + Nothing -> Nothing + Just language -> Just + $ formatter fmtOpts language . + (if addBirdTracks + then map ((OtherTok,"> "):) + else id) + $ highlightAs language rawCode highlightHtml :: Bool -- ^ True if inline HTML -> Attr -- ^ Attributes of the Code or CodeBlock -> String -- ^ Raw contents of the Code or CodeBlock - -> Either String Html -- ^ An error or the formatted Html + -> Maybe Html -- ^ Maybe formatted Html highlightHtml inline attr@(id',_,_) = fmap addId . highlight formatAsHtml inline attr where addId = if null id' then id else (! A.id (toValue id')) highlightLaTeX :: Bool -- ^ True if inline -> Attr -- ^ Attributes of the Code or CodeBlock -> String -- ^ Raw contents of the Code or CodeBlock - -> Either String String -- ^ An error or the formatted LaTeX string + -> Maybe String -- ^ Maybe formatted LaTeX highlightLaTeX = highlight formatAsLaTeX #else @@ -92,9 +92,9 @@ languages = [] languagesByExtension :: String -> [String] languagesByExtension _ = [] -highlightHtml :: Bool -> Attr -> String -> Either String Html +highlightHtml :: Bool -> Attr -> String -> Maybe Html highlightHtml _ _ _ = Left "Pandoc was not compiled with support for highlighting" -highlightLaTeX :: Bool -> Attr -> String -> Either String String +highlightLaTeX :: Bool -> Attr -> String -> Maybe String highlightLaTeX _ _ _ = Left "Pandoc was not compiled with support for highlighting" #endif -- cgit v1.2.3