git.iko.soy/typeable/pandoc
on master help sign in
Added `--highlight-style` and `--no-highlight` options.
commit16629bf1ce268e86f849ddb44435c6829fd933d2 authorJohn MacFarlane <fiddlosopher@gmail.com> dateTue 27 Dec 2011, 23:46 (15 years ago) parent3122959
6 files changed+67−15
README+17−6 src/Text/Pandoc/Highlighting.hs+6 src/Text/Pandoc/Shared.hs+3 src/Text/Pandoc/Writers/HTML.hs+3−2 src/Text/Pandoc/Writers/LaTeX.hs+3−2 src/pandoc.hs+35−5
README+17−6
@@ -217,6 +217,15 @@ Options
217217: Produce HTML5 instead of HTML4. This option has no effect for writers
218218 other than `html`.
219219
220+`--no-highlight`
221+: Disables syntax highlighting for code blocks and inlines, even when
222+ a language attribute is given.
223+
224+`--highlight-style`=*STYLE*
225+: Specifies the coloring style to be used in highlighted source code.
226+ Options are `pygments` (the default), `kate`, `monochrome`,
227+ `espresso`, `haddock`, and `tango`.
228+
220229`-m` [*URL*], `--latexmathml`[=*URL*]
221230: Use the [LaTeXMathML] script to display embedded TeX math in HTML output.
222231 To insert a link to a local copy of the `LaTeXMathML.js` script,
@@ -837,15 +846,15 @@ this syntax:
837846 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.haskell .numberLines}
838847 qsort [] = []
839848 qsort (x:xs) = qsort (filter (< x) xs) ++ [x] ++
840− qsort (filter (>= x) xs)
849+ qsort (filter (>= x) xs)
841850 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
842851
843852Some output formats can use this information to do syntax highlighting.
844−Currently, the only output format that uses this information is HTML.
845−If highlighting is supported for your output format and language, then the
846−code block above will appear highlighted, with numbered lines. (To see
847−which languages are supported, do `pandoc --version`.) Otherwise, the
848−code block above will appear as follows:
853+Currently, the only output formats that uses this information are HTML
854+and LaTeX. If highlighting is supported for your output format and language,
855+then the code block above will appear highlighted, with numbered lines. (To
856+see which languages are supported, do `pandoc --version`.) Otherwise, the code
857+block above will appear as follows:
849858
850859 <pre class="haskell">
851860 <code>
@@ -853,6 +862,8 @@ code block above will appear as follows:
853862 </code>
854863 </pre>
855864
865+To prevent all highlighting, use the `--no-highlight` flag.
866+To set the highlighting style, use `--highlight-style`.
856867
857868Lists
858869-----
src/Text/Pandoc/Highlighting.hs+6
@@ -38,6 +38,12 @@ module Text.Pandoc.Highlighting ( languages
3838 , formatHtmlBlock
3939 , styleToHtml
4040 , pygments
41+ , espresso
42+ , tango
43+ , kate
44+ , monochrome
45+ , haddock
46+ , Style
4147 ) where
4248import Text.Pandoc.Definition
4349import Text.Highlighting.Kate
src/Text/Pandoc/Shared.hs+3
@@ -81,6 +81,7 @@ import System.FilePath ( (</>) )
8181import Data.Generics (Typeable, Data)
8282import qualified Control.Monad.State as S
8383import Paths_pandoc (getDataFileName)
84+import Text.Pandoc.Highlighting (Style, pygments)
8485
8586--
8687-- List processing
@@ -479,6 +480,7 @@ data WriterOptions = WriterOptions
479480 , writerChapters :: Bool -- ^ Use "chapter" for top-level sects
480481 , writerListings :: Bool -- ^ Use listings package for code
481482 , writerHighlight :: Bool -- ^ Highlight source code
483+ , writerHighlightStyle :: Style -- ^ Style to use for highlighting
482484 } deriving Show
483485
484486{-# DEPRECATED writerXeTeX "writerXeTeX no longer does anything" #-}
@@ -513,6 +515,7 @@ defaultWriterOptions =
513515 , writerChapters = False
514516 , writerListings = False
515517 , writerHighlight = False
518+ , writerHighlightStyle = pygments
516519 }
517520
518521--
src/Text/Pandoc/Writers/HTML.hs+3−2
@@ -35,7 +35,7 @@ import Text.Pandoc.CharacterReferences ( decodeCharacterReferences )
3535import Text.Pandoc.Shared
3636import Text.Pandoc.Templates
3737import Text.Pandoc.Readers.TeXMath
38−import Text.Pandoc.Highlighting ( highlight, pygments, styleToHtml,
38+import Text.Pandoc.Highlighting ( highlight, styleToHtml,
3939 formatHtmlInline, formatHtmlBlock )
4040import Text.Pandoc.XML (stripTags, escapeStringForXML)
4141import Network.HTTP ( urlEncode )
@@ -154,7 +154,8 @@ pandocToHtml opts (Pandoc (Meta title' authors' date') blocks) = do
154154 ("/*<![CDATA[*/\n" ++ s ++ "/*]]>*/\n")
155155 Nothing -> mempty
156156 else mempty
157− let newvars = [("highlighting-css", renderHtml $ styleToHtml pygments) |
157+ let newvars = [("highlighting-css", renderHtml $ styleToHtml
158+ $ writerHighlightStyle opts) |
158159 stHighlighting st] ++
159160 [("math", renderHtml math) | stMath st]
160161 return (tit, auths, date, toc, thebody, newvars)
src/Text/Pandoc/Writers/LaTeX.hs+3−2
@@ -41,7 +41,7 @@ import Data.Char ( toLower, isPunctuation )
4141import Control.Monad.State
4242import Text.Pandoc.Pretty
4343import System.FilePath (dropExtension)
44−import Text.Pandoc.Highlighting (highlight, pygments, styleToLaTeX,
44+import Text.Pandoc.Highlighting (highlight, styleToLaTeX,
4545 formatLaTeXInline, formatLaTeXBlock)
4646
4747data WriterState =
@@ -132,7 +132,8 @@ pandocToLaTeX options (Pandoc (Meta title authors date) blocks) = do
132132 [ ("graphics", "yes") | stGraphics st ] ++
133133 [ ("book-class", "yes") | stBook st] ++
134134 [ ("listings", "yes") | writerListings options || stLHS st ] ++
135− [ ("highlighting-macros", styleToLaTeX pygments) | stHighlighting st ] ++
135+ [ ("highlighting-macros", styleToLaTeX
136+ $ writerHighlightStyle opts ) | stHighlighting st ] ++
136137 citecontext
137138 return $ if writerStandalone options
138139 then renderTemplate context template
src/pandoc.hs+35−5
@@ -33,7 +33,8 @@ import Text.Pandoc
3333import Text.Pandoc.Shared ( tabFilter, ObfuscationMethod (..), readDataFile,
3434 headerShift, findDataFile, normalize )
3535import Text.Pandoc.SelfContained ( makeSelfContained )
36−import Text.Pandoc.Highlighting ( languages )
36+import Text.Pandoc.Highlighting ( languages, Style, tango, pygments,
37+ espresso, kate, haddock, monochrome )
3738import System.Environment ( getArgs, getProgName )
3839import System.Exit ( exitWith, ExitCode (..) )
3940import System.FilePath
@@ -45,7 +46,7 @@ import System.IO ( stdout, stderr )
4546import System.IO.Error ( isDoesNotExistError )
4647import Control.Exception.Extensible ( throwIO )
4748import qualified Text.Pandoc.UTF8 as UTF8
48−import Text.CSL
49+import qualified Text.CSL as CSL
4950import Text.Pandoc.Biblio
5051import Control.Monad (when, unless, liftM)
5152import Network.HTTP (simpleHTTP, mkRequest, getResponseBody, RequestMethod(..))
@@ -100,6 +101,8 @@ data Opt = Opt
100101 , optXeTeX :: Bool -- ^ Format latex for xetex
101102 , optSmart :: Bool -- ^ Use smart typography
102103 , optHtml5 :: Bool -- ^ Produce HTML5 in HTML
104+ , optHighlight :: Bool -- ^ Highlight source code
105+ , optHighlightStyle :: Style -- ^ Style to use for highlighted code
103106 , optChapters :: Bool -- ^ Use chapter for top-level sects
104107 , optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math
105108 , optReferenceODT :: Maybe FilePath -- ^ Path of reference.odt
@@ -144,6 +147,8 @@ defaultOpts = Opt
144147 , optXeTeX = False
145148 , optSmart = False
146149 , optHtml5 = False
150+ , optHighlight = True
151+ , optHighlightStyle = pygments
147152 , optChapters = False
148153 , optHTMLMathMethod = PlainMath
149154 , optReferenceODT = Nothing
@@ -242,6 +247,28 @@ options =
242247 (\opt -> return opt { optHtml5 = True }))
243248 "" -- "Produce HTML5 in HTML output"
244249
250+ , Option "" ["no-highlight"]
251+ (NoArg
252+ (\opt -> return opt { optHighlight = False }))
253+ "" -- "Don't highlight source code"
254+
255+ , Option "" ["highlight-style"]
256+ (ReqArg
257+ (\arg opt -> do
258+ newStyle <- case map toLower arg of
259+ "pygments" -> return pygments
260+ "tango" -> return tango
261+ "espresso" -> return espresso
262+ "kate" -> return kate
263+ "monochrome" -> return monochrome
264+ "haddock" -> return haddock
265+ _ -> UTF8.hPutStrLn stderr
266+ ("Unknown style: " ++ arg) >>
267+ exitWith (ExitFailure 39)
268+ return opt{ optHighlightStyle = newStyle })
269+ "STYLE")
270+ "" -- "Style for highlighted code"
271+
245272 , Option "m" ["latexmathml", "asciimathml"]
246273 (OptArg
247274 (\arg opt ->
@@ -691,6 +718,8 @@ main = do
691718 , optSelfContained = selfContained
692719 , optSmart = smart
693720 , optHtml5 = html5
721+ , optHighlight = highlight
722+ , optHighlightStyle = highlightStyle
694723 , optChapters = chapters
695724 , optHTMLMathMethod = mathMethod
696725 , optReferenceODT = referenceODT
@@ -774,7 +803,7 @@ main = do
774803 return $ ("mathml-script", s) : variables
775804 _ -> return variables
776805
777− refs <- mapM (\f -> catch (readBiblioFile f) $ \e -> do
806+ refs <- mapM (\f -> catch (CSL.readBiblioFile f) $ \e -> do
778807 UTF8.hPutStrLn stderr $ "Error reading bibliography `" ++ f ++ "'"
779808 UTF8.hPutStrLn stderr $ show e
780809 exitWith (ExitFailure 23)) reffiles >>= \rs -> return $ concat rs
@@ -795,7 +824,7 @@ main = do
795824 stateLiterateHaskell = "+lhs" `isSuffixOf` readerName' ||
796825 lhsExtension sources,
797826 stateStandalone = standalone',
798− stateCitations = map refId refs,
827+ stateCitations = map CSL.refId refs,
799828 stateSmart = smart || writerName' `elem`
800829 ["latex", "context", "latex+lhs", "man"],
801830 stateColumns = columns,
@@ -835,7 +864,8 @@ main = do
835864 slideVariant == DZSlides,
836865 writerChapters = chapters,
837866 writerListings = listings,
838− writerHighlight = True }
867+ writerHighlight = highlight,
868+ writerHighlightStyle = highlightStyle }
839869
840870 when (isNonTextOutput writerName' && outputFile == "-") $
841871 do UTF8.hPutStrLn stderr ("Error: Cannot write " ++ writerName' ++ " output to stdout.\n" ++