git.iko.soy/typeable/pandoc
on master help sign in
Changed types of highlighting functions.

* highlightLaTeX, highlightHtml now return Maybe, not Either. * This is because h-k's higdlightAs no longer returns an Either.

commit7046cef26398acc6f1f1252533ed7591bd5118a8 authorJohn MacFarlane <fiddlosopher@gmail.com> dateThu 22 Dec 2011, 00:33 (15 years ago) parent1cefff6
2 files changed+16−16
src/Text/Pandoc/Highlighting.hs+12−12 src/Text/Pandoc/Writers/HTML.hs+4−4
src/Text/Pandoc/Highlighting.hs+12−12
@@ -48,7 +48,7 @@ highlight :: ([FormatOption] -> String -> [SourceLine] -> a) -- ^ Formatter
4848 -> Bool -- ^ True if inline
4949 -> Attr -- ^ Attributes of the Code or CodeBlock
5050 -> String -- ^ Raw contents of the Code or CodeBlock
51− -> Either String a -- ^ An error or the formatted result
51+ -> Maybe a -- ^ Maybe the formatted result
5252highlight formatter inline (_, classes, keyvals) rawCode =
5353 let firstNum = case reads (fromMaybe "1" $ lookup "startFrom" keyvals) of
5454 ((n,_):_) -> n
@@ -61,25 +61,25 @@ highlight formatter inline (_, classes, keyvals) rawCode =
6161 addBirdTracks = "literate" `elem` classes
6262 lcLanguages = map (map toLower) languages
6363 in case find (\c -> (map toLower c) `elem` lcLanguages) classes of
64− Nothing -> Left "Unknown or unsupported language"
65− Just language -> case highlightAs language rawCode of
66− Left err -> Left err
67− Right hl -> Right $ formatter fmtOpts language
68− $ if addBirdTracks
69− then map ((OtherTok,"> "):) hl
70− else hl
64+ Nothing -> Nothing
65+ Just language -> Just
66+ $ formatter fmtOpts language .
67+ (if addBirdTracks
68+ then map ((OtherTok,"> "):)
69+ else id)
70+ $ highlightAs language rawCode
7171
7272highlightHtml :: Bool -- ^ True if inline HTML
7373 -> Attr -- ^ Attributes of the Code or CodeBlock
7474 -> String -- ^ Raw contents of the Code or CodeBlock
75− -> Either String Html -- ^ An error or the formatted Html
75+ -> Maybe Html -- ^ Maybe formatted Html
7676highlightHtml inline attr@(id',_,_) = fmap addId . highlight formatAsHtml inline attr
7777 where addId = if null id' then id else (! A.id (toValue id'))
7878
7979highlightLaTeX :: Bool -- ^ True if inline
8080 -> Attr -- ^ Attributes of the Code or CodeBlock
8181 -> String -- ^ Raw contents of the Code or CodeBlock
82− -> Either String String -- ^ An error or the formatted LaTeX string
82+ -> Maybe String -- ^ Maybe formatted LaTeX
8383highlightLaTeX = highlight formatAsLaTeX
8484
8585#else
@@ -92,9 +92,9 @@ languages = []
9292languagesByExtension :: String -> [String]
9393languagesByExtension _ = []
9494
95−highlightHtml :: Bool -> Attr -> String -> Either String Html
95+highlightHtml :: Bool -> Attr -> String -> Maybe Html
9696highlightHtml _ _ _ = Left "Pandoc was not compiled with support for highlighting"
9797
98−highlightLaTeX :: Bool -> Attr -> String -> Either String String
98+highlightLaTeX :: Bool -> Attr -> String -> Maybe String
9999highlightLaTeX _ _ _ = Left "Pandoc was not compiled with support for highlighting"
100100#endif
src/Text/Pandoc/Writers/HTML.hs+4−4
@@ -365,13 +365,13 @@ blockToHtml opts (CodeBlock (id',classes,keyvals) rawCode) = do
365365 then classes
366366 else filter (/= "literate") classes
367367 case highlightHtml False (id',classes',keyvals) rawCode of
368− Left _ -> let attrs = attrsToHtml opts (id', classes', keyvals)
368+ Nothing -> let attrs = attrsToHtml opts (id', classes', keyvals)
369369 addBird = if "literate" `elem` classes'
370370 then unlines . map ("> " ++) . lines
371371 else unlines . lines
372372 in return $ foldl (!) H.pre attrs $ H.code
373373 $ toHtml $ addBird rawCode
374− Right h -> modify (\st -> st{ stHighlighting = True }) >>
374+ Just h -> modify (\st -> st{ stHighlighting = True }) >>
375375 return h
376376blockToHtml opts (BlockQuote blocks) =
377377 -- in S5, treat list in blockquote specially
@@ -541,10 +541,10 @@ inlineToHtml opts inline =
541541 (Emph lst) -> inlineListToHtml opts lst >>= return . H.em
542542 (Strong lst) -> inlineListToHtml opts lst >>= return . H.strong
543543 (Code attr str) -> case highlightHtml True attr str of
544− Left _ -> return
544+ Nothing -> return
545545 $ foldl (!) H.code (attrsToHtml opts attr)
546546 $ strToHtml str
547− Right h -> return h
547+ Just h -> return h
548548 (Strikeout lst) -> inlineListToHtml opts lst >>=
549549 return . H.del
550550 (SmallCaps lst) -> inlineListToHtml opts lst >>=