diff options
author | John MacFarlane <fiddlosopher@gmail.com> | 2011-12-22 00:33:38 -0800 |
---|---|---|
committer | John MacFarlane <fiddlosopher@gmail.com> | 2011-12-22 00:33:38 -0800 |
commit | 7046cef26398acc6f1f1252533ed7591bd5118a8 (patch) | |
tree | 0818557a2638a3b3c0702739cb323d41a8b46da4 /src/Text/Pandoc/Highlighting.hs | |
parent | 1cefff63195087b3b3c672253b615c699cbe4922 (diff) |
Changed types of highlighting functions.
* highlightLaTeX, highlightHtml now return Maybe, not Either.
* This is because h-k's higdlightAs no longer returns an Either.
Diffstat (limited to 'src/Text/Pandoc/Highlighting.hs')
-rw-r--r-- | src/Text/Pandoc/Highlighting.hs | 24 |
1 files changed, 12 insertions, 12 deletions
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 |