git.iko.soy/typeable/pandoc
on master help sign in
Revert "Add T.P.Readers.LaTeX.Include."
aab3e1eJohn MacFarlane
pandoc.cabal−1
@@ -626,7 +626,6 @@ library
626 Text.Pandoc.Readers.HTML.Table,
626 Text.Pandoc.Readers.HTML.Table,
627 Text.Pandoc.Readers.HTML.TagCategories,
627 Text.Pandoc.Readers.HTML.TagCategories,
628 Text.Pandoc.Readers.HTML.Types,
628 Text.Pandoc.Readers.HTML.Types,
629− Text.Pandoc.Readers.LaTeX.Include,
630 Text.Pandoc.Readers.LaTeX.Inline,
629 Text.Pandoc.Readers.LaTeX.Inline,
631 Text.Pandoc.Readers.LaTeX.Citation,
630 Text.Pandoc.Readers.LaTeX.Citation,
632 Text.Pandoc.Readers.LaTeX.Lang,
631 Text.Pandoc.Readers.LaTeX.Lang,
src/Text/Pandoc/Readers/LaTeX.hs+50−7
@@ -38,8 +38,9 @@ import Text.Pandoc.BCP47 (renderLang)
38import Text.Pandoc.Builder as B
38import Text.Pandoc.Builder as B
39import Text.Pandoc.Class.PandocPure (PandocPure)
39import Text.Pandoc.Class.PandocPure (PandocPure)
40import Text.Pandoc.Class.PandocMonad (PandocMonad (..), getResourcePath,
40import Text.Pandoc.Class.PandocMonad (PandocMonad (..), getResourcePath,
41+ readFileFromDirs, report,
41− report, setResourcePath)
42+ setResourcePath)
42−import Text.Pandoc.Error (PandocError (PandocParsecError))
43+import Text.Pandoc.Error (PandocError (PandocParseError, PandocParsecError))
43import Text.Pandoc.Highlighting (languagesByExtension)
44import Text.Pandoc.Highlighting (languagesByExtension)
44import Text.Pandoc.ImageSize (numUnit, showFl)
45import Text.Pandoc.ImageSize (numUnit, showFl)
45import Text.Pandoc.Logging
46import Text.Pandoc.Logging
@@ -60,8 +61,6 @@ import Text.Pandoc.Readers.LaTeX.Lang (inlineLanguageCommands,
60 enquoteCommands,
61 enquoteCommands,
61 babelLangToBCP47, setDefaultLanguage)
62 babelLangToBCP47, setDefaultLanguage)
62import Text.Pandoc.Readers.LaTeX.SIunitx (siunitxCommands)
63import Text.Pandoc.Readers.LaTeX.SIunitx (siunitxCommands)
63−import Text.Pandoc.Readers.LaTeX.Include (insertIncluded,
64− readFileFromTexinputs)
65import Text.Pandoc.Readers.LaTeX.Inline (acronymCommands, refCommands,
64import Text.Pandoc.Readers.LaTeX.Inline (acronymCommands, refCommands,
66 nameCommands, charCommands,
65 nameCommands, charCommands,
67 accentCommands,
66 accentCommands,
@@ -236,10 +235,19 @@ mkImage options (T.unpack -> src) = do
236 _ -> return src
235 _ -> return src
237 return $ imageWith attr (T.pack src') "" alt
236 return $ imageWith attr (T.pack src') "" alt
238
237
238+doxspace :: PandocMonad m => LP m Inlines
239+doxspace =
240+ (space <$ lookAhead (satisfyTok startsWithLetter)) <|> return mempty
241+ where startsWithLetter (Tok _ Word t) =
242+ case T.uncons t of
243+ Just (c, _) | isLetter c -> True
244+ _ -> False
245+ startsWithLetter _ = False
246+
239
247
240removeDoubleQuotes :: Text -> Text
248removeDoubleQuotes :: Text -> Text
241removeDoubleQuotes t =
249removeDoubleQuotes t =
242− fromMaybe t $ T.stripPrefix "\"" t >>= T.stripSuffix "\""
250+ Data.Maybe.fromMaybe t $ T.stripPrefix "\"" t >>= T.stripSuffix "\""
243
251
244doubleQuote :: PandocMonad m => LP m Inlines
252doubleQuote :: PandocMonad m => LP m Inlines
245doubleQuote =
253doubleQuote =
@@ -398,8 +406,8 @@ inlineCommands = M.unions
398 link (unescapeURL $ untokenize url) "" <$> tok)
406 link (unescapeURL $ untokenize url) "" <$> tok)
399 , ("includegraphics", do options <- option [] keyvals
407 , ("includegraphics", do options <- option [] keyvals
400 src <- braced
408 src <- braced
401− mkImage options . unescapeURL .
409+ mkImage options . unescapeURL . removeDoubleQuotes $
402− removeDoubleQuotes $ untokenize src)
410+ untokenize src)
403 , ("hyperlink", hyperlink)
411 , ("hyperlink", hyperlink)
404 , ("hypertarget", hypertargetInline)
412 , ("hypertarget", hypertargetInline)
405 -- hyphenat
413 -- hyphenat
@@ -409,6 +417,8 @@ inlineCommands = M.unions
409 -- LaTeX colors
417 -- LaTeX colors
410 , ("textcolor", coloredInline "color")
418 , ("textcolor", coloredInline "color")
411 , ("colorbox", coloredInline "background-color")
419 , ("colorbox", coloredInline "background-color")
420+ -- xspace
421+ , ("xspace", doxspace)
412 -- etoolbox
422 -- etoolbox
413 , ("ifstrequal", ifstrequal)
423 , ("ifstrequal", ifstrequal)
414 , ("newtoggle", braced >>= newToggle)
424 , ("newtoggle", braced >>= newToggle)
@@ -688,6 +698,39 @@ include name = do
688 mapM_ (insertIncluded defaultExt) fs
698 mapM_ (insertIncluded defaultExt) fs
689 return mempty
699 return mempty
690
700
701+readFileFromTexinputs :: PandocMonad m => FilePath -> LP m (Maybe Text)
702+readFileFromTexinputs fp = do
703+ fileContentsMap <- sFileContents <$> getState
704+ case M.lookup (T.pack fp) fileContentsMap of
705+ Just t -> return (Just t)
706+ Nothing -> do
707+ dirs <- map T.unpack . splitTextBy (==':') . fromMaybe "."
708+ <$> lookupEnv "TEXINPUTS"
709+ readFileFromDirs dirs fp
710+
711+insertIncluded :: PandocMonad m
712+ => FilePath
713+ -> FilePath
714+ -> LP m ()
715+insertIncluded defaultExtension f' = do
716+ let f = case takeExtension f' of
717+ ".tex" -> f'
718+ ".sty" -> f'
719+ _ -> addExtension f' defaultExtension
720+ pos <- getPosition
721+ containers <- getIncludeFiles <$> getState
722+ when (T.pack f `elem` containers) $
723+ throwError $ PandocParseError $ T.pack $ "Include file loop at " ++ show pos
724+ updateState $ addIncludeFile $ T.pack f
725+ mbcontents <- readFileFromTexinputs f
726+ contents <- case mbcontents of
727+ Just s -> return s
728+ Nothing -> do
729+ report $ CouldNotLoadIncludeFile (T.pack f) pos
730+ return ""
731+ getInput >>= setInput . (tokenize f contents ++)
732+ updateState dropLatestIncludeFile
733+
691authors :: PandocMonad m => LP m ()
734authors :: PandocMonad m => LP m ()
692authors = try $ do
735authors = try $ do
693 bgroup
736 bgroup
src/Text/Pandoc/Readers/LaTeX/Include.hsdeleted−66
@@ -1,66 +0,0 @@
1−{-# LANGUAGE OverloadedStrings #-}
2−{- |
3− Module : Text.Pandoc.Readers.LaTeX.Include
4− Copyright : Copyright (C) 2006-2021 John MacFarlane
5− License : GNU GPL, version 2 or above
6−
7− Maintainer : John MacFarlane <jgm@berkeley.edu>
8− Stability : alpha
9− Portability : portable
10−-}
11−module Text.Pandoc.Readers.LaTeX.Include
12− ( readFileFromTexinputs
13− , insertIncluded
14− )
15−where
16−
17−import qualified Data.Map as M
18−import Data.Text (Text)
19−import qualified Data.Text as T
20−import Text.Pandoc.Shared (splitTextBy)
21−import System.FilePath (takeExtension, addExtension)
22−import Control.Monad (when)
23−import Control.Monad.Except (throwError)
24−import Text.Pandoc.Error (PandocError(PandocParseError))
25−import Text.Pandoc.Logging (LogMessage(CouldNotLoadIncludeFile))
26−import Text.Pandoc.Class (PandocMonad (..), readFileFromDirs, report)
27−import Text.Pandoc.Readers.LaTeX.Parsing
28−import Text.Pandoc.Parsing (updateState, getState, getInput, setInput,
29− getPosition, addIncludeFile, getIncludeFiles,
30− dropLatestIncludeFile)
31−import Data.Maybe (fromMaybe)
32−
33−readFileFromTexinputs :: PandocMonad m => FilePath -> LP m (Maybe Text)
34−readFileFromTexinputs fp = do
35− fileContentsMap <- sFileContents <$> getState
36− case M.lookup (T.pack fp) fileContentsMap of
37− Just t -> return (Just t)
38− Nothing -> do
39− dirs <- map T.unpack . splitTextBy (==':') . fromMaybe "."
40− <$> lookupEnv "TEXINPUTS"
41− readFileFromDirs dirs fp
42−
43−insertIncluded :: PandocMonad m
44− => FilePath
45− -> FilePath
46− -> LP m ()
47−insertIncluded defaultExtension f' = do
48− let f = case takeExtension f' of
49− ".tex" -> f'
50− ".sty" -> f'
51− _ -> addExtension f' defaultExtension
52− pos <- getPosition
53− containers <- getIncludeFiles <$> getState
54− when (T.pack f `elem` containers) $
55− throwError $ PandocParseError $ T.pack $ "Include file loop at " ++ show pos
56− updateState $ addIncludeFile $ T.pack f
57− mbcontents <- readFileFromTexinputs f
58− contents <- case mbcontents of
59− Just s -> return s
60− Nothing -> do
61− report $ CouldNotLoadIncludeFile (T.pack f) pos
62− return ""
63− getInput >>= setInput . (tokenize f contents ++)
64− updateState dropLatestIncludeFile
65−
66−
src/Text/Pandoc/Readers/LaTeX/Inline.hs+2−13
@@ -35,8 +35,8 @@ import Text.Pandoc.Readers.LaTeX.Parsing
35import Text.Pandoc.Extensions (extensionEnabled, Extension(..))
35import Text.Pandoc.Extensions (extensionEnabled, Extension(..))
36import Text.Pandoc.Parsing (getOption, updateState, getState, notFollowedBy,
36import Text.Pandoc.Parsing (getOption, updateState, getState, notFollowedBy,
37 manyTill, getInput, setInput, incSourceColumn,
37 manyTill, getInput, setInput, incSourceColumn,
38− option, many1, try, lookAhead)
38+ option, many1, try)
39−import Data.Char (isDigit, isLetter)
39+import Data.Char (isDigit)
40import Text.Pandoc.Highlighting (fromListingsLanguage,)
40import Text.Pandoc.Highlighting (fromListingsLanguage,)
41import Data.Maybe (maybeToList, fromMaybe)
41import Data.Maybe (maybeToList, fromMaybe)
42import Text.Pandoc.Options (ReaderOptions(..))
42import Text.Pandoc.Options (ReaderOptions(..))
@@ -50,15 +50,6 @@ rawInlineOr name' fallback = do
50 then rawInline "latex" <$> getRawCommand name' ("\\" <> name')
50 then rawInline "latex" <$> getRawCommand name' ("\\" <> name')
51 else fallback
51 else fallback
52
52
53−doxspace :: PandocMonad m => LP m Inlines
54−doxspace =
55− (space <$ lookAhead (satisfyTok startsWithLetter)) <|> return mempty
56− where startsWithLetter (Tok _ Word t) =
57− case T.uncons t of
58− Just (c, _) | isLetter c -> True
59− _ -> False
60− startsWithLetter _ = False
61−
62dolabel :: PandocMonad m => LP m Inlines
53dolabel :: PandocMonad m => LP m Inlines
63dolabel = do
54dolabel = do
64 v <- braced
55 v <- braced
@@ -289,8 +280,6 @@ charCommands = M.fromList
289 , ("dothyp", lit ".\173")
280 , ("dothyp", lit ".\173")
290 , ("colonhyp", lit ":\173")
281 , ("colonhyp", lit ":\173")
291 , ("hyp", lit "-")
282 , ("hyp", lit "-")
292− -- xspace
293− , ("xspace", doxspace)
294 ]
283 ]
295
284
296biblatexInlineCommands :: PandocMonad m
285biblatexInlineCommands :: PandocMonad m