git.iko.soy/typeable/pandoc
on master help sign in
Changed types of highlighting functions.
7046cefJohn MacFarlane
src/Text/Pandoc/Highlighting.hs+12−12
@@ -48,7 +48,7 @@ highlight :: ([FormatOption] -> String -> [SourceLine] -> a) -- ^ Formatter
48 -> Bool -- ^ True if inline
48 -> Bool -- ^ True if inline
49 -> Attr -- ^ Attributes of the Code or CodeBlock
49 -> Attr -- ^ Attributes of the Code or CodeBlock
50 -> String -- ^ Raw contents of the Code or CodeBlock
50 -> 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
52highlight formatter inline (_, classes, keyvals) rawCode =
52highlight formatter inline (_, classes, keyvals) rawCode =
53 let firstNum = case reads (fromMaybe "1" $ lookup "startFrom" keyvals) of
53 let firstNum = case reads (fromMaybe "1" $ lookup "startFrom" keyvals) of
54 ((n,_):_) -> n
54 ((n,_):_) -> n
@@ -61,25 +61,25 @@ highlight formatter inline (_, classes, keyvals) rawCode =
61 addBirdTracks = "literate" `elem` classes
61 addBirdTracks = "literate" `elem` classes
62 lcLanguages = map (map toLower) languages
62 lcLanguages = map (map toLower) languages
63 in case find (\c -> (map toLower c) `elem` lcLanguages) classes of
63 in case find (\c -> (map toLower c) `elem` lcLanguages) classes of
64− Nothing -> Left "Unknown or unsupported language"
64+ Nothing -> Nothing
65− Just language -> case highlightAs language rawCode of
65+ Just language -> Just
66− Left err -> Left err
67− Right hl -> Right $ formatter fmtOpts language
66+ $ formatter fmtOpts language .
68− $ if addBirdTracks
67+ (if addBirdTracks
69− then map ((OtherTok,"> "):) hl
68+ then map ((OtherTok,"> "):)
70− else hl
69+ else id)
70+ $ highlightAs language rawCode
71
71
72highlightHtml :: Bool -- ^ True if inline HTML
72highlightHtml :: Bool -- ^ True if inline HTML
73 -> Attr -- ^ Attributes of the Code or CodeBlock
73 -> Attr -- ^ Attributes of the Code or CodeBlock
74 -> String -- ^ Raw contents of the Code or CodeBlock
74 -> String -- ^ Raw contents of the Code or CodeBlock
75− -> Either String Html -- ^ An error or the formatted Html
75+ -> Maybe Html -- ^ Maybe formatted Html
76highlightHtml inline attr@(id',_,_) = fmap addId . highlight formatAsHtml inline attr
76highlightHtml inline attr@(id',_,_) = fmap addId . highlight formatAsHtml inline attr
77 where addId = if null id' then id else (! A.id (toValue id'))
77 where addId = if null id' then id else (! A.id (toValue id'))
78
78
79highlightLaTeX :: Bool -- ^ True if inline
79highlightLaTeX :: Bool -- ^ True if inline
80 -> Attr -- ^ Attributes of the Code or CodeBlock
80 -> Attr -- ^ Attributes of the Code or CodeBlock
81 -> String -- ^ Raw contents of the Code or CodeBlock
81 -> 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
83highlightLaTeX = highlight formatAsLaTeX
83highlightLaTeX = highlight formatAsLaTeX
84
84
85#else
85#else
@@ -92,9 +92,9 @@ languages = []
92languagesByExtension :: String -> [String]
92languagesByExtension :: String -> [String]
93languagesByExtension _ = []
93languagesByExtension _ = []
94
94
95−highlightHtml :: Bool -> Attr -> String -> Either String Html
95+highlightHtml :: Bool -> Attr -> String -> Maybe Html
96highlightHtml _ _ _ = Left "Pandoc was not compiled with support for highlighting"
96highlightHtml _ _ _ = Left "Pandoc was not compiled with support for highlighting"
97
97
98−highlightLaTeX :: Bool -> Attr -> String -> Either String String
98+highlightLaTeX :: Bool -> Attr -> String -> Maybe String
99highlightLaTeX _ _ _ = Left "Pandoc was not compiled with support for highlighting"
99highlightLaTeX _ _ _ = Left "Pandoc was not compiled with support for highlighting"
100#endif
100#endif
src/Text/Pandoc/Writers/HTML.hs+4−4
@@ -365,13 +365,13 @@ blockToHtml opts (CodeBlock (id',classes,keyvals) rawCode) = do
365 then classes
365 then classes
366 else filter (/= "literate") classes
366 else filter (/= "literate") classes
367 case highlightHtml False (id',classes',keyvals) rawCode of
367 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)
369 addBird = if "literate" `elem` classes'
369 addBird = if "literate" `elem` classes'
370 then unlines . map ("> " ++) . lines
370 then unlines . map ("> " ++) . lines
371 else unlines . lines
371 else unlines . lines
372 in return $ foldl (!) H.pre attrs $ H.code
372 in return $ foldl (!) H.pre attrs $ H.code
373 $ toHtml $ addBird rawCode
373 $ toHtml $ addBird rawCode
374− Right h -> modify (\st -> st{ stHighlighting = True }) >>
374+ Just h -> modify (\st -> st{ stHighlighting = True }) >>
375 return h
375 return h
376blockToHtml opts (BlockQuote blocks) =
376blockToHtml opts (BlockQuote blocks) =
377 -- in S5, treat list in blockquote specially
377 -- in S5, treat list in blockquote specially
@@ -541,10 +541,10 @@ inlineToHtml opts inline =
541 (Emph lst) -> inlineListToHtml opts lst >>= return . H.em
541 (Emph lst) -> inlineListToHtml opts lst >>= return . H.em
542 (Strong lst) -> inlineListToHtml opts lst >>= return . H.strong
542 (Strong lst) -> inlineListToHtml opts lst >>= return . H.strong
543 (Code attr str) -> case highlightHtml True attr str of
543 (Code attr str) -> case highlightHtml True attr str of
544− Left _ -> return
544+ Nothing -> return
545 $ foldl (!) H.code (attrsToHtml opts attr)
545 $ foldl (!) H.code (attrsToHtml opts attr)
546 $ strToHtml str
546 $ strToHtml str
547− Right h -> return h
547+ Just h -> return h
548 (Strikeout lst) -> inlineListToHtml opts lst >>=
548 (Strikeout lst) -> inlineListToHtml opts lst >>=
549 return . H.del
549 return . H.del
550 (SmallCaps lst) -> inlineListToHtml opts lst >>=
550 (SmallCaps lst) -> inlineListToHtml opts lst >>=