@@ -1,8 +1,8 @@
1−{-# LANGUAGE OverloadedStrings #-}
2−{-# LANGUAGE PatternGuards #-}
3−{-# LANGUAGE FlexibleInstances #-}
1+{-# LANGUAGE FlexibleInstances #-}
42{-# LANGUAGE MultiParamTypeClasses #-}
5−{-# LANGUAGE ScopedTypeVariables #-}
3+{-# LANGUAGE OverloadedStrings #-}
4+{-# LANGUAGE PatternGuards #-}
5+{-# LANGUAGE ScopedTypeVariables #-}
66{-
77Copyright (C) 2006-2017 John MacFarlane <jgm@berkeley.edu>
88
@@ -44,35 +44,33 @@ import Control.Applicative (many, optional, (<|>))
4444import Control.Monad
4545import Control.Monad.Except (throwError)
4646import Control.Monad.Trans (lift)
47−import Data.Char (chr, isAlphaNum, isLetter, ord, isDigit, toLower)
47+import Data.Char (chr, isAlphaNum, isDigit, isLetter, ord, toLower)
4848import Data.Default
49−import Data.Text (Text)
50−import qualified Data.Text as T
5149import Data.List (intercalate, isPrefixOf)
5250import qualified Data.Map as M
53−import qualified Data.Set as Set
5451import Data.Maybe (fromMaybe, maybeToList)
52+import qualified Data.Set as Set
53+import Data.Text (Text)
54+import qualified Data.Text as T
5555import Safe (minimumDef)
5656import System.FilePath (addExtension, replaceExtension, takeExtension)
57+import Text.Pandoc.BCP47 (Lang (..), renderLang)
5758import Text.Pandoc.Builder
58−import Text.Pandoc.Class (PandocMonad, PandocPure, lookupEnv,
59+import Text.Pandoc.Class (PandocMonad, PandocPure, getResourcePath, lookupEnv,
5960 readFileFromDirs, report, setResourcePath,
60− getResourcePath, setTranslations, translateTerm)
61−import qualified Text.Pandoc.Translations as Translations
62−import Text.Pandoc.BCP47 (Lang(..), renderLang)
61+ setTranslations, translateTerm)
62+import Text.Pandoc.Error (PandocError (PandocMacroLoop, PandocParseError, PandocParsecError))
6363import Text.Pandoc.Highlighting (fromListingsLanguage, languagesByExtension)
6464import Text.Pandoc.ImageSize (numUnit, showFl)
6565import Text.Pandoc.Logging
6666import Text.Pandoc.Options
67−import Text.Pandoc.Parsing hiding (many, optional, withRaw,
68− mathInline, mathDisplay,
69− space, (<|>), spaces, blankline)
67+import Text.Pandoc.Parsing hiding (blankline, many, mathDisplay, mathInline,
68+ optional, space, spaces, withRaw, (<|>))
69+import Text.Pandoc.Readers.LaTeX.Types (ExpansionPoint (..), Macro (..),
70+ Tok (..), TokType (..))
7071import Text.Pandoc.Shared
71−import Text.Pandoc.Readers.LaTeX.Types (Macro(..), ExpansionPoint(..), Tok(..),
72− TokType(..))
72+import qualified Text.Pandoc.Translations as Translations
7373import Text.Pandoc.Walk
74−import Text.Pandoc.Error
75− (PandocError(PandocParsecError, PandocParseError, PandocMacroLoop))
7674import Text.Parsec.Pos
7775
7876-- for debugging:
@@ -100,10 +98,10 @@ parseLaTeX = do
10098 let meta = sMeta st
10199 let doc' = doc bs
102100 let headerLevel (Header n _ _) = [n]
103− headerLevel _ = []
101+ headerLevel _ = []
104102 let bottomLevel = minimumDef 1 $ query headerLevel doc'
105103 let adjustHeaders m (Header n attr ils) = Header (n+m) attr ils
106− adjustHeaders _ x = x
104+ adjustHeaders _ x = x
107105 let (Pandoc _ bs') =
108106 -- handle the case where you have \part or \chapter
109107 (if bottomLevel < 1
@@ -261,7 +259,7 @@ applyMacros s = (guardDisabled Ext_latex_macros >> return s) <|>
261259 , sMacros = extractMacros pstate }
262260 res <- runParserT retokenize lstate "math" (tokenize "math" (T.pack s))
263261 case res of
264− Left e -> fail (show e)
262+ Left e -> fail (show e)
265263 Right s' -> return s'
266264
267265rawLaTeXBlock :: (PandocMonad m, HasMacros s, HasReaderOptions s)
@@ -378,8 +376,8 @@ isSpaceOrTab '\t' = True
378376isSpaceOrTab _ = False
379377
380378isLetterOrAt :: Char -> Bool
381−isLetterOrAt '@' = True
382−isLetterOrAt c = isLetter c
379+isLetterOrAt '@' = True
380+isLetterOrAt c = isLetter c
383381
384382isLowerHex :: Char -> Bool
385383isLowerHex x = x >= '0' && x <= '9' || x >= 'a' && x <= 'f'
@@ -400,7 +398,7 @@ satisfyTok f =
400398 | otherwise = Nothing
401399 updatePos :: SourcePos -> Tok -> [Tok] -> SourcePos
402400 updatePos _spos _ (Tok pos _ _ : _) = pos
403− updatePos spos _ [] = spos
401+ updatePos spos _ [] = spos
404402
405403doMacros :: PandocMonad m => Int -> LP m ()
406404doMacros n = do
@@ -477,20 +475,20 @@ tokTypeIn toktypes (Tok _ tt _) = tt `elem` toktypes
477475controlSeq :: PandocMonad m => Text -> LP m Tok
478476controlSeq name = satisfyTok isNamed
479477 where isNamed (Tok _ (CtrlSeq n) _) = n == name
480− isNamed _ = False
478+ isNamed _ = False
481479
482480symbol :: PandocMonad m => Char -> LP m Tok
483481symbol c = satisfyTok isc
484482 where isc (Tok _ Symbol d) = case T.uncons d of
485483 Just (c',_) -> c == c'
486− _ -> False
484+ _ -> False
487485 isc _ = False
488486
489487symbolIn :: PandocMonad m => [Char] -> LP m Tok
490488symbolIn cs = satisfyTok isInCs
491489 where isInCs (Tok _ Symbol d) = case T.uncons d of
492490 Just (c,_) -> c `elem` cs
493− _ -> False
491+ _ -> False
494492 isInCs _ = False
495493
496494sp :: PandocMonad m => LP m ()
@@ -499,19 +497,19 @@ sp = whitespace <|> endline
499497whitespace :: PandocMonad m => LP m ()
500498whitespace = () <$ satisfyTok isSpaceTok
501499 where isSpaceTok (Tok _ Spaces _) = True
502− isSpaceTok _ = False
500+ isSpaceTok _ = False
503501
504502newlineTok :: PandocMonad m => LP m ()
505503newlineTok = () <$ satisfyTok isNewlineTok
506504
507505isNewlineTok :: Tok -> Bool
508506isNewlineTok (Tok _ Newline _) = True
509−isNewlineTok _ = False
507+isNewlineTok _ = False
510508
511509comment :: PandocMonad m => LP m ()
512510comment = () <$ satisfyTok isCommentTok
513511 where isCommentTok (Tok _ Comment _) = True
514− isCommentTok _ = False
512+ isCommentTok _ = False
515513
516514anyTok :: PandocMonad m => LP m Tok
517515anyTok = satisfyTok (const True)
@@ -535,7 +533,7 @@ primEscape = do
535533 | otherwise -> return (chr (ord c + 64))
536534 Nothing -> fail "Empty content of Esc1"
537535 Esc2 -> case safeRead ('0':'x':T.unpack (T.drop 2 t)) of
538− Just x -> return (chr x)
536+ Just x -> return (chr x)
539537 Nothing -> fail $ "Could not read: " ++ T.unpack t
540538 _ -> fail "Expected an Esc1 or Esc2 token" -- should not happen
541539
@@ -594,7 +592,7 @@ word = (str . T.unpack . untoken) <$> satisfyTok isWordTok
594592regularSymbol :: PandocMonad m => LP m Inlines
595593regularSymbol = (str . T.unpack . untoken) <$> satisfyTok isRegularSymbol
596594 where isRegularSymbol (Tok _ Symbol t) = not $ T.any isSpecial t
597− isRegularSymbol _ = False
595+ isRegularSymbol _ = False
598596 isSpecial c = c `Set.member` specialChars
599597
600598specialChars :: Set.Set Char
@@ -602,7 +600,7 @@ specialChars = Set.fromList "#$%&~_^\\{}"
602600
603601isWordTok :: Tok -> Bool
604602isWordTok (Tok _ Word _) = True
605−isWordTok _ = False
603+isWordTok _ = False
606604
607605inlineGroup :: PandocMonad m => LP m Inlines
608606inlineGroup = do
@@ -623,7 +621,7 @@ mkImage options src = do
623621 let replaceTextwidth (k,v) =
624622 case numUnit v of
625623 Just (num, "\\textwidth") -> (k, showFl (num * 100) ++ "%")
626− _ -> (k, v)
624+ _ -> (k, v)
627625 let kvs = map replaceTextwidth
628626 $ filter (\(k,_) -> k `elem` ["width", "height"]) options
629627 let attr = ("",[], kvs)
@@ -640,7 +638,7 @@ doxspace = do
640638 where startsWithLetter (Tok _ Word t) =
641639 case T.uncons t of
642640 Just (c, _) | isLetter c -> True
643− _ -> False
641+ _ -> False
644642 startsWithLetter _ = False
645643
646644
@@ -686,7 +684,7 @@ singleQuote = do
686684 where startsWithLetter (Tok _ Word t) =
687685 case T.uncons t of
688686 Just (c, _) | isLetter c -> True
689− _ -> False
687+ _ -> False
690688 startsWithLetter _ = False
691689
692690quoted' :: PandocMonad m
@@ -736,7 +734,7 @@ doverb = do
736734 Tok _ Symbol t <- anySymbol
737735 marker <- case T.uncons t of
738736 Just (c, ts) | T.null ts -> return c
739− _ -> mzero
737+ _ -> mzero
740738 withVerbatimMode $
741739 (code . T.unpack . untokenize) <$>
742740 manyTill (verbTok marker) (symbol marker)
@@ -760,7 +758,7 @@ dolstinline = do
760758 Tok _ Symbol t <- anySymbol
761759 marker <- case T.uncons t of
762760 Just (c, ts) | T.null ts -> return c
763− _ -> mzero
761+ _ -> mzero
764762 let stopchar = if marker == '{' then '}' else marker
765763 withVerbatimMode $
766764 (codeWith ("",classes,[]) . T.unpack . untokenize) <$>
@@ -770,7 +768,7 @@ keyval :: PandocMonad m => LP m (String, String)
770768keyval = try $ do
771769 Tok _ Word key <- satisfyTok isWordTok
772770 let isSpecSym (Tok _ Symbol t) = t /= "]" && t /= ","
773− isSpecSym _ = False
771+ isSpecSym _ = False
774772 optional sp
775773 val <- option [] $ do
776774 symbol '='
@@ -1504,7 +1502,7 @@ hypertargetBlock = try $ do
15041502 bs <- grouped block
15051503 case toList bs of
15061504 [Header 1 (ident,_,_) _] | ident == ref -> return bs
1507− _ -> return $ divWith (ref, [], []) bs
1505+ _ -> return $ divWith (ref, [], []) bs
15081506
15091507hypertargetInline :: PandocMonad m => LP m Inlines
15101508hypertargetInline = try $ do
@@ -1846,7 +1844,7 @@ argSeq n = do
18461844
18471845isArgTok :: Tok -> Bool
18481846isArgTok (Tok _ (Arg _) _) = True
1849−isArgTok _ = False
1847+isArgTok _ = False
18501848
18511849newcommand :: PandocMonad m => LP m (Text, Macro)
18521850newcommand = do
@@ -1869,7 +1867,7 @@ newcommand = do
18691867 when (mtype == "newcommand") $ do
18701868 macros <- sMacros <$> getState
18711869 case M.lookup name macros of
1872− Just _ -> report $ MacroAlreadyDefined (T.unpack txt) pos
1870+ Just _ -> report $ MacroAlreadyDefined (T.unpack txt) pos
18731871 Nothing -> return ()
18741872 return (name, Macro ExpandWhenUsed numargs optarg contents)
18751873
@@ -1893,7 +1891,7 @@ newenvironment = do
18931891 when (mtype == "newenvironment") $ do
18941892 macros <- sMacros <$> getState
18951893 case M.lookup name macros of
1896− Just _ -> report $ MacroAlreadyDefined (T.unpack name) pos
1894+ Just _ -> report $ MacroAlreadyDefined (T.unpack name) pos
18971895 Nothing -> return ()
18981896 return (name, Macro ExpandWhenUsed numargs optarg startcontents,
18991897 Macro ExpandWhenUsed 0 Nothing endcontents)
@@ -2186,8 +2184,8 @@ obeylines = do
21862184 softBreakToHard x = x
21872185 removeLeadingTrailingBreaks = reverse . dropWhile isLineBreak .
21882186 reverse . dropWhile isLineBreak
2189− isLineBreak LineBreak = True
2190− isLineBreak _ = False
2187+ isLineBreak LineBreak = True
2188+ isLineBreak _ = False
21912189
21922190minted :: PandocMonad m => LP m Blocks
21932191minted = do
@@ -2521,13 +2519,13 @@ setDefaultLanguage = do
25212519polyglossiaLangToBCP47 :: M.Map String (String -> Lang)
25222520polyglossiaLangToBCP47 = M.fromList
25232521 [ ("arabic", \o -> case filter (/=' ') o of
2524− "locale=algeria" -> Lang "ar" "" "DZ" []
2525− "locale=mashriq" -> Lang "ar" "" "SY" []
2526− "locale=libya" -> Lang "ar" "" "LY" []
2527− "locale=morocco" -> Lang "ar" "" "MA" []
2522+ "locale=algeria" -> Lang "ar" "" "DZ" []
2523+ "locale=mashriq" -> Lang "ar" "" "SY" []
2524+ "locale=libya" -> Lang "ar" "" "LY" []
2525+ "locale=morocco" -> Lang "ar" "" "MA" []
25282526 "locale=mauritania" -> Lang "ar" "" "MR" []
2529− "locale=tunisia" -> Lang "ar" "" "TN" []
2530− _ -> Lang "ar" "" "" [])
2527+ "locale=tunisia" -> Lang "ar" "" "TN" []
2528+ _ -> Lang "ar" "" "" [])
25312529 , ("german", \o -> case filter (/=' ') o of
25322530 "spelling=old" -> Lang "de" "" "DE" ["1901"]
25332531 "variant=austrian,spelling=old"
@@ -2539,20 +2537,20 @@ polyglossiaLangToBCP47 = M.fromList
25392537 _ -> Lang "de" "" "" [])
25402538 , ("lsorbian", \_ -> Lang "dsb" "" "" [])
25412539 , ("greek", \o -> case filter (/=' ') o of
2542− "variant=poly" -> Lang "el" "" "polyton" []
2540+ "variant=poly" -> Lang "el" "" "polyton" []
25432541 "variant=ancient" -> Lang "grc" "" "" []
2544− _ -> Lang "el" "" "" [])
2542+ _ -> Lang "el" "" "" [])
25452543 , ("english", \o -> case filter (/=' ') o of
25462544 "variant=australian" -> Lang "en" "" "AU" []
2547− "variant=canadian" -> Lang "en" "" "CA" []
2548− "variant=british" -> Lang "en" "" "GB" []
2545+ "variant=canadian" -> Lang "en" "" "CA" []
2546+ "variant=british" -> Lang "en" "" "GB" []
25492547 "variant=newzealand" -> Lang "en" "" "NZ" []
2550− "variant=american" -> Lang "en" "" "US" []
2551− _ -> Lang "en" "" "" [])
2548+ "variant=american" -> Lang "en" "" "US" []
2549+ _ -> Lang "en" "" "" [])
25522550 , ("usorbian", \_ -> Lang "hsb" "" "" [])
25532551 , ("latin", \o -> case filter (/=' ') o of
25542552 "variant=classic" -> Lang "la" "" "" ["x-classic"]
2555− _ -> Lang "la" "" "" [])
2553+ _ -> Lang "la" "" "" [])
25562554 , ("slovenian", \_ -> Lang "sl" "" "" [])
25572555 , ("serbianc", \_ -> Lang "sr" "cyrl" "" [])
25582556 , ("pinyin", \_ -> Lang "zh" "Latn" "" ["pinyin"])