aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Highlighting.hs24
-rw-r--r--src/Text/Pandoc/Writers/HTML.hs8
2 files changed, 16 insertions, 16 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
diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs
index 64a1c993d..96fa5e906 100644
--- a/src/Text/Pandoc/Writers/HTML.hs
+++ b/src/Text/Pandoc/Writers/HTML.hs
@@ -365,13 +365,13 @@ blockToHtml opts (CodeBlock (id',classes,keyvals) rawCode) = do
then classes
else filter (/= "literate") classes
case highlightHtml False (id',classes',keyvals) rawCode of
- Left _ -> let attrs = attrsToHtml opts (id', classes', keyvals)
+ Nothing -> let attrs = attrsToHtml opts (id', classes', keyvals)
addBird = if "literate" `elem` classes'
then unlines . map ("> " ++) . lines
else unlines . lines
in return $ foldl (!) H.pre attrs $ H.code
$ toHtml $ addBird rawCode
- Right h -> modify (\st -> st{ stHighlighting = True }) >>
+ Just h -> modify (\st -> st{ stHighlighting = True }) >>
return h
blockToHtml opts (BlockQuote blocks) =
-- in S5, treat list in blockquote specially
@@ -541,10 +541,10 @@ inlineToHtml opts inline =
(Emph lst) -> inlineListToHtml opts lst >>= return . H.em
(Strong lst) -> inlineListToHtml opts lst >>= return . H.strong
(Code attr str) -> case highlightHtml True attr str of
- Left _ -> return
+ Nothing -> return
$ foldl (!) H.code (attrsToHtml opts attr)
$ strToHtml str
- Right h -> return h
+ Just h -> return h
(Strikeout lst) -> inlineListToHtml opts lst >>=
return . H.del
(SmallCaps lst) -> inlineListToHtml opts lst >>=