git.iko.soy/typeable/pandoc
on master help sign in
Removed writerHighlight; made writerHighlightStyle a Maybe.

API change. For no highlighting, set writerHighlightStyle to Nothing.

commitd1efc839f129d23fe8a6523e33a01b0b463ee409 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 22 Jan 2017, 11:36 (10 years ago) parent6f9df9b
8 files changed+42−50
pandoc.hs+4−8 src/Text/Pandoc/Options.hs+3−4 src/Text/Pandoc/Writers/Docx.hs+8−21 src/Text/Pandoc/Writers/HTML.hs+12−7 src/Text/Pandoc/Writers/LaTeX.hs+12−7 tests/Tests/Writers/HTML.hs+1−1 tests/Tests/Writers/LaTeX.hs+1−1 tests/Tests/Writers/RST.hs+1−1
pandoc.hs+4−8
@@ -114,7 +114,6 @@ convertWithOpts opts args = do
114114 , optSelfContained = selfContained
115115 , optHtml5 = html5
116116 , optHtmlQTags = htmlQTags
117− , optHighlight = highlight
118117 , optHighlightStyle = highlightStyle
119118 , optTopLevelDivision = topLevelDivision
120119 , optHTMLMathMethod = mathMethod'
@@ -324,7 +323,6 @@ convertWithOpts opts args = do
324323 writerListings = listings,
325324 writerBeamer = False,
326325 writerSlideLevel = slideLevel,
327− writerHighlight = highlight,
328326 writerHighlightStyle = highlightStyle,
329327 writerSetextHeaders = setextHeaders,
330328 writerEpubMetadata = epubMetadata,
@@ -532,8 +530,7 @@ data Opt = Opt
532530 , optSelfContained :: Bool -- ^ Make HTML accessible offline
533531 , optHtml5 :: Bool -- ^ Produce HTML5 in HTML
534532 , optHtmlQTags :: Bool -- ^ Use <q> tags in HTML
535− , optHighlight :: Bool -- ^ Highlight source code
536− , optHighlightStyle :: Style -- ^ Style to use for highlighted code
533+ , optHighlightStyle :: Maybe Style -- ^ Style to use for highlighted code
537534 , optTopLevelDivision :: TopLevelDivision -- ^ Type of the top-level divisions
538535 , optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math
539536 , optReferenceDoc :: Maybe FilePath -- ^ Path of reference doc
@@ -595,8 +592,7 @@ defaultOpts = Opt
595592 , optSelfContained = False
596593 , optHtml5 = False
597594 , optHtmlQTags = False
598− , optHighlight = True
599− , optHighlightStyle = pygments
595+ , optHighlightStyle = Just pygments
600596 , optTopLevelDivision = TopLevelDefault
601597 , optHTMLMathMethod = PlainMath
602598 , optReferenceDoc = Nothing
@@ -836,14 +832,14 @@ options =
836832
837833 , Option "" ["no-highlight"]
838834 (NoArg
839− (\opt -> return opt { optHighlight = False }))
835+ (\opt -> return opt { optHighlightStyle = Nothing }))
840836 "" -- "Don't highlight source code"
841837
842838 , Option "" ["highlight-style"]
843839 (ReqArg
844840 (\arg opt -> do
845841 case lookup (map toLower arg) highlightingStyles of
846− Just s -> return opt{ optHighlightStyle = s }
842+ Just s -> return opt{ optHighlightStyle = Just s }
847843 Nothing -> err 39 $ "Unknown style: " ++ arg)
848844 "STYLE")
849845 "" -- "Style for highlighted code"
src/Text/Pandoc/Options.hs+3−4
@@ -171,8 +171,8 @@ data WriterOptions = WriterOptions
171171 , writerSlideLevel :: Maybe Int -- ^ Force header level of slides
172172 , writerTopLevelDivision :: TopLevelDivision -- ^ Type of top-level divisions
173173 , writerListings :: Bool -- ^ Use listings package for code
174− , writerHighlight :: Bool -- ^ Highlight source code
175− , writerHighlightStyle :: Style -- ^ Style to use for highlighting
174+ , writerHighlightStyle :: Maybe Style -- ^ Style to use for highlighting
175+ -- (Nothing = no highlighting)
176176 , writerSetextHeaders :: Bool -- ^ Use setext headers for levels 1-2 in markdown
177177 , writerEpubVersion :: Maybe EPUBVersion -- ^ Nothing or EPUB version
178178 , writerEpubMetadata :: String -- ^ Metadata to include in EPUB
@@ -214,8 +214,7 @@ instance Default WriterOptions where
214214 , writerSlideLevel = Nothing
215215 , writerTopLevelDivision = TopLevelDefault
216216 , writerListings = False
217− , writerHighlight = False
218− , writerHighlightStyle = pygments
217+ , writerHighlightStyle = Just pygments
219218 , writerSetextHeaders = True
220219 , writerEpubVersion = Nothing
221220 , writerEpubMetadata = ""
src/Text/Pandoc/Writers/Docx.hs+8−21
@@ -52,7 +52,6 @@ import Text.Pandoc.Error (PandocError)
5252import Text.XML.Light as XML
5353import Text.TeXMath
5454import Text.Pandoc.Readers.Docx.StyleMap
55−import Text.Pandoc.Readers.Docx.Util (elemName)
5655import Control.Monad.Reader
5756import Control.Monad.State
5857import Skylighting
@@ -450,18 +449,11 @@ writeDocx opts doc@(Pandoc meta _) = do
450449
451450 let newstyles = map newParaPropToOpenXml newDynamicParaProps ++
452451 map newTextPropToOpenXml newDynamicTextProps ++
453− (styleToOpenXml styleMaps $ writerHighlightStyle opts)
454− let styledoc' = styledoc{ elContent = modifyContent (elContent styledoc) }
455− where
456− modifyContent
457− | writerHighlight opts = (++ map Elem newstyles)
458− | otherwise = filter notTokStyle
459− notTokStyle (Elem el) = notStyle el || notTokId el
460− notTokStyle _ = True
461− notStyle = (/= elemName' "style") . elName
462− notTokId = maybe True (`notElem` tokStys) . findAttr (elemName' "styleId")
463− tokStys = "SourceCode" : map show (enumFromTo KeywordTok NormalTok)
464− elemName' = elemName (sNameSpaces styleMaps) "w"
452+ (case writerHighlightStyle opts of
453+ Nothing -> []
454+ Just sty -> (styleToOpenXml styleMaps sty))
455+ let styledoc' = styledoc{ elContent = elContent styledoc ++
456+ map Elem newstyles }
465457 let styleEntry = toEntry stylepath epochtime $ renderXml styledoc'
466458
467459 -- construct word/numbering.xml
@@ -1130,11 +1122,9 @@ inlineToOpenXML' opts (Code attrs str) = do
11301122 [ rCustomStyle (show toktype) ]
11311123 , mknode "w:t" [("xml:space","preserve")] (T.unpack tok) ]
11321124 withTextProp (rCustomStyle "VerbatimChar")
1133− $ if writerHighlight opts
1134− then case highlight formatOpenXML attrs str of
1135− Nothing -> unhighlighted
1136− Just h -> return h
1137− else unhighlighted
1125+ $ case writerHighlightStyle opts >> highlight formatOpenXML attrs str of
1126+ Just h -> return h
1127+ Nothing -> unhighlighted
11381128inlineToOpenXML' opts (Note bs) = do
11391129 notes <- gets stFootnotes
11401130 notenum <- (lift . lift) getUniqueId
@@ -1249,9 +1239,6 @@ inlineToOpenXML' opts (Image attr alt (src, title)) = do
12491239br :: Element
12501240br = breakElement "textWrapping"
12511241
1252−pageBreak :: Element
1253−pageBreak = breakElement "page"
1254−
12551242breakElement :: String -> Element
12561243breakElement kind = mknode "w:r" [] [mknode "w:br" [("w:type",kind)] () ]
12571244
src/Text/Pandoc/Writers/HTML.hs+12−7
@@ -179,8 +179,10 @@ pandocToHtml opts (Pandoc meta blocks) = do
179179 | otherwise -> mempty
180180 Nothing -> mempty
181181 let context = (if stHighlighting st
182− then defField "highlighting-css"
183− (styleToCss $ writerHighlightStyle opts)
182+ then case writerHighlightStyle opts of
183+ Just sty -> defField "highlighting-css"
184+ (styleToCss sty)
185+ Nothing -> id
184186 else id) $
185187 (if stMath st
186188 then defField "math" (renderHtml math)
@@ -509,8 +511,9 @@ blockToHtml opts (CodeBlock (id',classes,keyvals) rawCode) = do
509511 adjCode = if tolhs
510512 then unlines . map ("> " ++) . lines $ rawCode
511513 else rawCode
512− hlCode = if writerHighlight opts -- check highlighting options
513− then highlight formatHtmlBlock (id',classes',keyvals) adjCode
514+ hlCode = if isJust (writerHighlightStyle opts)
515+ then highlight formatHtmlBlock
516+ (id',classes',keyvals) adjCode
514517 else Nothing
515518 case hlCode of
516519 Nothing -> return $ addAttrs opts (id',classes,keyvals)
@@ -702,7 +705,8 @@ annotateMML e tex = math (unode "semantics" [cs, unode "annotation" (annotAttrs,
702705
703706
704707-- | Convert Pandoc inline element to HTML.
705−inlineToHtml :: PandocMonad m => WriterOptions -> Inline -> StateT WriterState m Html
708+inlineToHtml :: PandocMonad m
709+ => WriterOptions -> Inline -> StateT WriterState m Html
706710inlineToHtml opts inline =
707711 case inline of
708712 (Str str) -> return $ strToHtml str
@@ -739,8 +743,9 @@ inlineToHtml opts inline =
739743 modify $ \st -> st{ stHighlighting = True }
740744 return $ addAttrs opts (id',[],keyvals) h
741745 where (id',_,keyvals) = attr
742− hlCode = if writerHighlight opts
743− then highlight formatHtmlInline attr str
746+ hlCode = if isJust (writerHighlightStyle opts)
747+ then highlight formatHtmlInline
748+ attr str
744749 else Nothing
745750 (Strikeout lst) -> inlineListToHtml opts lst >>=
746751 return . H.del
src/Text/Pandoc/Writers/LaTeX.hs+12−7
@@ -188,8 +188,11 @@ pandocToLaTeX options (Pandoc meta blocks) = do
188188 defField "listings" (writerListings options || stLHS st) $
189189 defField "beamer" (writerBeamer options) $
190190 (if stHighlighting st
191− then defField "highlighting-macros" (styleToLaTeX
192− $ writerHighlightStyle options )
191+ then case writerHighlightStyle options of
192+ Just sty ->
193+ defField "highlighting-macros"
194+ (styleToLaTeX sty)
195+ Nothing -> id
193196 else id) $
194197 (case writerCiteMethod options of
195198 Natbib -> defField "biblio-title" biblioTitle .
@@ -512,10 +515,11 @@ blockToLaTeX (CodeBlock (identifier,classes,keyvalAttr) str) = do
512515 return (flush $ linkAnchor $$ text (T.unpack h))
513516 case () of
514517 _ | isEnabled Ext_literate_haskell opts && "haskell" `elem` classes &&
515− "literate" `elem` classes -> lhsCodeBlock
516− | writerListings opts -> listingsCodeBlock
517− | writerHighlight opts && not (null classes) -> highlightedCodeBlock
518− | otherwise -> rawCodeBlock
518+ "literate" `elem` classes -> lhsCodeBlock
519+ | writerListings opts -> listingsCodeBlock
520+ | not (null classes) && isJust (writerHighlightStyle opts)
521+ -> highlightedCodeBlock
522+ | otherwise -> rawCodeBlock
519523blockToLaTeX (RawBlock f x)
520524 | f == Format "latex" || f == Format "tex"
521525 = return $ text x
@@ -904,7 +908,8 @@ inlineToLaTeX (Code (_,classes,_) str) = do
904908 inHeading <- gets stInHeading
905909 case () of
906910 _ | writerListings opts && not inHeading -> listingsCode
907− | writerHighlight opts && not (null classes) -> highlightCode
911+ | isJust (writerHighlightStyle opts) && not (null classes)
912+ -> highlightCode
908913 | otherwise -> rawCode
909914 where listingsCode = do
910915 inNote <- gets stInNote
tests/Tests/Writers/HTML.hs+1−1
@@ -31,7 +31,7 @@ tests :: [Test]
3131tests = [ testGroup "inline code"
3232 [ "basic" =: code "@&" =?> "<code>@&amp;</code>"
3333 , "haskell" =: codeWith ("",["haskell"],[]) ">>="
34− =?> "<code class=\"haskell\">&gt;&gt;=</code>"
34+ =?> "<code class=\"sourceCode haskell\"><span class=\"fu\">&gt;&gt;=</span></code>"
3535 , "nolanguage" =: codeWith ("",["nolanguage"],[]) ">>="
3636 =?> "<code class=\"nolanguage\">&gt;&gt;=</code>"
3737 ]
tests/Tests/Writers/LaTeX.hs+1−1
@@ -8,7 +8,7 @@ import Text.Pandoc.Arbitrary ()
88import Text.Pandoc.Builder
99
1010latex :: (ToPandoc a) => a -> String
11−latex = latexWithOpts def{ writerHighlight = True }
11+latex = latexWithOpts def
1212
1313latexListing :: (ToPandoc a) => a -> String
1414latexListing = latexWithOpts def{ writerListings = True }
tests/Tests/Writers/RST.hs+1−1
@@ -10,7 +10,7 @@ import Text.Pandoc.Arbitrary()
1010infix 4 =:
1111(=:) :: (ToString a, ToPandoc a)
1212 => String -> (a, String) -> Test
13−(=:) = test (purely (writeRST def{ writerHighlight = True }) . toPandoc)
13+(=:) = test (purely (writeRST def . toPandoc))
1414
1515tests :: [Test]
1616tests = [ testGroup "rubrics"