summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2011-12-26 22:49:50 -0800
committerJohn MacFarlane <fiddlosopher@gmail.com>2011-12-26 22:49:50 -0800
commit45958de0e1ae4a1ed18659f33d3f710f64d57f84 (patch)
treeaa100fa3ab521b42fa3d564b3910a386dc094d1d /src/Text/Pandoc/Writers
parentcc18291baf863a59fb17a63c5c09d69da8c86b01 (diff)
Updated highlighting for highlighting-kate 0.4.
Text.Pandoc.Highlighting now exports just one new function, 'highlight', and reexports all the other functions from highlighting-kate that are used in the writers. This should make it easy to switch highlighting engines if that is ever desired.
Diffstat (limited to 'src/Text/Pandoc/Writers')
-rw-r--r--src/Text/Pandoc/Writers/Docbook.hs2
-rw-r--r--src/Text/Pandoc/Writers/HTML.hs26
-rw-r--r--src/Text/Pandoc/Writers/LaTeX.hs12
3 files changed, 24 insertions, 16 deletions
diff --git a/src/Text/Pandoc/Writers/Docbook.hs b/src/Text/Pandoc/Writers/Docbook.hs
index 9f8b921e7..150033f3f 100644
--- a/src/Text/Pandoc/Writers/Docbook.hs
+++ b/src/Text/Pandoc/Writers/Docbook.hs
@@ -35,7 +35,7 @@ import Text.Pandoc.Templates (renderTemplate)
import Text.Pandoc.Readers.TeXMath
import Data.List ( isPrefixOf, intercalate, isSuffixOf )
import Data.Char ( toLower )
-import Text.Pandoc.Highlighting (languages, languagesByExtension)
+import Text.Pandoc.Highlighting ( languages, languagesByExtension )
import Text.Pandoc.Pretty
-- | Convert list of authors to a docbook <author> section
diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs
index 96fa5e906..1cee2b8e6 100644
--- a/src/Text/Pandoc/Writers/HTML.hs
+++ b/src/Text/Pandoc/Writers/HTML.hs
@@ -35,7 +35,8 @@ import Text.Pandoc.CharacterReferences ( decodeCharacterReferences )
import Text.Pandoc.Shared
import Text.Pandoc.Templates
import Text.Pandoc.Readers.TeXMath
-import Text.Pandoc.Highlighting ( highlightHtml, defaultHighlightingCss )
+import Text.Pandoc.Highlighting ( highlight, pygments, styleToHtml,
+ formatHtmlInline, formatHtmlBlock )
import Text.Pandoc.XML (stripTags, escapeStringForXML)
import Network.HTTP ( urlEncode )
import Numeric ( showHex )
@@ -153,7 +154,7 @@ pandocToHtml opts (Pandoc (Meta title' authors' date') blocks) = do
("/*<![CDATA[*/\n" ++ s ++ "/*]]>*/\n")
Nothing -> mempty
else mempty
- let newvars = [("highlighting-css", defaultHighlightingCss) |
+ let newvars = [("highlighting-css", renderHtml $ styleToHtml pygments) |
stHighlighting st] ++
[("math", renderHtml math) | stMath st]
return (tit, auths, date, toc, thebody, newvars)
@@ -361,16 +362,21 @@ blockToHtml _ (RawBlock "html" str) = return $ preEscapedString str
blockToHtml _ (RawBlock _ _) = return mempty
blockToHtml _ (HorizontalRule) = return H.hr
blockToHtml opts (CodeBlock (id',classes,keyvals) rawCode) = do
- let classes' = if writerLiterateHaskell opts
- then classes
+ let tolhs = writerLiterateHaskell opts &&
+ any (\c -> map toLower c == "haskell") classes &&
+ any (\c -> map toLower c == "literate") classes
+ classes' = if tolhs
+ then map (\c -> if map toLower c == "haskell"
+ then "literatehaskell"
+ else c) classes
else filter (/= "literate") classes
- case highlightHtml False (id',classes',keyvals) rawCode of
+ adjCode = if tolhs
+ then unlines . map ("> " ++) . lines $ rawCode
+ else rawCode
+ case highlight formatHtmlBlock (id',classes,keyvals) adjCode of
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
+ $ toHtml adjCode
Just h -> modify (\st -> st{ stHighlighting = True }) >>
return h
blockToHtml opts (BlockQuote blocks) =
@@ -540,7 +546,7 @@ inlineToHtml opts inline =
(Apostrophe) -> return $ strToHtml "’"
(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
+ (Code attr str) -> case highlight formatHtmlInline attr str of
Nothing -> return
$ foldl (!) H.code (attrsToHtml opts attr)
$ strToHtml str
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs
index cb7df6b8a..117ecca51 100644
--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -41,7 +41,8 @@ import Data.Char ( toLower, isPunctuation )
import Control.Monad.State
import Text.Pandoc.Pretty
import System.FilePath (dropExtension)
-import Text.Pandoc.Highlighting (highlightLaTeX, defaultLaTeXMacros)
+import Text.Pandoc.Highlighting (highlight, pygments, styleToLaTeX,
+ formatLaTeXInline, formatLaTeXBlock)
data WriterState =
WriterState { stInNote :: Bool -- true if we're in a note
@@ -60,7 +61,7 @@ data WriterState =
, stLHS :: Bool -- true if document has literate haskell code
, stBook :: Bool -- true if document uses book or memoir class
, stCsquotes :: Bool -- true if document uses csquotes
- , stHighlighting :: Bool -- true if document has highlighted code
+ , stHighlighting :: Bool -- true if document has highlighted code
}
-- | Convert Pandoc to LaTeX.
@@ -131,7 +132,7 @@ pandocToLaTeX options (Pandoc (Meta title authors date) blocks) = do
[ ("graphics", "yes") | stGraphics st ] ++
[ ("book-class", "yes") | stBook st] ++
[ ("listings", "yes") | writerListings options || stLHS st ] ++
- [ ("highlighting-macros", defaultLaTeXMacros) | stHighlighting st ] ++
+ [ ("highlighting-macros", styleToLaTeX pygments) | stHighlighting st ] ++
citecontext
return $ if writerStandalone options
then renderTemplate context template
@@ -160,6 +161,7 @@ stringToLaTeX isUrl = escapeStringUsing latexEscapes
, ('\x2019', "'")
, ('\x201C', "``")
, ('\x201D', "''")
+ , ('\x2026', "\\ldots{}")
]
-- | Puts contents into LaTeX command.
@@ -231,7 +233,7 @@ blockToLaTeX (CodeBlock (_,classes,keyvalAttr) str) = do
return $ flush ("\\begin{lstlisting}" <> printParams $$ text str $$
"\\end{lstlisting}") $$ cr
highlightedCodeBlock =
- case highlightLaTeX False ("",classes,keyvalAttr) str of
+ case highlight formatLaTeXBlock ("",classes,keyvalAttr) str of
Nothing -> rawCodeBlock
Just h -> modify (\st -> st{ stHighlighting = True }) >>
return (text h)
@@ -407,7 +409,7 @@ inlineToLaTeX (Code (_,classes,_) str) = do
let chr = ((enumFromTo '!' '~') \\ str) !! 0
return $ text $ "\\lstinline" ++ [chr] ++ str ++ [chr]
highlightCode = do
- case highlightLaTeX True ("",classes,[]) str of
+ case highlight formatLaTeXInline ("",classes,[]) str of
Nothing -> rawCode
Just h -> modify (\st -> st{ stHighlighting = True }) >>
return (text h)