@@ -47,8 +47,7 @@ import Prelude
47import Control.Applicative (many, optional, (<|>))
47import Control.Applicative (many, optional, (<|>))
48import Control.Monad
48import Control.Monad
49import Control.Monad.Except (throwError)
49import Control.Monad.Except (throwError)
50−import Control.Monad.Trans (lift)
51−import Data.Char (chr, isAlphaNum, isDigit, isLetter, ord, toLower, toUpper)
50+import Data.Char (isDigit, isLetter, toLower, toUpper)
52import Data.Default
51import Data.Default
53import Data.List (intercalate, isPrefixOf)
52import Data.List (intercalate, isPrefixOf)
54import qualified Data.Map as M
53import qualified Data.Map as M
@@ -63,7 +62,7 @@ import Text.Pandoc.Builder
63import Text.Pandoc.Class (PandocMonad, PandocPure, getResourcePath, lookupEnv,
62import Text.Pandoc.Class (PandocMonad, PandocPure, getResourcePath, lookupEnv,
64 readFileFromDirs, report, setResourcePath,
63 readFileFromDirs, report, setResourcePath,
65 setTranslations, translateTerm, trace)
64 setTranslations, translateTerm, trace)
66−import Text.Pandoc.Error (PandocError (PandocMacroLoop, PandocParseError, PandocParsecError))
65+import Text.Pandoc.Error (PandocError ( PandocParseError, PandocParsecError))
67import Text.Pandoc.Highlighting (fromListingsLanguage, languagesByExtension)
66import Text.Pandoc.Highlighting (fromListingsLanguage, languagesByExtension)
68import Text.Pandoc.ImageSize (numUnit, showFl)
67import Text.Pandoc.ImageSize (numUnit, showFl)
69import Text.Pandoc.Logging
68import Text.Pandoc.Logging
@@ -72,10 +71,10 @@ import Text.Pandoc.Parsing hiding (blankline, many, mathDisplay, mathInline,
72 optional, space, spaces, withRaw, (<|>))
71 optional, space, spaces, withRaw, (<|>))
73import Text.Pandoc.Readers.LaTeX.Types (ExpansionPoint (..), Macro (..),
72import Text.Pandoc.Readers.LaTeX.Types (ExpansionPoint (..), Macro (..),
74 ArgSpec (..), Tok (..), TokType (..))
73 ArgSpec (..), Tok (..), TokType (..))
74+import Text.Pandoc.Readers.LaTeX.Parsing
75import Text.Pandoc.Shared
75import Text.Pandoc.Shared
76import qualified Text.Pandoc.Translations as Translations
76import qualified Text.Pandoc.Translations as Translations
77import Text.Pandoc.Walk
77import Text.Pandoc.Walk
78−import Text.Parsec.Pos
79import qualified Text.Pandoc.Builder as B
78import qualified Text.Pandoc.Builder as B
81-- for debugging:
80-- for debugging:
@@ -137,151 +136,6 @@ resolveRefs _ x = x
137-- Left e -> error (show e)
136-- Left e -> error (show e)
138-- Right r -> return r
137-- Right r -> return r
140−newtype DottedNum = DottedNum [Int]
143−renderDottedNum :: DottedNum -> String
144−renderDottedNum (DottedNum xs) =
145− intercalate "." (map show xs)
147−incrementDottedNum :: Int -> DottedNum -> DottedNum
148−incrementDottedNum level (DottedNum ns) = DottedNum $
149− case reverse (take level (ns ++ repeat 0)) of
150− (x:xs) -> reverse (x+1 : xs)
151− [] -> [] -- shouldn't happen
153−data LaTeXState = LaTeXState{ sOptions :: ReaderOptions
155− , sQuoteContext :: QuoteContext
156− , sMacros :: M.Map Text Macro
157− , sContainers :: [String]
158− , sHeaders :: M.Map Inlines String
159− , sLogMessages :: [LogMessage]
160− , sIdentifiers :: Set.Set String
161− , sVerbatimMode :: Bool
162− , sCaption :: (Maybe Inlines, Maybe String)
163− , sInListItem :: Bool
164− , sInTableCell :: Bool
165− , sLastHeaderNum :: DottedNum
166− , sLastFigureNum :: DottedNum
167− , sLabels :: M.Map String [Inline]
168− , sHasChapters :: Bool
169− , sToggles :: M.Map String Bool
173−defaultLaTeXState :: LaTeXState
174−defaultLaTeXState = LaTeXState{ sOptions = def
176− , sQuoteContext = NoQuote
179− , sHeaders = M.empty
181− , sIdentifiers = Set.empty
182− , sVerbatimMode = False
183− , sCaption = (Nothing, Nothing)
184− , sInListItem = False
185− , sInTableCell = False
186− , sLastHeaderNum = DottedNum []
187− , sLastFigureNum = DottedNum []
189− , sHasChapters = False
190− , sToggles = M.empty
193−instance PandocMonad m => HasQuoteContext LaTeXState m where
194− getQuoteContext = sQuoteContext <$> getState
195− withQuoteContext context parser = do
196− oldState <- getState
197− let oldQuoteContext = sQuoteContext oldState
198− setState oldState { sQuoteContext = context }
200− newState <- getState
201− setState newState { sQuoteContext = oldQuoteContext }
204−instance HasLogMessages LaTeXState where
205− addLogMessage msg st = st{ sLogMessages = msg : sLogMessages st }
206− getLogMessages st = reverse $ sLogMessages st
208−instance HasIdentifierList LaTeXState where
209− extractIdentifierList = sIdentifiers
210− updateIdentifierList f st = st{ sIdentifiers = f $ sIdentifiers st }
212−instance HasIncludeFiles LaTeXState where
213− getIncludeFiles = sContainers
214− addIncludeFile f s = s{ sContainers = f : sContainers s }
215− dropLatestIncludeFile s = s { sContainers = drop 1 $ sContainers s }
217−instance HasHeaderMap LaTeXState where
218− extractHeaderMap = sHeaders
219− updateHeaderMap f st = st{ sHeaders = f $ sHeaders st }
221−instance HasMacros LaTeXState where
222− extractMacros st = sMacros st
223− updateMacros f st = st{ sMacros = f (sMacros st) }
225−instance HasReaderOptions LaTeXState where
226− extractReaderOptions = sOptions
228−instance HasMeta LaTeXState where
229− setMeta field val st =
230− st{ sMeta = setMeta field val $ sMeta st }
231− deleteMeta field st =
232− st{ sMeta = deleteMeta field $ sMeta st }
234−instance Default LaTeXState where
235− def = defaultLaTeXState
237−type LP m = ParserT [Tok] LaTeXState m
239−withVerbatimMode :: PandocMonad m => LP m a -> LP m a
240−withVerbatimMode parser = do
241− updateState $ \st -> st{ sVerbatimMode = True }
243− updateState $ \st -> st{ sVerbatimMode = False }
246−rawLaTeXParser :: (PandocMonad m, HasMacros s, HasReaderOptions s)
247− => Bool -> LP m a -> LP m a -> ParserT String s m (a, String)
248−rawLaTeXParser retokenize parser valParser = do
250− let toks = tokenize "source" $ T.pack inp
252− let lstate = def{ sOptions = extractReaderOptions pstate }
253− let lstate' = lstate { sMacros = extractMacros pstate }
254− let rawparser = (,) <$> withRaw valParser <*> getState
255− res' <- lift $ runParserT (snd <$> withRaw parser) lstate "chunk" toks
259− res <- lift $ runParserT (do when retokenize $ do
260− -- retokenize, applying macros
262− ts <- many (satisfyTok (const True))
265− lstate' "chunk" toks'
268− Right ((val, raw), st) -> do
269− updateState (updateMacros (sMacros st <>))
270− _ <- takeP (T.length (untokenize toks'))
271− return (val, T.unpack (untokenize raw))
273−applyMacros :: (PandocMonad m, HasMacros s, HasReaderOptions s)
274− => String -> ParserT String s m String
275−applyMacros s = (guardDisabled Ext_latex_macros >> return s) <|>
276− do let retokenize = doMacros 0 *>
277− (toksToString <$> many (satisfyTok (const True)))
279− let lstate = def{ sOptions = extractReaderOptions pstate
280− , sMacros = extractMacros pstate }
281− res <- runParserT retokenize lstate "math" (tokenize "math" (T.pack s))
283− Left e -> fail (show e)
284− Right s' -> return s'
286rawLaTeXBlock :: (PandocMonad m, HasMacros s, HasReaderOptions s)
140rawLaTeXBlock :: (PandocMonad m, HasMacros s, HasReaderOptions s)
287 => ParserT String s m String
141 => ParserT String s m String
@@ -326,358 +180,6 @@ inlineCommand = do
326 lookAhead (try (char '\\' >> letter))
180 lookAhead (try (char '\\' >> letter))
327 fst <$> rawLaTeXParser True (inlineEnvironment <|> inlineCommand') inlines
181 fst <$> rawLaTeXParser True (inlineEnvironment <|> inlineCommand') inlines
329−tokenize :: SourceName -> Text -> [Tok]
330−tokenize sourcename = totoks (initialPos sourcename)
332−totoks :: SourcePos -> Text -> [Tok]
338− Tok pos Newline "\n"
339− : totoks (setSourceColumn (incSourceLine pos 1) 1) rest
341− let (sps, rest') = T.span isSpaceOrTab t
342− in Tok pos Spaces sps
343− : totoks (incSourceColumn pos (T.length sps))
346− let (ws, rest') = T.span isAlphaNum t
348− : totoks (incSourceColumn pos (T.length ws)) rest'
350− let (cs, rest') = T.break (== '\n') rest
351− in Tok pos Comment ("%" <> cs)
352− : totoks (incSourceColumn pos (1 + T.length cs)) rest'
354− case T.uncons rest of
355− Nothing -> [Tok pos (CtrlSeq " ") "\\"]
358− -- \makeatletter is common in macro defs;
359− -- ideally we should make tokenization sensitive
360− -- to \makeatletter and \makeatother, but this is
361− -- probably best for now
362− let (ws, rest'') = T.span isLetterOrAt rest
363− (ss, rest''') = T.span isSpaceOrTab rest''
364− in Tok pos (CtrlSeq ws) ("\\" <> ws <> ss)
365− : totoks (incSourceColumn pos
366− (1 + T.length ws + T.length ss)) rest'''
367− | isSpaceOrTab d || d == '\n' ->
368− let (w1, r1) = T.span isSpaceOrTab rest
369− (w2, (w3, r3)) = case T.uncons r1 of
372− T.span isSpaceOrTab r2)
373− _ -> (mempty, (mempty, r1))
374− ws = "\\" <> w1 <> w2 <> w3
375− in case T.uncons r3 of
377− Tok pos (CtrlSeq " ") ("\\" <> w1)
378− : totoks (incSourceColumn pos (T.length ws))
381− Tok pos (CtrlSeq " ") ws
382− : totoks (incSourceColumn pos (T.length ws))
385− Tok pos (CtrlSeq (T.singleton d)) (T.pack [c,d])
386− : totoks (incSourceColumn pos 2) rest'
388− let (t1, t2) = T.span (\d -> d >= '0' && d <= '9') rest
389− in case safeRead (T.unpack t1) of
391− Tok pos (Arg i) ("#" <> t1)
392− : totoks (incSourceColumn pos (1 + T.length t1)) t2
395− : totoks (incSourceColumn pos 1) t2
397− case T.uncons rest of
398− Just ('^', rest') ->
399− case T.uncons rest' of
402− case T.uncons rest'' of
403− Just (e, rest''') | isLowerHex e ->
404− Tok pos Esc2 (T.pack ['^','^',d,e])
405− : totoks (incSourceColumn pos 4) rest'''
407− Tok pos Esc1 (T.pack ['^','^',d])
408− : totoks (incSourceColumn pos 3) rest''
410− Tok pos Esc1 (T.pack ['^','^',d])
411− : totoks (incSourceColumn pos 3) rest''
412− _ -> Tok pos Symbol "^" :
413− Tok (incSourceColumn pos 1) Symbol "^" :
414− totoks (incSourceColumn pos 2) rest'
415− _ -> Tok pos Symbol "^"
416− : totoks (incSourceColumn pos 1) rest
418− Tok pos Symbol (T.singleton c) : totoks (incSourceColumn pos 1) rest
420−isSpaceOrTab :: Char -> Bool
421−isSpaceOrTab ' ' = True
422−isSpaceOrTab '\t' = True
423−isSpaceOrTab _ = False
425−isLetterOrAt :: Char -> Bool
426−isLetterOrAt '@' = True
427−isLetterOrAt c = isLetter c
429−isLowerHex :: Char -> Bool
430−isLowerHex x = x >= '0' && x <= '9' || x >= 'a' && x <= 'f'
432−untokenize :: [Tok] -> Text
433−untokenize = mconcat . map untoken
435−untoken :: Tok -> Text
436−untoken (Tok _ _ t) = t
438−satisfyTok :: PandocMonad m => (Tok -> Bool) -> LP m Tok
441− res <- tokenPrim (T.unpack . untoken) updatePos matcher
442− doMacros 0 -- apply macros on remaining input stream
444− where matcher t | f t = Just t
445− | otherwise = Nothing
446− updatePos :: SourcePos -> Tok -> [Tok] -> SourcePos
447− updatePos _spos _ (Tok pos _ _ : _) = pos
448− updatePos spos _ [] = incSourceColumn spos 1
450−doMacros :: PandocMonad m => Int -> LP m ()
452− verbatimMode <- sVerbatimMode <$> getState
453− unless verbatimMode $ do
456− Tok spos (CtrlSeq "begin") _ : Tok _ Symbol "{" :
457− Tok _ Word name : Tok _ Symbol "}" : ts
458− -> handleMacros spos name ts
459− Tok spos (CtrlSeq "end") _ : Tok _ Symbol "{" :
460− Tok _ Word name : Tok _ Symbol "}" : ts
461− -> handleMacros spos ("end" <> name) ts
462− Tok _ (CtrlSeq "expandafter") _ : t : ts
465− getInput >>= setInput . combineTok t
466− Tok spos (CtrlSeq name) _ : ts
467− -> handleMacros spos name ts
469− where combineTok (Tok spos (CtrlSeq name) x) (Tok _ Word w : ts)
470− | T.all isLetterOrAt w =
471− Tok spos (CtrlSeq (name <> w)) (x1 <> w <> x2) : ts
472− where (x1, x2) = T.break isSpaceOrTab x
473− combineTok t ts = t:ts
474− handleMacros spos name ts = do
475− macros <- sMacros <$> getState
476− case M.lookup name macros of
477− Nothing -> return ()
478− Just (Macro expansionPoint argspecs optarg newtoks) -> do
480− let matchTok (Tok _ toktype txt) =
481− satisfyTok (\(Tok _ toktype' txt') ->
482− toktype == toktype' &&
484− let matchPattern toks = try $ mapM_ matchTok toks
485− let getargs argmap [] = return argmap
486− getargs argmap (Pattern toks : rest) = try $ do
489− getargs argmap (ArgNum i : Pattern toks : rest) =
491− x <- mconcat <$> manyTill
492− (braced <|> ((:[]) <$> anyTok))
494− getargs (M.insert i x argmap) rest
495− getargs argmap (ArgNum i : rest) = do
496− x <- try $ spaces >> bracedOrToken
497− getargs (M.insert i x argmap) rest
498− args <- case optarg of
499− Nothing -> getargs M.empty argspecs
501− x <- option o bracketedToks
502− getargs (M.singleton 1 x) argspecs
503− -- first boolean param is true if we're tokenizing
504− -- an argument (in which case we don't want to
506− let addTok False (Tok _ (Arg i) _) acc =
507− case M.lookup i args of
509− Just xs -> foldr (addTok True) acc xs
511− addTok _ (Tok _ (CtrlSeq x) txt)
512− acc@(Tok _ Word _ : _)
513− | not (T.null txt) &&
514− isLetter (T.last txt) =
515− Tok spos (CtrlSeq x) (txt <> " ") : acc
516− addTok _ t acc = setpos spos t : acc
518− setInput $ foldr (addTok False) ts' newtoks
519− case expansionPoint of
521− if n > 20 -- detect macro expansion loops
522− then throwError $ PandocMacroLoop (T.unpack name)
523− else doMacros (n + 1)
524− ExpandWhenDefined -> return ()
527−setpos :: SourcePos -> Tok -> Tok
528−setpos spos (Tok _ tt txt) = Tok spos tt txt
530−anyControlSeq :: PandocMonad m => LP m Tok
531−anyControlSeq = satisfyTok isCtrlSeq
533−isCtrlSeq :: Tok -> Bool
534−isCtrlSeq (Tok _ (CtrlSeq _) _) = True
537−anySymbol :: PandocMonad m => LP m Tok
538−anySymbol = satisfyTok isSymbolTok
540−isSymbolTok :: Tok -> Bool
541−isSymbolTok (Tok _ Symbol _) = True
542−isSymbolTok _ = False
544−spaces :: PandocMonad m => LP m ()
545−spaces = skipMany (satisfyTok (tokTypeIn [Comment, Spaces, Newline]))
547−spaces1 :: PandocMonad m => LP m ()
548−spaces1 = skipMany1 (satisfyTok (tokTypeIn [Comment, Spaces, Newline]))
550−tokTypeIn :: [TokType] -> Tok -> Bool
551−tokTypeIn toktypes (Tok _ tt _) = tt `elem` toktypes
553−controlSeq :: PandocMonad m => Text -> LP m Tok
554−controlSeq name = satisfyTok isNamed
555− where isNamed (Tok _ (CtrlSeq n) _) = n == name
558−symbol :: PandocMonad m => Char -> LP m Tok
559−symbol c = satisfyTok isc
560− where isc (Tok _ Symbol d) = case T.uncons d of
561− Just (c',_) -> c == c'
565−symbolIn :: PandocMonad m => [Char] -> LP m Tok
566−symbolIn cs = satisfyTok isInCs
567− where isInCs (Tok _ Symbol d) = case T.uncons d of
568− Just (c,_) -> c `elem` cs
572−sp :: PandocMonad m => LP m ()
573−sp = whitespace <|> endline
575−whitespace :: PandocMonad m => LP m ()
576−whitespace = () <$ satisfyTok isSpaceTok
578−isSpaceTok :: Tok -> Bool
579−isSpaceTok (Tok _ Spaces _) = True
582−newlineTok :: PandocMonad m => LP m ()
583−newlineTok = () <$ satisfyTok isNewlineTok
585−isNewlineTok :: Tok -> Bool
586−isNewlineTok (Tok _ Newline _) = True
587−isNewlineTok _ = False
589−comment :: PandocMonad m => LP m ()
590−comment = () <$ satisfyTok isCommentTok
592−isCommentTok :: Tok -> Bool
593−isCommentTok (Tok _ Comment _) = True
594−isCommentTok _ = False
596−anyTok :: PandocMonad m => LP m Tok
597−anyTok = satisfyTok (const True)
599−endline :: PandocMonad m => LP m ()
603− notFollowedBy blankline
605−blankline :: PandocMonad m => LP m ()
606−blankline = try $ skipMany whitespace *> newlineTok
608−primEscape :: PandocMonad m => LP m Char
610− Tok _ toktype t <- satisfyTok (tokTypeIn [Esc1, Esc2])
612− Esc1 -> case T.uncons (T.drop 2 t) of
614− | c >= '\64' && c <= '\127' -> return (chr (ord c - 64))
615− | otherwise -> return (chr (ord c + 64))
616− Nothing -> fail "Empty content of Esc1"
617− Esc2 -> case safeRead ('0':'x':T.unpack (T.drop 2 t)) of
618− Just x -> return (chr x)
619− Nothing -> fail $ "Could not read: " ++ T.unpack t
620− _ -> fail "Expected an Esc1 or Esc2 token" -- should not happen
622−bgroup :: PandocMonad m => LP m Tok
625− symbol '{' <|> controlSeq "bgroup" <|> controlSeq "begingroup"
627−egroup :: PandocMonad m => LP m Tok
628−egroup = symbol '}' <|> controlSeq "egroup" <|> controlSeq "endgroup"
630−grouped :: (PandocMonad m, Monoid a) => LP m a -> LP m a
631−grouped parser = try $ do
633− -- first we check for an inner 'grouped', because
634− -- {{a,b}} should be parsed the same as {a,b}
635− try (grouped parser <* egroup) <|> (mconcat <$> manyTill parser egroup)
637−braced' :: PandocMonad m => LP m Tok -> Int -> LP m [Tok]
639− handleEgroup <|> handleBgroup <|> handleOther
640− where handleEgroup = do
644− else (t:) <$> braced' getTok (n - 1)
647− (t:) <$> braced' getTok (n + 1)
650− (t:) <$> braced' getTok n
652−braced :: PandocMonad m => LP m [Tok]
653−braced = bgroup *> braced' anyTok 1
655−-- URLs require special handling, because they can contain %
656−-- characters. So we retonenize comments as we go...
657−bracedUrl :: PandocMonad m => LP m [Tok]
658−bracedUrl = bgroup *> braced' (retokenizeComment >> anyTok) 1
660−bracketed :: PandocMonad m => Monoid a => LP m a -> LP m a
661−bracketed parser = try $ do
663− mconcat <$> manyTill parser (symbol ']')
665−parenWrapped :: PandocMonad m => Monoid a => LP m a -> LP m a
666−parenWrapped parser = try $ do
668− mconcat <$> manyTill parser (symbol ')')
670−dimenarg :: PandocMonad m => LP m Text
672− ch <- option False $ True <$ symbol '='
673− Tok _ _ s <- satisfyTok isWordTok
674− guard $ T.take 2 (T.reverse s) `elem`
675− ["pt","pc","in","bp","cm","mm","dd","cc","sp"]
676− let num = T.take (T.length s - 2) s
677− guard $ T.length num > 0
678− guard $ T.all isDigit num
679− return $ T.pack ['=' | ch] <> s
681-- inline elements:
183-- inline elements:
683word :: PandocMonad m => LP m Inlines
185word :: PandocMonad m => LP m Inlines
@@ -689,13 +191,6 @@ regularSymbol = (str . T.unpack . untoken) <$> satisfyTok isRegularSymbol
689 isRegularSymbol _ = False
191 isRegularSymbol _ = False
690 isSpecial c = c `Set.member` specialChars
192 isSpecial c = c `Set.member` specialChars
692−specialChars :: Set.Set Char
693−specialChars = Set.fromList "#$%&~_^\\{}"
695−isWordTok :: Tok -> Bool
696−isWordTok (Tok _ Word _) = True
699inlineGroup :: PandocMonad m => LP m Inlines
194inlineGroup :: PandocMonad m => LP m Inlines
700inlineGroup = do
195inlineGroup = do
701 ils <- grouped inline
196 ils <- grouped inline
@@ -1396,9 +891,6 @@ breve 'U' = "Ŭ"
1396breve 'u' = "ŭ"
891breve 'u' = "ŭ"
1397breve c = [c]
892breve c = [c]
1399−toksToString :: [Tok] -> String
1400−toksToString = T.unpack . untokenize
1402mathDisplay :: String -> Inlines
894mathDisplay :: String -> Inlines
1403mathDisplay = displayMath . trim
895mathDisplay = displayMath . trim
@@ -1562,19 +1054,6 @@ tok = try $ spaces >> grouped inline <|> inlineCommand' <|> singleChar'
1562 Tok _ _ t <- singleChar
1054 Tok _ _ t <- singleChar
1563 return (str (T.unpack t))
1055 return (str (T.unpack t))
1565−singleChar :: PandocMonad m => LP m Tok
1566−singleChar = try $ do
1567− Tok pos toktype t <- satisfyTok (tokTypeIn [Word, Symbol])
1568− guard $ not $ toktype == Symbol &&
1569− T.any (`Set.member` specialChars) t
1572− let (t1, t2) = (T.take 1 t, T.drop 1 t)
1574− setInput $ Tok (incSourceColumn pos 1) toktype t2 : inp
1575− return $ Tok pos toktype t1
1576− else return $ Tok pos toktype t
1578opt :: PandocMonad m => LP m Inlines
1057opt :: PandocMonad m => LP m Inlines
1579opt = bracketed inline <|> (str . T.unpack <$> rawopt)
1058opt = bracketed inline <|> (str . T.unpack <$> rawopt)
@@ -1611,20 +1090,6 @@ overlayTok =
1611 Tok _ Symbol c -> c `elem` ["-","+","@","|",":",","]
1090 Tok _ Symbol c -> c `elem` ["-","+","@","|",":",","]
1612 _ -> False)
1091 _ -> False)
1614−ignore :: (Monoid a, PandocMonad m) => String -> ParserT s u m a
1617− report $ SkippedContent raw pos
1620−withRaw :: PandocMonad m => LP m a -> LP m (a, [Tok])
1624− nxt <- option (Tok (initialPos "source") Word "") (lookAhead anyTok)
1625− let raw = takeWhile (/= nxt) inp
1626− return (result, raw)
1628inBrackets :: Inlines -> Inlines
1093inBrackets :: Inlines -> Inlines
1629inBrackets x = str "[" <> x <> str "]"
1094inBrackets x = str "[" <> x <> str "]"
@@ -1634,17 +1099,6 @@ unescapeURL ('\\':x:xs) | isEscapable x = x:unescapeURL xs
1634unescapeURL (x:xs) = x:unescapeURL xs
1099unescapeURL (x:xs) = x:unescapeURL xs
1635unescapeURL [] = ""
1100unescapeURL [] = ""
1637−-- For handling URLs, which allow literal % characters...
1638−retokenizeComment :: PandocMonad m => LP m ()
1639−retokenizeComment = (do
1640− Tok pos Comment txt <- satisfyTok isCommentTok
1641− let updPos (Tok pos' toktype' txt') =
1642− Tok (incSourceColumn (incSourceLine pos' (sourceLine pos - 1))
1643− (sourceColumn pos)) toktype' txt'
1644− let newtoks = map updPos $ tokenize (sourceName pos) $ T.tail txt
1645− getInput >>= setInput . ((Tok pos Symbol "%" : newtoks) ++))
1648mathEnvWith :: PandocMonad m
1102mathEnvWith :: PandocMonad m
1649 => (Inlines -> a) -> Maybe Text -> Text -> LP m a
1103 => (Inlines -> a) -> Maybe Text -> Text -> LP m a
1650mathEnvWith f innerEnv name = f . mathDisplay . inner <$> mathEnv name
1104mathEnvWith f innerEnv name = f . mathDisplay . inner <$> mathEnv name
@@ -2364,9 +1818,6 @@ isArgTok :: Tok -> Bool
2364isArgTok (Tok _ (Arg _) _) = True
1818isArgTok (Tok _ (Arg _) _) = True
2365isArgTok _ = False
1819isArgTok _ = False
2367−bracedOrToken :: PandocMonad m => LP m [Tok]
2368−bracedOrToken = braced <|> ((:[]) <$> (anyControlSeq <|> singleChar))
2370newcommand :: PandocMonad m => LP m (Text, Macro)
1821newcommand :: PandocMonad m => LP m (Text, Macro)
2371newcommand = do
1822newcommand = do
2372 pos <- getPosition
1823 pos <- getPosition
@@ -2417,11 +1868,6 @@ newenvironment = do
2417 return (name, Macro ExpandWhenUsed argspecs optarg startcontents,
1868 return (name, Macro ExpandWhenUsed argspecs optarg startcontents,
2418 Macro ExpandWhenUsed [] Nothing endcontents)
1869 Macro ExpandWhenUsed [] Nothing endcontents)
2420−bracketedToks :: PandocMonad m => LP m [Tok]
2423− mconcat <$> manyTill (braced <|> (:[]) <$> anyTok) (symbol ']')
2425bracketedNum :: PandocMonad m => LP m Int
1871bracketedNum :: PandocMonad m => LP m Int
2426bracketedNum = do
1872bracketedNum = do
2427 ds <- untokenize <$> bracketedToks
1873 ds <- untokenize <$> bracketedToks