{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternGuards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE ViewPatterns #-}
module Text.Pandoc.Readers.LaTeX ( readLaTeX,
applyMacros,
rawLaTeXInline,
rawLaTeXBlock,
inlineCommand
) where
import Control.Applicative (many, optional, (<|>))
import Control.Monad
import Control.Monad.Except (throwError)
import Data.Containers.ListUtils (nubOrd)
import Data.Char (isDigit, isLetter, isAlphaNum, toUpper, chr)
import Data.Default
import Data.List (intercalate)
import qualified Data.Map as M
import Data.Maybe (fromMaybe, maybeToList)
import qualified Data.Set as Set
import Data.Text (Text)
import qualified Data.Text as T
import Data.Either (partitionEithers)
import Skylighting (defaultSyntaxMap)
import System.FilePath (addExtension, replaceExtension, takeExtension)
import Text.Collate.Lang (renderLang)
import Text.Pandoc.Builder as B
import Text.Pandoc.Class (PandocPure, PandocMonad (..), getResourcePath,
readFileFromDirs, report,
setResourcePath, getZonedTime)
import Data.Time (ZonedTime(..), LocalTime(..), showGregorian)
import Text.Pandoc.Error (PandocError (PandocParseError))
import Text.Pandoc.Highlighting (languagesByExtension)
import Text.Pandoc.ImageSize (numUnit, showFl)
import Text.Pandoc.Logging
import Text.Pandoc.Options
import Text.Pandoc.Parsing hiding (blankline, many, mathDisplay, mathInline,
optional, space, spaces, withRaw, (<|>))
import Text.Pandoc.TeX (Tok (..), TokType (..))
import Text.Pandoc.Readers.LaTeX.Parsing
import Text.Pandoc.Readers.LaTeX.Citation (citationCommands, cites)
import Text.Pandoc.Readers.LaTeX.Math (dollarsMath, inlineEnvironments,
inlineEnvironment,
mathDisplay, mathInline,
newtheorem, theoremstyle, proof,
theoremEnvironment)
import Text.Pandoc.Readers.LaTeX.Table (tableEnvironments)
import Text.Pandoc.Readers.LaTeX.Macro (macroDef)
import Text.Pandoc.Readers.LaTeX.Lang (inlineLanguageCommands,
enquoteCommands,
babelLangToBCP47, setDefaultLanguage)
import Text.Pandoc.Readers.LaTeX.SIunitx (siunitxCommands)
import Text.Pandoc.Readers.LaTeX.Inline (acronymCommands, refCommands,
nameCommands, charCommands,
accentCommands,
biblatexInlineCommands,
verbCommands, rawInlineOr,
listingsLanguage)
import Text.Pandoc.Shared
import Text.Pandoc.Walk
import Data.List.NonEmpty (nonEmpty)
readLaTeX :: (PandocMonad m, ToSources a)
=> ReaderOptions
-> a
-> m Pandoc
readLaTeX :: forall (m :: * -> *) a.
(PandocMonad m, ToSources a) =>
ReaderOptions -> a -> m Pandoc
readLaTeX ReaderOptions
opts a
ltx = do
let sources :: Sources
sources = forall a. ToSources a => a -> Sources
toSources a
ltx
Either ParseError Pandoc
parsed <- forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> u -> String -> s -> m (Either ParseError a)
runParserT forall (m :: * -> *). PandocMonad m => LP m Pandoc
parseLaTeX forall a. Default a => a
def{ sOptions :: ReaderOptions
sOptions = ReaderOptions
opts } String
"source"
(Bool -> [Tok] -> TokStream
TokStream Bool
False (Sources -> [Tok]
tokenizeSources Sources
sources))
case Either ParseError Pandoc
parsed of
Right Pandoc
result -> forall (m :: * -> *) a. Monad m => a -> m a
return Pandoc
result
Left ParseError
e -> forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError forall a b. (a -> b) -> a -> b
$ Sources -> ParseError -> PandocError
fromParsecError Sources
sources ParseError
e
parseLaTeX :: PandocMonad m => LP m Pandoc
parseLaTeX :: forall (m :: * -> *). PandocMonad m => LP m Pandoc
parseLaTeX = do
Blocks
bs <- forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
LaTeXState
st <- forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
let meta :: Meta
meta = LaTeXState -> Meta
sMeta LaTeXState
st
let doc' :: Pandoc
doc' = Blocks -> Pandoc
doc Blocks
bs
let headerLevel :: Block -> [Int]
headerLevel (Header Int
n Attr
_ [Inline]
_) = [Int
n]
headerLevel Block
_ = []
let bottomLevel :: Int
bottomLevel = forall b a. b -> (a -> b) -> Maybe a -> b
maybe Int
1 forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum forall a b. (a -> b) -> a -> b
$ forall a. [a] -> Maybe (NonEmpty a)
nonEmpty forall a b. (a -> b) -> a -> b
$ forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query Block -> [Int]
headerLevel Pandoc
doc'
let adjustHeaders :: Int -> Block -> Block
adjustHeaders Int
m (Header Int
n Attr
attr [Inline]
ils) = Int -> Attr -> [Inline] -> Block
Header (Int
nforall a. Num a => a -> a -> a
+Int
m) Attr
attr [Inline]
ils
adjustHeaders Int
_ Block
x = Block
x
let (Pandoc Meta
_ [Block]
bs') =
(if Int
bottomLevel forall a. Ord a => a -> a -> Bool
< Int
1
then forall a b. Walkable a b => (a -> a) -> b -> b
walk (Int -> Block -> Block
adjustHeaders (Int
1 forall a. Num a => a -> a -> a
- Int
bottomLevel))
else forall a. a -> a
id) forall a b. (a -> b) -> a -> b
$
forall a b. Walkable a b => (a -> a) -> b -> b
walk (Map Text [Inline] -> Inline -> Inline
resolveRefs (LaTeXState -> Map Text [Inline]
sLabels LaTeXState
st)) Pandoc
doc'
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Meta -> [Block] -> Pandoc
Pandoc Meta
meta [Block]
bs'
resolveRefs :: M.Map Text [Inline] -> Inline -> Inline
resolveRefs :: Map Text [Inline] -> Inline -> Inline
resolveRefs Map Text [Inline]
labels x :: Inline
x@(Link (Text
ident,[Text]
classes,[(Text, Text)]
kvs) [Inline]
_ (Text, Text)
_) =
case (forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"reference-type" [(Text, Text)]
kvs,
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"reference" [(Text, Text)]
kvs) of
(Just Text
"ref", Just Text
lab) ->
case forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Text
lab Map Text [Inline]
labels of
Just [Inline]
txt -> Attr -> [Inline] -> (Text, Text) -> Inline
Link (Text
ident,[Text]
classes,[(Text, Text)]
kvs) [Inline]
txt (Text
"#" forall a. Semigroup a => a -> a -> a
<> Text
lab, Text
"")
Maybe [Inline]
Nothing -> Inline
x
(Maybe Text, Maybe Text)
_ -> Inline
x
resolveRefs Map Text [Inline]
_ Inline
x = Inline
x
rawLaTeXBlock :: (PandocMonad m, HasMacros s, HasReaderOptions s)
=> ParsecT Sources s m Text
rawLaTeXBlock :: forall (m :: * -> *) s.
(PandocMonad m, HasMacros s, HasReaderOptions s) =>
ParsecT Sources s m Text
rawLaTeXBlock = do
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'\\' forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
letter))
[Tok]
toks <- forall (m :: * -> *) s. PandocMonad m => ParsecT Sources s m [Tok]
getInputTokens
forall a b. (a, b) -> b
snd forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (
forall (m :: * -> *) s a.
(PandocMonad m, HasMacros s, HasReaderOptions s, Show a) =>
[Tok] -> LP m a -> LP m a -> ParsecT Sources s m (a, Text)
rawLaTeXParser [Tok]
toks
(forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
(Text -> a) -> LP m a
macroDef (forall a b. a -> b -> a
const forall a. Monoid a => a
mempty) forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
do forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice (forall a b. (a -> b) -> [a] -> [b]
map forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq
[Text
"include", Text
"input", Text
"subfile", Text
"usepackage"])
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall (m :: * -> *). PandocMonad m => LP m Inlines
opt
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty) forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (m :: * -> *) s a.
(PandocMonad m, HasMacros s, HasReaderOptions s, Show a) =>
[Tok] -> LP m a -> LP m a -> ParsecT Sources s m (a, Text)
rawLaTeXParser [Tok]
toks
(forall (m :: * -> *). PandocMonad m => LP m Blocks
environment forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (m :: * -> *). PandocMonad m => LP m Blocks
blockCommand)
(forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (forall (m :: * -> *). PandocMonad m => LP m Blocks
block forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (m :: * -> *). PandocMonad m => LP m Blocks
beginOrEndCommand)))
beginOrEndCommand :: PandocMonad m => LP m Blocks
beginOrEndCommand :: forall (m :: * -> *). PandocMonad m => LP m Blocks
beginOrEndCommand = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
Tok SourcePos
_ (CtrlSeq Text
name) Text
txt <- forall (m :: * -> *). PandocMonad m => LP m Tok
anyControlSeq
forall (f :: * -> *). Alternative f => Bool -> f ()
guard forall a b. (a -> b) -> a -> b
$ Text
name forall a. Eq a => a -> a -> Bool
== Text
"begin" Bool -> Bool -> Bool
|| Text
name forall a. Eq a => a -> a -> Bool
== Text
"end"
([Tok]
envname, [Tok]
rawargs) <- forall (m :: * -> *) a. PandocMonad m => LP m a -> LP m (a, [Tok])
withRaw forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
if forall k a. Ord k => k -> Map k a -> Bool
M.member ([Tok] -> Text
untokenize [Tok]
envname)
(forall (m :: * -> *). PandocMonad m => Map Text (LP m Inlines)
inlineEnvironments :: M.Map Text (LP PandocPure Inlines))
then forall (m :: * -> *) a. MonadPlus m => m a
mzero
else forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text -> Text -> Blocks
rawBlock Text
"latex"
(Text
txt forall a. Semigroup a => a -> a -> a
<> [Tok] -> Text
untokenize [Tok]
rawargs)
rawLaTeXInline :: (PandocMonad m, HasMacros s, HasReaderOptions s)
=> ParsecT Sources s m Text
rawLaTeXInline :: forall (m :: * -> *) s.
(PandocMonad m, HasMacros s, HasReaderOptions s) =>
ParsecT Sources s m Text
rawLaTeXInline = do
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'\\' forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
letter))
[Tok]
toks <- forall (m :: * -> *) s. PandocMonad m => ParsecT Sources s m [Tok]
getInputTokens
Text
raw <- forall a b. (a, b) -> b
snd forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
( forall (m :: * -> *) s a.
(PandocMonad m, HasMacros s, HasReaderOptions s, Show a) =>
[Tok] -> LP m a -> LP m a -> ParsecT Sources s m (a, Text)
rawLaTeXParser [Tok]
toks
(forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq Text
"input" forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall (m :: * -> *). PandocMonad m => LP m Text
rawopt forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced))
forall (m :: * -> *). PandocMonad m => LP m Inlines
inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (m :: * -> *) s a.
(PandocMonad m, HasMacros s, HasReaderOptions s, Show a) =>
[Tok] -> LP m a -> LP m a -> ParsecT Sources s m (a, Text)
rawLaTeXParser [Tok]
toks (forall (m :: * -> *). PandocMonad m => LP m Inlines
inlineEnvironment forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (m :: * -> *). PandocMonad m => LP m Inlines
inlineCommand')
forall (m :: * -> *). PandocMonad m => LP m Inlines
inlines
)
String
finalbraces <- forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
"{}"))
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
raw forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack String
finalbraces
inlineCommand :: PandocMonad m => ParsecT Sources ParserState m Inlines
inlineCommand :: forall (m :: * -> *).
PandocMonad m =>
ParsecT Sources ParserState m Inlines
inlineCommand = do
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'\\' forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
letter))
[Tok]
toks <- forall (m :: * -> *) s. PandocMonad m => ParsecT Sources s m [Tok]
getInputTokens
forall a b. (a, b) -> a
fst forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s a.
(PandocMonad m, HasMacros s, HasReaderOptions s, Show a) =>
[Tok] -> LP m a -> LP m a -> ParsecT Sources s m (a, Text)
rawLaTeXParser [Tok]
toks (forall (m :: * -> *). PandocMonad m => LP m Inlines
inlineEnvironment forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (m :: * -> *). PandocMonad m => LP m Inlines
inlineCommand')
forall (m :: * -> *). PandocMonad m => LP m Inlines
inlines
inlineGroup :: PandocMonad m => LP m Inlines
inlineGroup :: forall (m :: * -> *). PandocMonad m => LP m Inlines
inlineGroup = do
Inlines
ils <- forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped forall (m :: * -> *). PandocMonad m => LP m Inlines
inline
if forall (t :: * -> *) a. Foldable t => t a -> Bool
null Inlines
ils
then forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
else forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Attr -> Inlines -> Inlines
spanWith Attr
nullAttr Inlines
ils
doLHSverb :: PandocMonad m => LP m Inlines
doLHSverb :: forall (m :: * -> *). PandocMonad m => LP m Inlines
doLHSverb =
Attr -> Text -> Inlines
codeWith (Text
"",[Text
"haskell"],[]) forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill (forall (m :: * -> *). PandocMonad m => (Tok -> Bool) -> LP m Tok
satisfyTok (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tok -> Bool
isNewlineTok)) (forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol Char
'|')
mkImage :: PandocMonad m => [(Text, Text)] -> Text -> LP m Inlines
mkImage :: forall (m :: * -> *).
PandocMonad m =>
[(Text, Text)] -> Text -> LP m Inlines
mkImage [(Text, Text)]
options (Text -> String
T.unpack -> String
src) = do
let replaceTextwidth :: (a, Text) -> (a, Text)
replaceTextwidth (a
k,Text
v) =
case Text -> Maybe (Double, Text)
numUnit Text
v of
Just (Double
num, Text
"\\textwidth") -> (a
k, forall a. RealFloat a => a -> Text
showFl (Double
num forall a. Num a => a -> a -> a
* Double
100) forall a. Semigroup a => a -> a -> a
<> Text
"%")
Maybe (Double, Text)
_ -> (a
k, Text
v)
let kvs :: [(Text, Text)]
kvs = forall a b. (a -> b) -> [a] -> [b]
map forall {a}. (a, Text) -> (a, Text)
replaceTextwidth
forall a b. (a -> b) -> a -> b
$ forall a. (a -> Bool) -> [a] -> [a]
filter (\(Text
k,Text
_) -> Text
k forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Text
"width", Text
"height"]) [(Text, Text)]
options
let attr :: (Text, [a], [(Text, Text)])
attr = (Text
"",[], [(Text, Text)]
kvs)
let alt :: Inlines
alt = forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Text -> Inlines
str Text
"image") Text -> Inlines
str forall a b. (a -> b) -> a -> b
$ forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"alt" [(Text, Text)]
options
Text
defaultExt <- forall st s (m :: * -> *) t b.
(HasReaderOptions st, Stream s m t) =>
(ReaderOptions -> b) -> ParsecT s st m b
getOption ReaderOptions -> Text
readerDefaultImageExtension
let exts' :: [String]
exts' = [String
".pdf", String
".png", String
".jpg", String
".mps", String
".jpeg", String
".jbig2", String
".jb2"]
let exts :: [String]
exts = [String]
exts' forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map (forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toUpper) [String]
exts'
let findFile :: String -> [String] -> m String
findFile String
s [] = forall (m :: * -> *) a. Monad m => a -> m a
return String
s
findFile String
s (String
e:[String]
es) = do
let s' :: String
s' = String -> String -> String
addExtension String
s String
e
Bool
exists <- forall (m :: * -> *). PandocMonad m => String -> m Bool
fileExists String
s'
if Bool
exists
then forall (m :: * -> *) a. Monad m => a -> m a
return String
s'
else String -> [String] -> m String
findFile String
s [String]
es
String
src' <- case String -> String
takeExtension String
src of
String
"" | Bool -> Bool
not (Text -> Bool
T.null Text
defaultExt) -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ String -> String -> String
addExtension String
src forall a b. (a -> b) -> a -> b
$ Text -> String
T.unpack Text
defaultExt
| Bool
otherwise -> forall {m :: * -> *}.
PandocMonad m =>
String -> [String] -> m String
findFile String
src [String]
exts
String
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return String
src
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Attr -> Text -> Text -> Inlines -> Inlines
imageWith forall {a}. (Text, [a], [(Text, Text)])
attr (String -> Text
T.pack String
src') Text
"" Inlines
alt
removeDoubleQuotes :: Text -> Text
removeDoubleQuotes :: Text -> Text
removeDoubleQuotes Text
t =
forall a. a -> Maybe a -> a
Data.Maybe.fromMaybe Text
t forall a b. (a -> b) -> a -> b
$ Text -> Text -> Maybe Text
T.stripPrefix Text
"\"" Text
t forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Text -> Maybe Text
T.stripSuffix Text
"\""
doubleQuote :: PandocMonad m => LP m Inlines
doubleQuote :: forall (m :: * -> *). PandocMonad m => LP m Inlines
doubleQuote =
forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Inlines) -> LP m [Tok] -> LP m () -> LP m Inlines
quoted' Inlines -> Inlines
doubleQuoted (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) t u a.
Stream s m t =>
Int -> ParsecT s u m a -> ParsecT s u m [a]
count Int
2 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol Char
'`')
(forall (f :: * -> *) a. Functor f => f a -> f ()
void forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) t u a.
Stream s m t =>
Int -> ParsecT s u m a -> ParsecT s u m [a]
count Int
2 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol Char
'\'')
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Inlines) -> LP m [Tok] -> LP m () -> LP m Inlines
quoted' Inlines -> Inlines
doubleQuoted ((forall a. a -> [a] -> [a]
:[]) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol Char
'“') (forall (f :: * -> *) a. Functor f => f a -> f ()
void forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol Char
'”')
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Inlines) -> LP m [Tok] -> LP m () -> LP m Inlines
quoted' Inlines -> Inlines
doubleQuoted (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol Char
'"', forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol Char
'`'])
(forall (f :: * -> *) a. Functor f => f a -> f ()
void forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol Char
'"', forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol Char
'\''])
singleQuote :: PandocMonad m => LP m Inlines
singleQuote :: forall (m :: * -> *). PandocMonad m => LP m Inlines
singleQuote =
forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Inlines) -> LP m [Tok] -> LP m () -> LP m Inlines
quoted' Inlines -> Inlines
singleQuoted ((forall a. a -> [a] -> [a]
:[]) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol Char
'`')
(forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol Char
'\'' forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (forall (m :: * -> *). PandocMonad m => (Tok -> Bool) -> LP m Tok
satisfyTok Tok -> Bool
startsWithLetter))
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Inlines) -> LP m [Tok] -> LP m () -> LP m Inlines
quoted' Inlines -> Inlines
singleQuoted ((forall a. a -> [a] -> [a]
:[]) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol Char
'‘')
(forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol Char
'’' forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (forall (m :: * -> *). PandocMonad m => (Tok -> Bool) -> LP m Tok
satisfyTok Tok -> Bool
startsWithLetter))
where startsWithLetter :: Tok -> Bool
startsWithLetter (Tok SourcePos
_ TokType
Word Text
t) =
case Text -> Maybe (Char, Text)
T.uncons Text
t of
Just (Char
c, Text
_) | Char -> Bool
isLetter Char
c -> Bool
True
Maybe (Char, Text)
_ -> Bool
False
startsWithLetter Tok
_ = Bool
False
quoted' :: PandocMonad m
=> (Inlines -> Inlines)
-> LP m [Tok]
-> LP m ()
-> LP m Inlines
quoted' :: forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Inlines) -> LP m [Tok] -> LP m () -> LP m Inlines
quoted' Inlines -> Inlines
f LP m [Tok]
starter LP m ()
ender = do
Text
startchs <- [Tok] -> Text
untokenize forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m [Tok]
starter
Bool
smart <- Extension -> Extensions -> Bool
extensionEnabled Extension
Ext_smart forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall st s (m :: * -> *) t b.
(HasReaderOptions st, Stream s m t) =>
(ReaderOptions -> b) -> ParsecT s st m b
getOption ReaderOptions -> Extensions
readerExtensions
if Bool
smart
then do
[Inlines]
ils <- forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy LP m ()
ender forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *). PandocMonad m => LP m Inlines
inline)
(LP m ()
ender forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> Inlines
f (forall a. Monoid a => [a] -> a
mconcat [Inlines]
ils))) forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
(forall a. Semigroup a => a -> a -> a
<> forall a. Monoid a => [a] -> a
mconcat [Inlines]
ils) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
forall (m :: * -> *). Text -> LP m Inlines
lit (case Text
startchs of
Text
"``" -> Text
"“"
Text
"`" -> Text
"‘"
Text
cs -> Text
cs)
else forall (m :: * -> *). Text -> LP m Inlines
lit Text
startchs
lit :: Text -> LP m Inlines
lit :: forall (m :: * -> *). Text -> LP m Inlines
lit = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines
str
blockquote :: PandocMonad m => Bool -> Maybe Text -> LP m Blocks
blockquote :: forall (m :: * -> *).
PandocMonad m =>
Bool -> Maybe Text -> LP m Blocks
blockquote Bool
cvariant Maybe Text
mblang = do
Blocks
citepar <- if Bool
cvariant
then (\[Citation]
xs -> Inlines -> Blocks
para ([Citation] -> Inlines -> Inlines
cite [Citation]
xs forall a. Monoid a => a
mempty))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *).
PandocMonad m =>
LP m Inlines -> CitationMode -> Bool -> LP m [Citation]
cites forall (m :: * -> *). PandocMonad m => LP m Inlines
inline CitationMode
NormalCitation Bool
False
else forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option forall a. Monoid a => a
mempty forall a b. (a -> b) -> a -> b
$ Inlines -> Blocks
para forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
bracketed forall (m :: * -> *). PandocMonad m => LP m Inlines
inline
let lang :: Maybe Lang
lang = Maybe Text
mblang forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Maybe Lang
babelLangToBCP47
let langdiv :: Blocks -> Blocks
langdiv = case Maybe Lang
lang of
Maybe Lang
Nothing -> forall a. a -> a
id
Just Lang
l -> Attr -> Blocks -> Blocks
divWith (Text
"",[],[(Text
"lang", Lang -> Text
renderLang Lang
l)])
Inlines
_closingPunct <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option forall a. Monoid a => a
mempty forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
bracketed forall (m :: * -> *). PandocMonad m => LP m Inlines
inline
Blocks
bs <- forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped forall (m :: * -> *). PandocMonad m => LP m Blocks
block
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => String -> LP m Tok
symbolIn (String
".:;?!" :: [Char])
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Blocks -> Blocks
blockQuote forall b c a. (b -> c) -> (a -> b) -> a -> c
. Blocks -> Blocks
langdiv forall a b. (a -> b) -> a -> b
$ (Blocks
bs forall a. Semigroup a => a -> a -> a
<> Blocks
citepar)
inlineCommand' :: PandocMonad m => LP m Inlines
inlineCommand' :: forall (m :: * -> *). PandocMonad m => LP m Inlines
inlineCommand' = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
Tok SourcePos
_ (CtrlSeq Text
name) Text
cmd <- forall (m :: * -> *). PandocMonad m => LP m Tok
anyControlSeq
forall (f :: * -> *). Alternative f => Bool -> f ()
guard forall a b. (a -> b) -> a -> b
$ Text
name forall a. Eq a => a -> a -> Bool
/= Text
"begin" Bool -> Bool -> Bool
&& Text
name forall a. Eq a => a -> a -> Bool
/= Text
"end" Bool -> Bool -> Bool
&& Text
name forall a. Eq a => a -> a -> Bool
/= Text
"and"
Text
star <- if (Char -> Bool) -> Text -> Bool
T.all Char -> Bool
isAlphaNum Text
name
then forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Text
"" (Text
"*" forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol Char
'*' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *). PandocMonad m => LP m ()
sp)
else forall (f :: * -> *) a. Applicative f => a -> f a
pure Text
""
Text
overlay <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Text
"" forall (m :: * -> *). PandocMonad m => LP m Text
overlaySpecification
let name' :: Text
name' = Text
name forall a. Semigroup a => a -> a -> a
<> Text
star forall a. Semigroup a => a -> a -> a
<> Text
overlay
let names :: [Text]
names = forall a. Ord a => [a] -> [a]
nubOrd [Text
name', Text
name]
let raw :: ParsecT TokStream LaTeXState m Inlines
raw = do
forall (f :: * -> *). Alternative f => Bool -> f ()
guard forall a b. (a -> b) -> a -> b
$ Text -> Bool
isInlineCommand Text
name Bool -> Bool -> Bool
|| Bool -> Bool
not (Text -> Bool
isBlockCommand Text
name)
Text
rawcommand <- forall (m :: * -> *). PandocMonad m => Text -> Text -> LP m Text
getRawCommand Text
name (Text
cmd forall a. Semigroup a => a -> a -> a
<> Text
star)
(forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_raw_tex forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Text -> Inlines
rawInline Text
"latex" Text
rawcommand))
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall a (m :: * -> *) s u.
(Monoid a, PandocMonad m) =>
Text -> ParsecT s u m a
ignore Text
rawcommand
forall k v. Ord k => v -> [k] -> Map k v -> v
lookupListDefault ParsecT TokStream LaTeXState m Inlines
raw [Text]
names forall (m :: * -> *). PandocMonad m => Map Text (LP m Inlines)
inlineCommands
tok :: PandocMonad m => LP m Inlines
tok :: forall (m :: * -> *). PandocMonad m => LP m Inlines
tok = forall (m :: * -> *). PandocMonad m => LP m Inlines -> LP m Inlines
tokWith forall (m :: * -> *). PandocMonad m => LP m Inlines
inline
unescapeURL :: Text -> Text
unescapeURL :: Text -> Text
unescapeURL = [Text] -> Text
T.concat forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> [Text]
go forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> [Text]
T.splitOn Text
"\\"
where
isEscapable :: Char -> Bool
isEscapable Char
c = (Char -> Bool) -> Text -> Bool
T.any (forall a. Eq a => a -> a -> Bool
== Char
c) Text
"#$%&~_^\\{}"
go :: [Text] -> [Text]
go (Text
x:[Text]
xs) = Text
x forall a. a -> [a] -> [a]
: forall a b. (a -> b) -> [a] -> [b]
map Text -> Text
unescapeInterior [Text]
xs
go [] = []
unescapeInterior :: Text -> Text
unescapeInterior Text
t
| Just (Char
c, Text
_) <- Text -> Maybe (Char, Text)
T.uncons Text
t
, Char -> Bool
isEscapable Char
c = Text
t
| Bool
otherwise = Text
"\\" forall a. Semigroup a => a -> a -> a
<> Text
t
inlineCommands :: PandocMonad m => M.Map Text (LP m Inlines)
inlineCommands :: forall (m :: * -> *). PandocMonad m => Map Text (LP m Inlines)
inlineCommands = forall (f :: * -> *) k a.
(Foldable f, Ord k) =>
f (Map k a) -> Map k a
M.unions
[ forall (m :: * -> *).
PandocMonad m =>
LP m Inlines -> Map Text (LP m Inlines)
accentCommands forall (m :: * -> *). PandocMonad m => LP m Inlines
tok
, forall (m :: * -> *).
PandocMonad m =>
LP m Inlines -> Map Text (LP m Inlines)
citationCommands forall (m :: * -> *). PandocMonad m => LP m Inlines
inline
, forall (m :: * -> *).
PandocMonad m =>
LP m Inlines -> Map Text (LP m Inlines)
siunitxCommands forall (m :: * -> *). PandocMonad m => LP m Inlines
tok
, forall (m :: * -> *). PandocMonad m => Map Text (LP m Inlines)
acronymCommands
, forall (m :: * -> *). PandocMonad m => Map Text (LP m Inlines)
refCommands
, forall (m :: * -> *). PandocMonad m => Map Text (LP m Inlines)
nameCommands
, forall (m :: * -> *). PandocMonad m => Map Text (LP m Inlines)
verbCommands
, forall (m :: * -> *). PandocMonad m => Map Text (LP m Inlines)
charCommands
, forall (m :: * -> *).
PandocMonad m =>
LP m Inlines -> Map Text (LP m Inlines)
enquoteCommands forall (m :: * -> *). PandocMonad m => LP m Inlines
tok
, forall (m :: * -> *).
PandocMonad m =>
LP m Inlines -> Map Text (LP m Inlines)
inlineLanguageCommands forall (m :: * -> *). PandocMonad m => LP m Inlines
tok
, forall (m :: * -> *).
PandocMonad m =>
LP m Inlines -> Map Text (LP m Inlines)
biblatexInlineCommands forall (m :: * -> *). PandocMonad m => LP m Inlines
tok
, Map Text (LP m Inlines)
rest ]
where
rest :: Map Text (LP m Inlines)
rest = forall k a. Ord k => [(k, a)] -> Map k a
M.fromList
[ (Text
"emph", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
emph forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"textit", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
emph forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"textsl", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
emph forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"textsc", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
smallcaps forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"textsf", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces (Attr -> Inlines -> Inlines
spanWith (Text
"",[Text
"sans-serif"],[])) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"textmd", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces (Attr -> Inlines -> Inlines
spanWith (Text
"",[Text
"medium"],[])) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"textrm", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces (Attr -> Inlines -> Inlines
spanWith (Text
"",[Text
"roman"],[])) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"textup", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces (Attr -> Inlines -> Inlines
spanWith (Text
"",[Text
"upright"],[])) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"texttt", Attr -> Inlines -> Inlines
formatCode Attr
nullAttr forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"alert", forall (m :: * -> *). PandocMonad m => LP m ()
skipopts forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Attr -> Inlines -> Inlines
spanWith (Text
"",[Text
"alert"],[]) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"textsuperscript", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
superscript forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"textsubscript", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
subscript forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"textbf", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
strong forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"textnormal", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces (Attr -> Inlines -> Inlines
spanWith (Text
"",[Text
"nodecor"],[])) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"underline", Inlines -> Inlines
underline forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"mbox", forall (m :: * -> *).
PandocMonad m =>
Text -> LP m Inlines -> LP m Inlines
rawInlineOr Text
"mbox" forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
processHBox forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"hbox", forall (m :: * -> *).
PandocMonad m =>
Text -> LP m Inlines -> LP m Inlines
rawInlineOr Text
"hbox" forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
processHBox forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"vbox", forall (m :: * -> *).
PandocMonad m =>
Text -> LP m Inlines -> LP m Inlines
rawInlineOr Text
"vbox" forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"lettrine", forall (m :: * -> *).
PandocMonad m =>
Text -> LP m Inlines -> LP m Inlines
rawInlineOr Text
"lettrine" forall (m :: * -> *). PandocMonad m => LP m Inlines
lettrine)
, (Text
"(", Text -> Inlines
mathInline forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill forall (m :: * -> *). PandocMonad m => LP m Tok
anyTok (forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq Text
")"))
, (Text
"[", Text -> Inlines
mathDisplay forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill forall (m :: * -> *). PandocMonad m => LP m Tok
anyTok (forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq Text
"]"))
, (Text
"ensuremath", Text -> Inlines
mathInline forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced)
, (Text
"texorpdfstring", forall a b. a -> b -> a
const forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"em", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
emph forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
inlines)
, (Text
"it", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
emph forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
inlines)
, (Text
"sl", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
emph forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
inlines)
, (Text
"bf", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
strong forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
inlines)
, (Text
"tt", Attr -> Inlines -> Inlines
formatCode Attr
nullAttr forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
inlines)
, (Text
"rm", forall (m :: * -> *). PandocMonad m => LP m Inlines
inlines)
, (Text
"itshape", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
emph forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
inlines)
, (Text
"slshape", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
emph forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
inlines)
, (Text
"scshape", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
smallcaps forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
inlines)
, (Text
"bfseries", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
strong forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
inlines)
, (Text
"MakeUppercase", Inlines -> Inlines
makeUppercase forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"MakeTextUppercase", Inlines -> Inlines
makeUppercase forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"uppercase", Inlines -> Inlines
makeUppercase forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"MakeLowercase", Inlines -> Inlines
makeLowercase forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"MakeTextLowercase", Inlines -> Inlines
makeLowercase forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"lowercase", Inlines -> Inlines
makeLowercase forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"thanks", forall (m :: * -> *). PandocMonad m => LP m ()
skipopts forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Blocks -> Inlines
note forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped forall (m :: * -> *). PandocMonad m => LP m Blocks
block)
, (Text
"footnote", forall (m :: * -> *). PandocMonad m => LP m ()
skipopts forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *). PandocMonad m => LP m Inlines
footnote)
, (Text
"passthrough", Inlines -> Inlines
fixPassthroughEscapes forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"includegraphics", do [(Text, Text)]
options <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] forall (m :: * -> *). PandocMonad m => LP m [(Text, Text)]
keyvals
[Tok]
src <- forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
forall (m :: * -> *).
PandocMonad m =>
[(Text, Text)] -> Text -> LP m Inlines
mkImage [(Text, Text)]
options forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Text -> Text
unescapeURL forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Text -> Text
removeDoubleQuotes forall a b. (a -> b) -> a -> b
$ [Tok] -> Text
untokenize [Tok]
src)
, (Text
"includesvg", do [(Text, Text)]
options <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] forall (m :: * -> *). PandocMonad m => LP m [(Text, Text)]
keyvals
[Tok]
src <- forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
forall (m :: * -> *).
PandocMonad m =>
[(Text, Text)] -> Text -> LP m Inlines
mkImage [(Text, Text)]
options forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Text -> Text
unescapeURL forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Text -> Text
removeDoubleQuotes forall a b. (a -> b) -> a -> b
$ [Tok] -> Text
untokenize [Tok]
src)
, (Text
"url", (\Text
url -> Attr -> Text -> Text -> Inlines -> Inlines
linkWith (Text
"",[Text
"uri"],[]) Text
url Text
"" (Text -> Inlines
str Text
url))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
unescapeURL forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m [Tok]
bracedUrl)
, (Text
"nolinkurl", Text -> Inlines
code forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
unescapeURL forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m [Tok]
bracedUrl)
, (Text
"href", do [Tok]
url <- forall (m :: * -> *). PandocMonad m => LP m [Tok]
bracedUrl
forall (m :: * -> *). PandocMonad m => LP m ()
sp
Text -> Text -> Inlines -> Inlines
link (Text -> Text
unescapeURL forall a b. (a -> b) -> a -> b
$ [Tok] -> Text
untokenize [Tok]
url) Text
"" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"hyperlink", forall (m :: * -> *). PandocMonad m => LP m Inlines
hyperlink)
, (Text
"hyperref", forall (m :: * -> *). PandocMonad m => LP m Inlines
hyperref)
, (Text
"hypertarget", forall (m :: * -> *). PandocMonad m => LP m Inlines
hypertargetInline)
, (Text
"nohyphens", forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"textnhtt", Attr -> Inlines -> Inlines
formatCode Attr
nullAttr forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"nhttfamily", Attr -> Inlines -> Inlines
formatCode Attr
nullAttr forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"textcolor", forall (m :: * -> *). PandocMonad m => Text -> LP m Inlines
coloredInline Text
"color")
, (Text
"colorbox", forall (m :: * -> *). PandocMonad m => Text -> LP m Inlines
coloredInline Text
"background-color")
, (Text
"ifstrequal", forall (m :: * -> *) a. (PandocMonad m, Monoid a) => LP m a
ifstrequal)
, (Text
"newtoggle", forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a (m :: * -> *).
(Monoid a, PandocMonad m) =>
[Tok] -> LP m a
newToggle)
, (Text
"toggletrue", forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a (m :: * -> *).
(Monoid a, PandocMonad m) =>
Bool -> [Tok] -> LP m a
setToggle Bool
True)
, (Text
"togglefalse", forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a (m :: * -> *).
(Monoid a, PandocMonad m) =>
Bool -> [Tok] -> LP m a
setToggle Bool
False)
, (Text
"iftoggle", forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => LP m ()
ifToggle forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *). PandocMonad m => LP m Inlines
inline)
, (Text
"input", forall (m :: * -> *).
PandocMonad m =>
Text -> LP m Inlines -> LP m Inlines
rawInlineOr Text
"input" forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. (PandocMonad m, Monoid a) => Text -> LP m a
include Text
"input")
, (Text
"st", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
strikeout forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"ul", Inlines -> Inlines
underline forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"hl", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces (Attr -> Inlines -> Inlines
spanWith (Text
"",[Text
"mark"],[])) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"sout", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
strikeout forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"uline", Inlines -> Inlines
underline forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
, (Text
"ifdim", forall (m :: * -> *). PandocMonad m => LP m Inlines
ifdim)
, (Text
"today", forall (m :: * -> *). PandocMonad m => LP m Inlines
today)
]
today :: PandocMonad m => LP m Inlines
today :: forall (m :: * -> *). PandocMonad m => LP m Inlines
today =
Text -> Inlines
text forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack forall b c a. (b -> c) -> (a -> b) -> a -> c
. Day -> String
showGregorian forall b c a. (b -> c) -> (a -> b) -> a -> c
. LocalTime -> Day
localDay forall b c a. (b -> c) -> (a -> b) -> a -> c
. ZonedTime -> LocalTime
zonedTimeToLocalTime
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => m ZonedTime
getZonedTime
footnote :: PandocMonad m => LP m Inlines
= do
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \LaTeXState
st -> LaTeXState
st{ sLastNoteNum :: Int
sLastNoteNum = LaTeXState -> Int
sLastNoteNum LaTeXState
st forall a. Num a => a -> a -> a
+ Int
1 }
Blocks
contents <- forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped forall (m :: * -> *). PandocMonad m => LP m Blocks
block forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM forall (m :: * -> *). PandocMonad m => Inline -> LP m Inline
resolveNoteLabel
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Blocks -> Inlines
note Blocks
contents
resolveNoteLabel :: PandocMonad m => Inline -> LP m Inline
resolveNoteLabel :: forall (m :: * -> *). PandocMonad m => Inline -> LP m Inline
resolveNoteLabel (Span (Text
_,[Text]
cls,[(Text, Text)]
kvs) [Inline]
_)
| Just Text
lab <- forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"label" [(Text, Text)]
kvs = do
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \LaTeXState
st -> LaTeXState
st{
sLabels :: Map Text [Inline]
sLabels = forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Text
lab (forall a. Many a -> [a]
toList forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines
text forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> Text
tshow forall a b. (a -> b) -> a -> b
$ LaTeXState -> Int
sLastNoteNum LaTeXState
st)
forall a b. (a -> b) -> a -> b
$ LaTeXState -> Map Text [Inline]
sLabels LaTeXState
st }
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Attr -> [Inline] -> Inline
Span (Text
lab,[Text]
cls,[(Text, Text)]
kvs) []
resolveNoteLabel Inline
il = forall (m :: * -> *) a. Monad m => a -> m a
return Inline
il
lettrine :: PandocMonad m => LP m Inlines
lettrine :: forall (m :: * -> *). PandocMonad m => LP m Inlines
lettrine = do
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional forall (m :: * -> *). PandocMonad m => LP m Text
rawopt
Inlines
x <- forall (m :: * -> *). PandocMonad m => LP m Inlines
tok
Inlines
y <- forall (m :: * -> *). PandocMonad m => LP m Inlines
tok
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces (Attr -> Inlines -> Inlines
spanWith (Text
"",[Text
"lettrine"],[])) Inlines
x forall a. Semigroup a => a -> a -> a
<> Inlines -> Inlines
smallcaps Inlines
y
ifdim :: PandocMonad m => LP m Inlines
ifdim :: forall (m :: * -> *). PandocMonad m => LP m Inlines
ifdim = do
[Tok]
contents <- forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill forall (m :: * -> *). PandocMonad m => LP m Tok
anyTok (forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq Text
"fi")
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines
rawInline Text
"latex" forall a b. (a -> b) -> a -> b
$ Text
"\\ifdim" forall a. Semigroup a => a -> a -> a
<> [Tok] -> Text
untokenize [Tok]
contents forall a. Semigroup a => a -> a -> a
<> Text
"\\fi"
makeUppercase :: Inlines -> Inlines
makeUppercase :: Inlines -> Inlines
makeUppercase = forall a. [a] -> Many a
fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. Walkable a b => (a -> a) -> b -> b
walk ((Text -> Text) -> Inline -> Inline
alterStr Text -> Text
T.toUpper) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Many a -> [a]
toList
makeLowercase :: Inlines -> Inlines
makeLowercase :: Inlines -> Inlines
makeLowercase = forall a. [a] -> Many a
fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. Walkable a b => (a -> a) -> b -> b
walk ((Text -> Text) -> Inline -> Inline
alterStr Text -> Text
T.toLower) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Many a -> [a]
toList
alterStr :: (Text -> Text) -> Inline -> Inline
alterStr :: (Text -> Text) -> Inline -> Inline
alterStr Text -> Text
f (Str Text
xs) = Text -> Inline
Str (Text -> Text
f Text
xs)
alterStr Text -> Text
_ Inline
x = Inline
x
fixPassthroughEscapes :: Inlines -> Inlines
fixPassthroughEscapes :: Inlines -> Inlines
fixPassthroughEscapes = forall a b. Walkable a b => (a -> a) -> b -> b
walk Inline -> Inline
go
where
go :: Inline -> Inline
go (Code Attr
attr Text
txt) = Attr -> Text -> Inline
Code Attr
attr (String -> Text
T.pack forall a b. (a -> b) -> a -> b
$ String -> String
unescapePassthrough forall a b. (a -> b) -> a -> b
$ Text -> String
T.unpack Text
txt)
go Inline
x = Inline
x
unescapePassthrough :: String -> String
unescapePassthrough [] = []
unescapePassthrough (Char
'\\':Char
c:String
cs)
| Char
c forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Char
'%',Char
'{',Char
'}',Char
'\\'] = Char
c forall a. a -> [a] -> [a]
: String -> String
unescapePassthrough String
cs
unescapePassthrough (Char
c:String
cs) = Char
c forall a. a -> [a] -> [a]
: String -> String
unescapePassthrough String
cs
hyperlink :: PandocMonad m => LP m Inlines
hyperlink :: forall (m :: * -> *). PandocMonad m => LP m Inlines
hyperlink = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
Text
src <- [Tok] -> Text
untokenize forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
Inlines
lab <- forall (m :: * -> *). PandocMonad m => LP m Inlines
tok
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines -> Inlines
link (Text
"#" forall a. Semigroup a => a -> a -> a
<> Text
src) Text
"" Inlines
lab
hyperref :: PandocMonad m => LP m Inlines
hyperref :: forall (m :: * -> *). PandocMonad m => LP m Inlines
hyperref = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
Text
url <- ((Text
"#" forall a. Semigroup a => a -> a -> a
<>) forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *). PandocMonad m => LP m ()
sp forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m [Tok]
bracketedToks forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *). PandocMonad m => LP m ()
sp))
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Tok] -> Text
untokenize forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall (m :: * -> *). PandocMonad m => LP m [Tok]
bracedUrl forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *). PandocMonad m => LP m [Tok]
bracedUrl forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *). PandocMonad m => LP m [Tok]
bracedUrl)
Text -> Text -> Inlines -> Inlines
link Text
url Text
"" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok
hypertargetBlock :: PandocMonad m => LP m Blocks
hypertargetBlock :: forall (m :: * -> *). PandocMonad m => LP m Blocks
hypertargetBlock = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
Text
ref <- [Tok] -> Text
untokenize forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
Blocks
bs <- forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped forall (m :: * -> *). PandocMonad m => LP m Blocks
block
case forall a. Many a -> [a]
toList Blocks
bs of
[Header Int
1 (Text
ident,[Text]
_,[(Text, Text)]
_) [Inline]
_] | Text
ident forall a. Eq a => a -> a -> Bool
== Text
ref -> forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
bs
[Block]
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Attr -> Blocks -> Blocks
divWith (Text
ref, [], []) Blocks
bs
hypertargetInline :: PandocMonad m => LP m Inlines
hypertargetInline :: forall (m :: * -> *). PandocMonad m => LP m Inlines
hypertargetInline = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
Text
ref <- [Tok] -> Text
untokenize forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
Inlines
ils <- forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped forall (m :: * -> *). PandocMonad m => LP m Inlines
inline
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Attr -> Inlines -> Inlines
spanWith (Text
ref, [], []) Inlines
ils
newToggle :: (Monoid a, PandocMonad m) => [Tok] -> LP m a
newToggle :: forall a (m :: * -> *).
(Monoid a, PandocMonad m) =>
[Tok] -> LP m a
newToggle [Tok]
name = do
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \LaTeXState
st ->
LaTeXState
st{ sToggles :: Map Text Bool
sToggles = forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert ([Tok] -> Text
untokenize [Tok]
name) Bool
False (LaTeXState -> Map Text Bool
sToggles LaTeXState
st) }
forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
setToggle :: (Monoid a, PandocMonad m) => Bool -> [Tok] -> LP m a
setToggle :: forall a (m :: * -> *).
(Monoid a, PandocMonad m) =>
Bool -> [Tok] -> LP m a
setToggle Bool
on [Tok]
name = do
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \LaTeXState
st ->
LaTeXState
st{ sToggles :: Map Text Bool
sToggles = forall k a. Ord k => (a -> a) -> k -> Map k a -> Map k a
M.adjust (forall a b. a -> b -> a
const Bool
on) ([Tok] -> Text
untokenize [Tok]
name) (LaTeXState -> Map Text Bool
sToggles LaTeXState
st) }
forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
ifToggle :: PandocMonad m => LP m ()
ifToggle :: forall (m :: * -> *). PandocMonad m => LP m ()
ifToggle = do
[Tok]
name <- forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
[Tok]
yes <- forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
[Tok]
no <- forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
Map Text Bool
toggles <- LaTeXState -> Map Text Bool
sToggles forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
TokStream Bool
_ [Tok]
inp <- forall (m :: * -> *) s u. Monad m => ParsecT s u m s
getInput
let name' :: Text
name' = [Tok] -> Text
untokenize [Tok]
name
case forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Text
name' Map Text Bool
toggles of
Just Bool
True -> forall (m :: * -> *) s u. Monad m => s -> ParsecT s u m ()
setInput forall a b. (a -> b) -> a -> b
$ Bool -> [Tok] -> TokStream
TokStream Bool
False ([Tok]
yes forall a. [a] -> [a] -> [a]
++ [Tok]
inp)
Just Bool
False -> forall (m :: * -> *) s u. Monad m => s -> ParsecT s u m ()
setInput forall a b. (a -> b) -> a -> b
$ Bool -> [Tok] -> TokStream
TokStream Bool
False ([Tok]
no forall a. [a] -> [a] -> [a]
++ [Tok]
inp)
Maybe Bool
Nothing -> do
SourcePos
pos <- forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
UndefinedToggle Text
name' SourcePos
pos
forall (m :: * -> *) a. Monad m => a -> m a
return ()
ifstrequal :: (PandocMonad m, Monoid a) => LP m a
ifstrequal :: forall (m :: * -> *) a. (PandocMonad m, Monoid a) => LP m a
ifstrequal = do
Inlines
str1 <- forall (m :: * -> *). PandocMonad m => LP m Inlines
tok
Inlines
str2 <- forall (m :: * -> *). PandocMonad m => LP m Inlines
tok
[Tok]
ifequal <- forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
[Tok]
ifnotequal <- forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
TokStream Bool
_ [Tok]
ts <- forall (m :: * -> *) s u. Monad m => ParsecT s u m s
getInput
if Inlines
str1 forall a. Eq a => a -> a -> Bool
== Inlines
str2
then forall (m :: * -> *) s u. Monad m => s -> ParsecT s u m ()
setInput forall a b. (a -> b) -> a -> b
$ Bool -> [Tok] -> TokStream
TokStream Bool
False ([Tok]
ifequal forall a. [a] -> [a] -> [a]
++ [Tok]
ts)
else forall (m :: * -> *) s u. Monad m => s -> ParsecT s u m ()
setInput forall a b. (a -> b) -> a -> b
$ Bool -> [Tok] -> TokStream
TokStream Bool
False ([Tok]
ifnotequal forall a. [a] -> [a] -> [a]
++ [Tok]
ts)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
coloredInline :: PandocMonad m => Text -> LP m Inlines
coloredInline :: forall (m :: * -> *). PandocMonad m => Text -> LP m Inlines
coloredInline Text
stylename = do
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts
[Tok]
color <- forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
Attr -> Inlines -> Inlines
spanWith (Text
"",[],[(Text
"style",Text
stylename forall a. Semigroup a => a -> a -> a
<> Text
": " forall a. Semigroup a => a -> a -> a
<> [Tok] -> Text
untokenize [Tok]
color)]) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok
processHBox :: Inlines -> Inlines
processHBox :: Inlines -> Inlines
processHBox = forall a b. Walkable a b => (a -> a) -> b -> b
walk Inline -> Inline
convert
where
convert :: Inline -> Inline
convert Inline
Space = Text -> Inline
Str forall a b. (a -> b) -> a -> b
$ Char -> Text
T.singleton forall a b. (a -> b) -> a -> b
$ Int -> Char
chr Int
160
convert Inline
SoftBreak = Text -> Inline
Str forall a b. (a -> b) -> a -> b
$ Char -> Text
T.singleton forall a b. (a -> b) -> a -> b
$ Int -> Char
chr Int
160
convert Inline
LineBreak = Text -> Inline
Str Text
""
convert Inline
x = Inline
x
isBlockCommand :: Text -> Bool
isBlockCommand :: Text -> Bool
isBlockCommand Text
s =
Text
s forall k a. Ord k => k -> Map k a -> Bool
`M.member` (forall (m :: * -> *). PandocMonad m => Map Text (LP m Blocks)
blockCommands :: M.Map Text (LP PandocPure Blocks))
Bool -> Bool -> Bool
|| Text
s forall a. Ord a => a -> Set a -> Bool
`Set.member` Set Text
treatAsBlock
treatAsBlock :: Set.Set Text
treatAsBlock :: Set Text
treatAsBlock = forall a. Ord a => [a] -> Set a
Set.fromList
[ Text
"special", Text
"pdfannot", Text
"pdfstringdef"
, Text
"bibliographystyle"
, Text
"maketitle", Text
"makeindex", Text
"makeglossary"
, Text
"addcontentsline", Text
"addtocontents", Text
"addtocounter"
, Text
"ignore"
, Text
"hyperdef"
, Text
"markboth", Text
"markright", Text
"markleft"
, Text
"hspace", Text
"vspace"
, Text
"newpage"
, Text
"clearpage"
, Text
"pagebreak"
, Text
"titleformat"
, Text
"listoffigures"
, Text
"listoftables"
, Text
"write"
]
isInlineCommand :: Text -> Bool
isInlineCommand :: Text -> Bool
isInlineCommand Text
s =
Text
s forall k a. Ord k => k -> Map k a -> Bool
`M.member` (forall (m :: * -> *). PandocMonad m => Map Text (LP m Inlines)
inlineCommands :: M.Map Text (LP PandocPure Inlines))
Bool -> Bool -> Bool
|| Text
s forall a. Ord a => a -> Set a -> Bool
`Set.member` Set Text
treatAsInline
treatAsInline :: Set.Set Text
treatAsInline :: Set Text
treatAsInline = forall a. Ord a => [a] -> Set a
Set.fromList
[ Text
"index"
, Text
"hspace"
, Text
"vspace"
, Text
"noindent"
, Text
"newpage"
, Text
"clearpage"
, Text
"pagebreak"
]
lookupListDefault :: (Ord k) => v -> [k] -> M.Map k v -> v
lookupListDefault :: forall k v. Ord k => v -> [k] -> Map k v -> v
lookupListDefault v
d = (forall a. a -> Maybe a -> a
fromMaybe v
d forall b c a. (b -> c) -> (a -> b) -> a -> c
.) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {a} {a}. Ord a => [a] -> Map a a -> Maybe a
lookupList
where lookupList :: [a] -> Map a a -> Maybe a
lookupList [a]
l Map a a
m = forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, MonadPlus m) =>
t (m a) -> m a
msum forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (forall k a. Ord k => k -> Map k a -> Maybe a
`M.lookup` Map a a
m) [a]
l
inline :: PandocMonad m => LP m Inlines
inline :: forall (m :: * -> *). PandocMonad m => LP m Inlines
inline = do
Tok SourcePos
pos TokType
toktype Text
t <- forall (m :: * -> *). PandocMonad m => LP m Tok
peekTok
let eatOneToken :: LP m Tok
eatOneToken = forall (m :: * -> *). PandocMonad m => (Tok -> Bool) -> LP m Tok
satisfyTok (forall a b. a -> b -> a
const Bool
True)
let symbolAsString :: LP m Inlines
symbolAsString = Text -> Inlines
str Text
t forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ LP m Tok
eatOneToken
let unescapedSymbolAsString :: LP m Inlines
unescapedSymbolAsString =
do LP m Tok
eatOneToken
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
ParsingUnescaped Text
t SourcePos
pos
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text -> Inlines
str Text
t
case TokType
toktype of
TokType
Comment -> forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ LP m Tok
eatOneToken
TokType
Spaces -> Inlines
space forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ LP m Tok
eatOneToken
TokType
Newline -> Inlines
softbreak forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). PandocMonad m => LP m ()
endline
TokType
Word -> Text -> Inlines
str Text
t forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ LP m Tok
eatOneToken
TokType
Symbol ->
case Text
t of
Text
"-" -> LP m Tok
eatOneToken forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option (Text -> Inlines
str Text
"-") (forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol Char
'-' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option (Text -> Inlines
str Text
"–") (Text -> Inlines
str Text
"—" forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol Char
'-'))
Text
"'" -> LP m Tok
eatOneToken forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option (Text -> Inlines
str Text
"’") (Text -> Inlines
str Text
"”" forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol Char
'\'')
Text
"~" -> Text -> Inlines
str Text
"\160" forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ LP m Tok
eatOneToken
Text
"`" -> forall (m :: * -> *). PandocMonad m => LP m Inlines
doubleQuote forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (m :: * -> *). PandocMonad m => LP m Inlines
singleQuote forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m Inlines
symbolAsString
Text
"\"" -> forall (m :: * -> *). PandocMonad m => LP m Inlines
doubleQuote forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (m :: * -> *). PandocMonad m => LP m Inlines
singleQuote forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m Inlines
symbolAsString
Text
"“" -> forall (m :: * -> *). PandocMonad m => LP m Inlines
doubleQuote forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m Inlines
symbolAsString
Text
"‘" -> forall (m :: * -> *). PandocMonad m => LP m Inlines
singleQuote forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m Inlines
symbolAsString
Text
"$" -> forall (m :: * -> *). PandocMonad m => LP m Inlines
dollarsMath forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m Inlines
unescapedSymbolAsString
Text
"|" -> (forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_literate_haskell forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
LP m Tok
eatOneToken forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m Inlines
doLHSverb) forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m Inlines
symbolAsString
Text
"{" -> forall (m :: * -> *). PandocMonad m => LP m Inlines
inlineGroup
Text
"#" -> LP m Inlines
unescapedSymbolAsString
Text
"&" -> LP m Inlines
unescapedSymbolAsString
Text
"_" -> LP m Inlines
unescapedSymbolAsString
Text
"^" -> LP m Inlines
unescapedSymbolAsString
Text
"\\" -> forall (m :: * -> *) a. MonadPlus m => m a
mzero
Text
"}" -> forall (m :: * -> *) a. MonadPlus m => m a
mzero
Text
_ -> LP m Inlines
symbolAsString
CtrlSeq Text
_ -> forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
(Text -> a) -> LP m a
macroDef (Text -> Text -> Inlines
rawInline Text
"latex")
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (m :: * -> *). PandocMonad m => LP m Inlines
inlineGroup
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (m :: * -> *). PandocMonad m => LP m Inlines
inlineCommand'
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (m :: * -> *). PandocMonad m => LP m Inlines
inlineEnvironment
TokType
Esc1 -> Text -> Inlines
str forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Text
T.singleton forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Char
primEscape
TokType
Esc2 -> Text -> Inlines
str forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Text
T.singleton forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Char
primEscape
TokType
_ -> forall (m :: * -> *) a. MonadPlus m => m a
mzero
inlines :: PandocMonad m => LP m Inlines
inlines :: forall (m :: * -> *). PandocMonad m => LP m Inlines
inlines = forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (f :: * -> *) a. Alternative f => f a -> f [a]
many forall (m :: * -> *). PandocMonad m => LP m Inlines
inline
opt :: PandocMonad m => LP m Inlines
opt :: forall (m :: * -> *). PandocMonad m => LP m Inlines
opt = do
[Tok]
toks <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *). PandocMonad m => LP m ()
sp forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m [Tok]
bracketedToks forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *). PandocMonad m => LP m ()
sp)
LaTeXState
st <- forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
Either ParseError Inlines
parsed <- forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> u -> String -> s -> m (Either ParseError a)
runParserT (forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (f :: * -> *) a. Alternative f => f a -> f [a]
many forall (m :: * -> *). PandocMonad m => LP m Inlines
inline) LaTeXState
st String
"bracketed option"
(Bool -> [Tok] -> TokStream
TokStream Bool
False [Tok]
toks)
case Either ParseError Inlines
parsed of
Right Inlines
result -> forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
result
Left ParseError
e -> forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError forall a b. (a -> b) -> a -> b
$ Sources -> ParseError -> PandocError
fromParsecError (forall a. ToSources a => a -> Sources
toSources [Tok]
toks) ParseError
e
preamble :: PandocMonad m => LP m Blocks
preamble :: forall (m :: * -> *). PandocMonad m => LP m Blocks
preamble = forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (f :: * -> *) a. Alternative f => f a -> f [a]
many ParsecT TokStream LaTeXState m Blocks
preambleBlock
where preambleBlock :: ParsecT TokStream LaTeXState m Blocks
preambleBlock = (forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). PandocMonad m => LP m ()
spaces1)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
(Text -> a) -> LP m a
macroDef (Text -> Text -> Blocks
rawBlock Text
"latex")
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (m :: * -> *). PandocMonad m => LP m Blocks
filecontents
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). PandocMonad m => LP m Blocks
blockCommand)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (do forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (forall (m :: * -> *). PandocMonad m => Text -> LP m ()
begin_ Text
"document")
forall (m :: * -> *). PandocMonad m => LP m Tok
anyTok
forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty)
rule :: PandocMonad m => LP m Blocks
rule :: forall (m :: * -> *). PandocMonad m => LP m Blocks
rule = do
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts
Text
width <- (Char -> Bool) -> Text -> Text
T.takeWhile (\Char
c -> Char -> Bool
isDigit Char
c Bool -> Bool -> Bool
|| Char
c forall a. Eq a => a -> a -> Bool
== Char
'.') forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Walkable Inline a => a -> Text
stringify forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok
Inlines
_thickness <- forall (m :: * -> *). PandocMonad m => LP m Inlines
tok
case forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead Text
width of
Just (Double
0 :: Double) -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
Maybe Double
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
horizontalRule
paragraph :: PandocMonad m => LP m Blocks
paragraph :: forall (m :: * -> *). PandocMonad m => LP m Blocks
paragraph = do
Inlines
x <- Inlines -> Inlines
trimInlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 forall (m :: * -> *). PandocMonad m => LP m Inlines
inline
if Inlines
x forall a. Eq a => a -> a -> Bool
== forall a. Monoid a => a
mempty
then forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
else forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Inlines -> Blocks
para Inlines
x
rawBlockOr :: PandocMonad m => Text -> LP m Blocks -> LP m Blocks
rawBlockOr :: forall (m :: * -> *).
PandocMonad m =>
Text -> LP m Blocks -> LP m Blocks
rawBlockOr Text
name LP m Blocks
fallback = do
Bool
parseRaw <- Extension -> Extensions -> Bool
extensionEnabled Extension
Ext_raw_tex forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall st s (m :: * -> *) t b.
(HasReaderOptions st, Stream s m t) =>
(ReaderOptions -> b) -> ParsecT s st m b
getOption ReaderOptions -> Extensions
readerExtensions
if Bool
parseRaw
then Text -> Text -> Blocks
rawBlock Text
"latex" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => Text -> Text -> LP m Text
getRawCommand Text
name (Text
"\\" forall a. Semigroup a => a -> a -> a
<> Text
name)
else LP m Blocks
fallback
doSubfile :: PandocMonad m => LP m Blocks
doSubfile :: forall (m :: * -> *). PandocMonad m => LP m Blocks
doSubfile = do
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall (m :: * -> *). PandocMonad m => LP m Inlines
opt
String
f <- Text -> String
T.unpack forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
removeDoubleQuotes forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
T.strip forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
TokStream
oldToks <- forall (m :: * -> *) s u. Monad m => ParsecT s u m s
getInput
forall (m :: * -> *) s u. Monad m => s -> ParsecT s u m ()
setInput forall a b. (a -> b) -> a -> b
$ Bool -> [Tok] -> TokStream
TokStream Bool
False []
forall (m :: * -> *). PandocMonad m => String -> LP m ()
insertIncluded ((String -> Bool) -> String -> String -> String
ensureExtension (forall a. Eq a => a -> a -> Bool
/= String
"") String
".tex" String
f)
Blocks
bs <- forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
forall (m :: * -> *) s u. Monad m => s -> ParsecT s u m ()
setInput TokStream
oldToks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
bs
include :: (PandocMonad m, Monoid a) => Text -> LP m a
include :: forall (m :: * -> *) a. (PandocMonad m, Monoid a) => Text -> LP m a
include Text
name = do
let isAllowed :: String -> Bool
isAllowed =
case Text
name of
Text
"include" -> (forall a. Eq a => a -> a -> Bool
== String
".tex")
Text
"input" -> (forall a. Eq a => a -> a -> Bool
/= String
"")
Text
_ -> forall a b. a -> b -> a
const Bool
False
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall (m :: * -> *). PandocMonad m => LP m Inlines
opt
[String]
fs <- forall a b. (a -> b) -> [a] -> [b]
map (Text -> String
T.unpack forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
removeDoubleQuotes forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
T.strip) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> [Text]
T.splitOn Text
"," forall b c a. (b -> c) -> (a -> b) -> a -> c
.
[Tok] -> Text
untokenize forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (forall (m :: * -> *). PandocMonad m => String -> LP m ()
insertIncluded forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> Bool) -> String -> String -> String
ensureExtension String -> Bool
isAllowed String
".tex") [String]
fs
forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
usepackage :: (PandocMonad m, Monoid a) => LP m a
usepackage :: forall (m :: * -> *) a. (PandocMonad m, Monoid a) => LP m a
usepackage = do
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall (m :: * -> *). PandocMonad m => LP m Inlines
opt
[String]
fs <- forall a b. (a -> b) -> [a] -> [b]
map (Text -> String
T.unpack forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
removeDoubleQuotes forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
T.strip) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> [Text]
T.splitOn Text
"," forall b c a. (b -> c) -> (a -> b) -> a -> c
.
[Tok] -> Text
untokenize forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
let parsePackage :: String -> ParsecT TokStream LaTeXState m ()
parsePackage String
f = do
TokStream Bool
_ [Tok]
ts <- forall (m :: * -> *). PandocMonad m => String -> LP m TokStream
getIncludedToks ((String -> Bool) -> String -> String -> String
ensureExtension (forall a. Eq a => a -> a -> Bool
== String
".sty") String
".sty" String
f)
forall (m :: * -> *) a. PandocMonad m => LP m a -> [Tok] -> LP m a
parseFromToks (do Blocks
_ <- forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
do SourcePos
pos <- forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
CouldNotParseIncludeFile (String -> Text
T.pack String
f) SourcePos
pos)
[Tok]
ts
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ forall (m :: * -> *). PandocMonad m => String -> LP m ()
parsePackage [String]
fs
forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
readFileFromTexinputs :: PandocMonad m => FilePath -> LP m (Maybe Text)
readFileFromTexinputs :: forall (m :: * -> *). PandocMonad m => String -> LP m (Maybe Text)
readFileFromTexinputs String
fp = do
Map Text Text
fileContentsMap <- LaTeXState -> Map Text Text
sFileContents forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
case forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup (String -> Text
T.pack String
fp) Map Text Text
fileContentsMap of
Just Text
t -> forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. a -> Maybe a
Just Text
t)
Maybe Text
Nothing -> do
[String]
dirs <- forall a b. (a -> b) -> [a] -> [b]
map (\Text
t -> if Text -> Bool
T.null Text
t
then String
"."
else Text -> String
T.unpack Text
t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> Text -> [Text]
T.split (forall a. Eq a => a -> a -> Bool
==Char
':') forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Maybe a -> a
fromMaybe Text
""
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => Text -> m (Maybe Text)
lookupEnv Text
"TEXINPUTS"
forall (m :: * -> *).
PandocMonad m =>
[String] -> String -> m (Maybe Text)
readFileFromDirs [String]
dirs String
fp
ensureExtension :: (FilePath -> Bool) -> FilePath -> FilePath -> FilePath
ensureExtension :: (String -> Bool) -> String -> String -> String
ensureExtension String -> Bool
isAllowed String
defaultExt String
fp =
let ext :: String
ext = String -> String
takeExtension String
fp
in if String -> Bool
isAllowed String
ext
then String
fp
else String -> String -> String
addExtension String
fp String
defaultExt
getIncludedToks :: PandocMonad m
=> FilePath
-> LP m TokStream
getIncludedToks :: forall (m :: * -> *). PandocMonad m => String -> LP m TokStream
getIncludedToks String
f = do
SourcePos
pos <- forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
[Text]
containers <- forall st. HasIncludeFiles st => st -> [Text]
getIncludeFiles forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (String -> Text
T.pack String
f forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Text]
containers) forall a b. (a -> b) -> a -> b
$
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError forall a b. (a -> b) -> a -> b
$ Text -> PandocError
PandocParseError forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack forall a b. (a -> b) -> a -> b
$ String
"Include file loop at " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show SourcePos
pos
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ forall st. HasIncludeFiles st => Text -> st -> st
addIncludeFile forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack String
f
Maybe Text
mbcontents <- forall (m :: * -> *). PandocMonad m => String -> LP m (Maybe Text)
readFileFromTexinputs String
f
Text
contents <- case Maybe Text
mbcontents of
Just Text
s -> forall (m :: * -> *) a. Monad m => a -> m a
return Text
s
Maybe Text
Nothing -> do
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
CouldNotLoadIncludeFile (String -> Text
T.pack String
f) SourcePos
pos
forall (m :: * -> *) a. Monad m => a -> m a
return Text
""
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall st. HasIncludeFiles st => st -> st
dropLatestIncludeFile
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Bool -> [Tok] -> TokStream
TokStream Bool
False forall a b. (a -> b) -> a -> b
$ SourcePos -> Text -> [Tok]
tokenize (String -> SourcePos
initialPos String
f) Text
contents
insertIncluded :: PandocMonad m
=> FilePath
-> LP m ()
insertIncluded :: forall (m :: * -> *). PandocMonad m => String -> LP m ()
insertIncluded String
f = do
TokStream
contents <- forall (m :: * -> *). PandocMonad m => String -> LP m TokStream
getIncludedToks String
f
TokStream
ts <- forall (m :: * -> *) s u. Monad m => ParsecT s u m s
getInput
forall (m :: * -> *) s u. Monad m => s -> ParsecT s u m ()
setInput forall a b. (a -> b) -> a -> b
$ TokStream
contents forall a. Semigroup a => a -> a -> a
<> TokStream
ts
authors :: PandocMonad m => LP m ()
authors :: forall (m :: * -> *). PandocMonad m => LP m ()
authors = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *). PandocMonad m => LP m Tok
bgroup
let oneAuthor :: ParsecT TokStream LaTeXState m Inlines
oneAuthor = [Block] -> Inlines
blocksToInlines' forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Many a -> [a]
B.toList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 forall (m :: * -> *). PandocMonad m => LP m Blocks
block
[Inlines]
auths <- forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
sepBy ParsecT TokStream LaTeXState m Inlines
oneAuthor (forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq Text
"and")
forall (m :: * -> *). PandocMonad m => LP m Tok
egroup
forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta Text
"author" (forall a b. (a -> b) -> [a] -> [b]
map Inlines -> Inlines
trimInlines [Inlines]
auths)
looseItem :: PandocMonad m => LP m Blocks
looseItem :: forall (m :: * -> *). PandocMonad m => LP m Blocks
looseItem = do
Bool
inListItem <- LaTeXState -> Bool
sInListItem forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
forall (f :: * -> *). Alternative f => Bool -> f ()
guard forall a b. (a -> b) -> a -> b
$ Bool -> Bool
not Bool
inListItem
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts
forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
epigraph :: PandocMonad m => LP m Blocks
epigraph :: forall (m :: * -> *). PandocMonad m => LP m Blocks
epigraph = do
Blocks
p1 <- forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped forall (m :: * -> *). PandocMonad m => LP m Blocks
block
Blocks
p2 <- forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped forall (m :: * -> *). PandocMonad m => LP m Blocks
block
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Attr -> Blocks -> Blocks
divWith (Text
"", [Text
"epigraph"], []) (Blocks
p1 forall a. Semigroup a => a -> a -> a
<> Blocks
p2)
section :: PandocMonad m => Attr -> Int -> LP m Blocks
section :: forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section (Text
ident, [Text]
classes, [(Text, Text)]
kvs) Int
lvl = do
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts
Inlines
contents <- forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped forall (m :: * -> *). PandocMonad m => LP m Inlines
inline
Text
lab <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Text
ident forall a b. (a -> b) -> a -> b
$
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *). PandocMonad m => LP m ()
spaces forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq Text
"label"
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *). PandocMonad m => LP m ()
spaces forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Tok] -> Text
untokenize forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced)
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Int
lvl forall a. Eq a => a -> a -> Bool
== Int
0) forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \LaTeXState
st -> LaTeXState
st{ sHasChapters :: Bool
sHasChapters = Bool
True }
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Text
"unnumbered" forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Text]
classes) forall a b. (a -> b) -> a -> b
$ do
DottedNum
hn <- LaTeXState -> DottedNum
sLastHeaderNum forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
Bool
hasChapters <- LaTeXState -> Bool
sHasChapters forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
let lvl' :: Int
lvl' = Int
lvl forall a. Num a => a -> a -> a
+ if Bool
hasChapters then Int
1 else Int
0
let num :: DottedNum
num = Int -> DottedNum -> DottedNum
incrementDottedNum Int
lvl' DottedNum
hn
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \LaTeXState
st -> LaTeXState
st{ sLastHeaderNum :: DottedNum
sLastHeaderNum = DottedNum
num
, sLabels :: Map Text [Inline]
sLabels = forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Text
lab
[Text -> Inline
Str (DottedNum -> Text
renderDottedNum DottedNum
num)]
(LaTeXState -> Map Text [Inline]
sLabels LaTeXState
st) }
Attr
attr' <- forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st, HasLogMessages st,
HasIdentifierList st) =>
Attr -> Inlines -> ParsecT s st m Attr
registerHeader (Text
lab, [Text]
classes, [(Text, Text)]
kvs) Inlines
contents
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Attr -> Int -> Inlines -> Blocks
headerWith Attr
attr' Int
lvl Inlines
contents
blockCommand :: PandocMonad m => LP m Blocks
blockCommand :: forall (m :: * -> *). PandocMonad m => LP m Blocks
blockCommand = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
Tok SourcePos
_ (CtrlSeq Text
name) Text
txt <- forall (m :: * -> *). PandocMonad m => LP m Tok
anyControlSeq
forall (f :: * -> *). Alternative f => Bool -> f ()
guard forall a b. (a -> b) -> a -> b
$ Text
name forall a. Eq a => a -> a -> Bool
/= Text
"begin" Bool -> Bool -> Bool
&& Text
name forall a. Eq a => a -> a -> Bool
/= Text
"end" Bool -> Bool -> Bool
&& Text
name forall a. Eq a => a -> a -> Bool
/= Text
"and"
Text
star <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Text
"" (Text
"*" forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol Char
'*' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *). PandocMonad m => LP m ()
sp)
let name' :: Text
name' = Text
name forall a. Semigroup a => a -> a -> a
<> Text
star
let names :: [Text]
names = forall a. Ord a => [a] -> [a]
nubOrd [Text
name', Text
name]
let rawDefiniteBlock :: ParsecT TokStream LaTeXState m Blocks
rawDefiniteBlock = do
forall (f :: * -> *). Alternative f => Bool -> f ()
guard forall a b. (a -> b) -> a -> b
$ Text -> Bool
isBlockCommand Text
name
Text
rawcontents <- forall (m :: * -> *). PandocMonad m => Text -> Text -> LP m Text
getRawCommand Text
name (Text
txt forall a. Semigroup a => a -> a -> a
<> Text
star)
(forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_raw_tex forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Text -> Blocks
rawBlock Text
"latex" Text
rawcontents))
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall a (m :: * -> *) s u.
(Monoid a, PandocMonad m) =>
Text -> ParsecT s u m a
ignore Text
rawcontents
let startCommand :: ParsecT TokStream LaTeXState m ()
startCommand = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
Tok SourcePos
_ (CtrlSeq Text
n) Text
_ <- forall (m :: * -> *). PandocMonad m => LP m Tok
anyControlSeq
forall (f :: * -> *). Alternative f => Bool -> f ()
guard forall a b. (a -> b) -> a -> b
$ Text
"start" Text -> Text -> Bool
`T.isPrefixOf` Text
n
let rawMaybeBlock :: ParsecT TokStream LaTeXState m Blocks
rawMaybeBlock = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
forall (f :: * -> *). Alternative f => Bool -> f ()
guard forall a b. (a -> b) -> a -> b
$ Bool -> Bool
not forall a b. (a -> b) -> a -> b
$ Text -> Bool
isInlineCommand Text
name
Text
rawcontents <- forall (m :: * -> *). PandocMonad m => Text -> Text -> LP m Text
getRawCommand Text
name (Text
txt forall a. Semigroup a => a -> a -> a
<> Text
star)
Blocks
curr <- (forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_raw_tex forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Text -> Blocks
rawBlock Text
"latex" Text
rawcontents))
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall a (m :: * -> *) s u.
(Monoid a, PandocMonad m) =>
Text -> ParsecT s u m a
ignore Text
rawcontents
[Blocks]
rest <- forall (f :: * -> *) a. Alternative f => f a -> f [a]
many forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT TokStream LaTeXState m ()
startCommand forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m Blocks
blockCommand
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => LP m ()
blankline forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT TokStream LaTeXState m ()
startCommand
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Blocks
curr forall a. Semigroup a => a -> a -> a
<> forall a. Monoid a => [a] -> a
mconcat [Blocks]
rest
let raw :: ParsecT TokStream LaTeXState m Blocks
raw = ParsecT TokStream LaTeXState m Blocks
rawDefiniteBlock forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT TokStream LaTeXState m Blocks
rawMaybeBlock
forall k v. Ord k => v -> [k] -> Map k v -> v
lookupListDefault ParsecT TokStream LaTeXState m Blocks
raw [Text]
names forall (m :: * -> *). PandocMonad m => Map Text (LP m Blocks)
blockCommands
closing :: PandocMonad m => LP m Blocks
closing :: forall (m :: * -> *). PandocMonad m => LP m Blocks
closing = do
Inlines
contents <- forall (m :: * -> *). PandocMonad m => LP m Inlines
tok
LaTeXState
st <- forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
let extractInlines :: MetaValue -> [Inline]
extractInlines (MetaBlocks [Plain [Inline]
ys]) = [Inline]
ys
extractInlines (MetaBlocks [Para [Inline]
ys ]) = [Inline]
ys
extractInlines MetaValue
_ = []
let sigs :: Blocks
sigs = case Text -> Meta -> Maybe MetaValue
lookupMeta Text
"author" (LaTeXState -> Meta
sMeta LaTeXState
st) of
Just (MetaList [MetaValue]
xs) ->
Inlines -> Blocks
para forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
trimInlines forall a b. (a -> b) -> a -> b
$ forall a. [a] -> Many a
fromList forall a b. (a -> b) -> a -> b
$
forall a. [a] -> [[a]] -> [a]
intercalate [Inline
LineBreak] forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map MetaValue -> [Inline]
extractInlines [MetaValue]
xs
Maybe MetaValue
_ -> forall a. Monoid a => a
mempty
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Inlines -> Blocks
para (Inlines -> Inlines
trimInlines Inlines
contents) forall a. Semigroup a => a -> a -> a
<> Blocks
sigs
parbox :: PandocMonad m => LP m Blocks
parbox :: forall (m :: * -> *). PandocMonad m => LP m Blocks
parbox = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
Bool
oldInTableCell <- LaTeXState -> Bool
sInTableCell forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \LaTeXState
st -> LaTeXState
st{ sInTableCell :: Bool
sInTableCell = Bool
False }
Blocks
res <- forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped forall (m :: * -> *). PandocMonad m => LP m Blocks
block
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \LaTeXState
st -> LaTeXState
st{ sInTableCell :: Bool
sInTableCell = Bool
oldInTableCell }
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
res
blockCommands :: PandocMonad m => M.Map Text (LP m Blocks)
blockCommands :: forall (m :: * -> *). PandocMonad m => Map Text (LP m Blocks)
blockCommands = forall k a. Ord k => [(k, a)] -> Map k a
M.fromList
[ (Text
"par", forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). PandocMonad m => LP m ()
skipopts)
, (Text
"parbox", forall (m :: * -> *). PandocMonad m => LP m Blocks
parbox)
, (Text
"title", forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (forall (m :: * -> *). PandocMonad m => LP m ()
skipopts forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
(forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped forall (m :: * -> *). PandocMonad m => LP m Inlines
inline forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta Text
"title")
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped forall (m :: * -> *). PandocMonad m => LP m Blocks
block forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta Text
"title")))
, (Text
"subtitle", forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (forall (m :: * -> *). PandocMonad m => LP m ()
skipopts forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta Text
"subtitle"))
, (Text
"author", forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (forall (m :: * -> *). PandocMonad m => LP m ()
skipopts forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m ()
authors))
, (Text
"address", forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (forall (m :: * -> *). PandocMonad m => LP m ()
skipopts forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta Text
"address"))
, (Text
"signature", forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (forall (m :: * -> *). PandocMonad m => LP m ()
skipopts forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m ()
authors))
, (Text
"date", forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (forall (m :: * -> *). PandocMonad m => LP m ()
skipopts forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta Text
"date"))
, (Text
"newtheorem", forall (m :: * -> *). PandocMonad m => LP m Inlines -> LP m Blocks
newtheorem forall (m :: * -> *). PandocMonad m => LP m Inlines
inline)
, (Text
"theoremstyle", forall (m :: * -> *). PandocMonad m => LP m Blocks
theoremstyle)
, (Text
"extratitle", forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (forall (m :: * -> *). PandocMonad m => LP m ()
skipopts forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta Text
"extratitle"))
, (Text
"frontispiece", forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (forall (m :: * -> *). PandocMonad m => LP m ()
skipopts forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta Text
"frontispiece"))
, (Text
"titlehead", forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (forall (m :: * -> *). PandocMonad m => LP m ()
skipopts forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta Text
"titlehead"))
, (Text
"subject", forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (forall (m :: * -> *). PandocMonad m => LP m ()
skipopts forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta Text
"subject"))
, (Text
"publishers", forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (forall (m :: * -> *). PandocMonad m => LP m ()
skipopts forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta Text
"publishers"))
, (Text
"uppertitleback", forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (forall (m :: * -> *). PandocMonad m => LP m ()
skipopts forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta Text
"uppertitleback"))
, (Text
"lowertitleback", forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (forall (m :: * -> *). PandocMonad m => LP m ()
skipopts forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta Text
"lowertitleback"))
, (Text
"dedication", forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (forall (m :: * -> *). PandocMonad m => LP m ()
skipopts forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta Text
"dedication"))
, (Text
"part", forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section Attr
nullAttr (-Int
1))
, (Text
"part*", forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section (Text
"",[Text
"unnumbered"],[]) (-Int
1))
, (Text
"chapter", forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section Attr
nullAttr Int
0)
, (Text
"chapter*", forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section (Text
"",[Text
"unnumbered"],[]) Int
0)
, (Text
"section", forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section Attr
nullAttr Int
1)
, (Text
"section*", forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section (Text
"",[Text
"unnumbered"],[]) Int
1)
, (Text
"subsection", forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section Attr
nullAttr Int
2)
, (Text
"subsection*", forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section (Text
"",[Text
"unnumbered"],[]) Int
2)
, (Text
"subsubsection", forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section Attr
nullAttr Int
3)
, (Text
"subsubsection*", forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section (Text
"",[Text
"unnumbered"],[]) Int
3)
, (Text
"paragraph", forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section Attr
nullAttr Int
4)
, (Text
"paragraph*", forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section (Text
"",[Text
"unnumbered"],[]) Int
4)
, (Text
"subparagraph", forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section Attr
nullAttr Int
5)
, (Text
"subparagraph*", forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section (Text
"",[Text
"unnumbered"],[]) Int
5)
, (Text
"frametitle", forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section Attr
nullAttr Int
3)
, (Text
"framesubtitle", forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section Attr
nullAttr Int
4)
, (Text
"opening", Inlines -> Blocks
para forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Inlines
trimInlines forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall (m :: * -> *). PandocMonad m => LP m ()
skipopts forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok))
, (Text
"closing", forall (m :: * -> *). PandocMonad m => LP m ()
skipopts forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m Blocks
closing)
, (Text
"plainbreak", forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (f :: * -> *) a. Applicative f => a -> f a
pure Blocks
horizontalRule)
, (Text
"plainbreak*", forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (f :: * -> *) a. Applicative f => a -> f a
pure Blocks
horizontalRule)
, (Text
"fancybreak", forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (f :: * -> *) a. Applicative f => a -> f a
pure Blocks
horizontalRule)
, (Text
"fancybreak*", forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (f :: * -> *) a. Applicative f => a -> f a
pure Blocks
horizontalRule)
, (Text
"plainfancybreak", forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (f :: * -> *) a. Applicative f => a -> f a
pure Blocks
horizontalRule)
, (Text
"plainfancybreak*", forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (f :: * -> *) a. Applicative f => a -> f a
pure Blocks
horizontalRule)
, (Text
"pfbreak", forall (f :: * -> *) a. Applicative f => a -> f a
pure Blocks
horizontalRule)
, (Text
"pfbreak*", forall (f :: * -> *) a. Applicative f => a -> f a
pure Blocks
horizontalRule)
, (Text
"hrule", forall (f :: * -> *) a. Applicative f => a -> f a
pure Blocks
horizontalRule)
, (Text
"strut", forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Monoid a => a
mempty)
, (Text
"rule", forall (m :: * -> *). PandocMonad m => LP m Blocks
rule)
, (Text
"item", forall (m :: * -> *). PandocMonad m => LP m Blocks
looseItem)
, (Text
"documentclass", forall (m :: * -> *). PandocMonad m => LP m ()
skipopts forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m Blocks
preamble)
, (Text
"centerline", Inlines -> Blocks
para forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Inlines
trimInlines forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall (m :: * -> *). PandocMonad m => LP m ()
skipopts forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok))
, (Text
"caption", forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). PandocMonad m => LP m Inlines -> LP m ()
setCaption forall (m :: * -> *). PandocMonad m => LP m Inlines
inline)
, (Text
"bibliography", forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (forall (m :: * -> *). PandocMonad m => LP m ()
skipopts forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta Text
"bibliography" forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Inlines]
splitBibs forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize))
, (Text
"addbibresource", forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (forall (m :: * -> *). PandocMonad m => LP m ()
skipopts forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta Text
"bibliography" forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Inlines]
splitBibs forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize))
, (Text
"endinput", forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). PandocMonad m => LP m ()
skipSameFileToks)
, (Text
"lstinputlisting", forall (m :: * -> *). PandocMonad m => LP m Blocks
inputListing)
, (Text
"inputminted", forall (m :: * -> *). PandocMonad m => LP m Blocks
inputMinted)
, (Text
"graphicspath", forall (m :: * -> *). PandocMonad m => LP m Blocks
graphicsPath)
, (Text
"setdefaultlanguage", forall (m :: * -> *). PandocMonad m => LP m Blocks
setDefaultLanguage)
, (Text
"setmainlanguage", forall (m :: * -> *). PandocMonad m => LP m Blocks
setDefaultLanguage)
, (Text
"hypertarget", forall (m :: * -> *). PandocMonad m => LP m Blocks
hypertargetBlock)
, (Text
"textcolor", forall (m :: * -> *). PandocMonad m => Text -> LP m Blocks
coloredBlock Text
"color")
, (Text
"colorbox", forall (m :: * -> *). PandocMonad m => Text -> LP m Blocks
coloredBlock Text
"background-color")
, (Text
"blockquote", forall (m :: * -> *).
PandocMonad m =>
Bool -> Maybe Text -> LP m Blocks
blockquote Bool
False forall a. Maybe a
Nothing)
, (Text
"blockcquote", forall (m :: * -> *).
PandocMonad m =>
Bool -> Maybe Text -> LP m Blocks
blockquote Bool
True forall a. Maybe a
Nothing)
, (Text
"foreignblockquote", forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *).
PandocMonad m =>
Bool -> Maybe Text -> LP m Blocks
blockquote Bool
False forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize)
, (Text
"foreignblockcquote", forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *).
PandocMonad m =>
Bool -> Maybe Text -> LP m Blocks
blockquote Bool
True forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize)
, (Text
"hyphenblockquote", forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *).
PandocMonad m =>
Bool -> Maybe Text -> LP m Blocks
blockquote Bool
False forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize)
, (Text
"hyphenblockcquote", forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *).
PandocMonad m =>
Bool -> Maybe Text -> LP m Blocks
blockquote Bool
True forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize)
, (Text
"include", forall (m :: * -> *).
PandocMonad m =>
Text -> LP m Blocks -> LP m Blocks
rawBlockOr Text
"include" forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. (PandocMonad m, Monoid a) => Text -> LP m a
include Text
"include")
, (Text
"input", forall (m :: * -> *).
PandocMonad m =>
Text -> LP m Blocks -> LP m Blocks
rawBlockOr Text
"input" forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. (PandocMonad m, Monoid a) => Text -> LP m a
include Text
"input")
, (Text
"subfile", forall (m :: * -> *).
PandocMonad m =>
Text -> LP m Blocks -> LP m Blocks
rawBlockOr Text
"subfile" forall (m :: * -> *). PandocMonad m => LP m Blocks
doSubfile)
, (Text
"usepackage", forall (m :: * -> *).
PandocMonad m =>
Text -> LP m Blocks -> LP m Blocks
rawBlockOr Text
"usepackage" forall (m :: * -> *) a. (PandocMonad m, Monoid a) => LP m a
usepackage)
, (Text
"PackageError", forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced))
, (Text
"epigraph", forall (m :: * -> *). PandocMonad m => LP m Blocks
epigraph)
, (Text
"raggedright", forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Monoid a => a
mempty)
]
skipSameFileToks :: PandocMonad m => LP m ()
skipSameFileToks :: forall (m :: * -> *). PandocMonad m => LP m ()
skipSameFileToks = do
SourcePos
pos <- forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => String -> LP m Tok
infile (SourcePos -> String
sourceName SourcePos
pos)
environments :: PandocMonad m => M.Map Text (LP m Blocks)
environments :: forall (m :: * -> *). PandocMonad m => Map Text (LP m Blocks)
environments = forall k a. Ord k => Map k a -> Map k a -> Map k a
M.union (forall (m :: * -> *).
PandocMonad m =>
LP m Blocks -> LP m Inlines -> Map Text (LP m Blocks)
tableEnvironments forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks forall (m :: * -> *). PandocMonad m => LP m Inlines
inline) forall a b. (a -> b) -> a -> b
$
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList
[ (Text
"document", forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env Text
"document" forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall (m :: * -> *). PandocMonad m => LP m Tok
anyTok)
, (Text
"abstract", forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env Text
"abstract" forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta Text
"abstract"))
, (Text
"sloppypar", forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env Text
"sloppypar" forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks)
, (Text
"letter", forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env Text
"letter" forall (m :: * -> *). PandocMonad m => LP m Blocks
letterContents)
, (Text
"minipage", forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env Text
"minipage" forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m ()
spaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m ()
spaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks)
, (Text
"figure", forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env Text
"figure" forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => LP m ()
skipopts forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m Blocks
figure')
, (Text
"subfigure", forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env Text
"subfigure" forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => LP m ()
skipopts forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m Inlines
tok forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m Blocks
figure')
, (Text
"center", Attr -> Blocks -> Blocks
divWith (Text
"", [Text
"center"], []) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env Text
"center" forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks)
, (Text
"quote", Blocks -> Blocks
blockQuote forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env Text
"quote" forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks)
, (Text
"quotation", Blocks -> Blocks
blockQuote forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env Text
"quotation" forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks)
, (Text
"verse", Blocks -> Blocks
blockQuote forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env Text
"verse" forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks)
, (Text
"itemize", [Blocks] -> Blocks
bulletList forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
listenv Text
"itemize" (forall (f :: * -> *) a. Alternative f => f a -> f [a]
many forall (m :: * -> *). PandocMonad m => LP m Blocks
item))
, (Text
"description", [(Inlines, [Blocks])] -> Blocks
definitionList forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
listenv Text
"description" (forall (f :: * -> *) a. Alternative f => f a -> f [a]
many forall (m :: * -> *). PandocMonad m => LP m (Inlines, [Blocks])
descItem))
, (Text
"enumerate", forall (m :: * -> *). PandocMonad m => LP m Blocks
orderedList')
, (Text
"alltt", Blocks -> Blocks
alltt forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env Text
"alltt" forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks)
, (Text
"code", forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_literate_haskell forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
(Attr -> Text -> Blocks
codeBlockWith (Text
"",[Text
"haskell",Text
"literate"],[]) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => Text -> LP m Text
verbEnv Text
"code"))
, (Text
"comment", forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). PandocMonad m => Text -> LP m Text
verbEnv Text
"comment")
, (Text
"verbatim", Text -> Blocks
codeBlock forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => Text -> LP m Text
verbEnv Text
"verbatim")
, (Text
"Verbatim", forall (m :: * -> *). PandocMonad m => Text -> LP m Blocks
fancyverbEnv Text
"Verbatim")
, (Text
"BVerbatim", forall (m :: * -> *). PandocMonad m => Text -> LP m Blocks
fancyverbEnv Text
"BVerbatim")
, (Text
"lstlisting", do Attr
attr <- [(Text, Text)] -> Attr
parseListingsOptions forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] forall (m :: * -> *). PandocMonad m => LP m [(Text, Text)]
keyvals
Attr -> Text -> Blocks
codeBlockWith Attr
attr forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => Text -> LP m Text
verbEnv Text
"lstlisting")
, (Text
"minted", forall (m :: * -> *). PandocMonad m => LP m Blocks
minted)
, (Text
"obeylines", forall (m :: * -> *). PandocMonad m => LP m Blocks
obeylines)
, (Text
"tikzpicture", forall (m :: * -> *). PandocMonad m => Text -> LP m Blocks
rawVerbEnv Text
"tikzpicture")
, (Text
"tikzcd", forall (m :: * -> *). PandocMonad m => Text -> LP m Blocks
rawVerbEnv Text
"tikzcd")
, (Text
"lilypond", forall (m :: * -> *). PandocMonad m => Text -> LP m Blocks
rawVerbEnv Text
"lilypond")
, (Text
"ly", forall (m :: * -> *). PandocMonad m => Text -> LP m Blocks
rawVerbEnv Text
"ly")
, (Text
"proof", forall (m :: * -> *).
PandocMonad m =>
LP m Blocks -> LP m Inlines -> LP m Blocks
proof forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks forall (m :: * -> *). PandocMonad m => LP m Inlines
opt)
, (Text
"ifstrequal", forall (m :: * -> *) a. (PandocMonad m, Monoid a) => LP m a
ifstrequal)
, (Text
"newtoggle", forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a (m :: * -> *).
(Monoid a, PandocMonad m) =>
[Tok] -> LP m a
newToggle)
, (Text
"toggletrue", forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a (m :: * -> *).
(Monoid a, PandocMonad m) =>
Bool -> [Tok] -> LP m a
setToggle Bool
True)
, (Text
"togglefalse", forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a (m :: * -> *).
(Monoid a, PandocMonad m) =>
Bool -> [Tok] -> LP m a
setToggle Bool
False)
, (Text
"iftoggle", forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => LP m ()
ifToggle forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *). PandocMonad m => LP m Blocks
block)
, (Text
"CSLReferences", forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env Text
"CSLReferences" forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks)
]
filecontents :: PandocMonad m => LP m Blocks
filecontents :: forall (m :: * -> *). PandocMonad m => LP m Blocks
filecontents = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq Text
"begin"
Text
name <- [Tok] -> Text
untokenize forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
forall (f :: * -> *). Alternative f => Bool -> f ()
guard forall a b. (a -> b) -> a -> b
$ Text
name forall a. Eq a => a -> a -> Bool
== Text
"filecontents" Bool -> Bool -> Bool
|| Text
name forall a. Eq a => a -> a -> Bool
== Text
"filecontents*"
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts
Text
fp <- [Tok] -> Text
untokenize forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
Text
txt <- forall (m :: * -> *). PandocMonad m => Text -> LP m Text
verbEnv Text
name
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \LaTeXState
st ->
LaTeXState
st{ sFileContents :: Map Text Text
sFileContents = forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Text
fp Text
txt (LaTeXState -> Map Text Text
sFileContents LaTeXState
st) }
forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
environment :: PandocMonad m => LP m Blocks
environment :: forall (m :: * -> *). PandocMonad m => LP m Blocks
environment = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq Text
"begin"
Text
name <- [Tok] -> Text
untokenize forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
forall k a. Ord k => a -> k -> Map k a -> a
M.findWithDefault forall (m :: * -> *) a. MonadPlus m => m a
mzero Text
name forall (m :: * -> *). PandocMonad m => Map Text (LP m Blocks)
environments forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
forall (m :: * -> *).
PandocMonad m =>
LP m Blocks -> LP m Inlines -> Text -> LP m Blocks
theoremEnvironment forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks forall (m :: * -> *). PandocMonad m => LP m Inlines
opt Text
name forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
if forall k a. Ord k => k -> Map k a -> Bool
M.member Text
name (forall (m :: * -> *). PandocMonad m => Map Text (LP m Inlines)
inlineEnvironments
:: M.Map Text (LP PandocPure Inlines))
then forall (m :: * -> *) a. MonadPlus m => m a
mzero
else forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *). PandocMonad m => Text -> LP m Blocks
rawEnv Text
name) forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (m :: * -> *). PandocMonad m => Text -> LP m Blocks
rawVerbEnv Text
name
rawEnv :: PandocMonad m => Text -> LP m Blocks
rawEnv :: forall (m :: * -> *). PandocMonad m => Text -> LP m Blocks
rawEnv Text
name = do
Extensions
exts <- forall st s (m :: * -> *) t b.
(HasReaderOptions st, Stream s m t) =>
(ReaderOptions -> b) -> ParsecT s st m b
getOption ReaderOptions -> Extensions
readerExtensions
let parseRaw :: Bool
parseRaw = Extension -> Extensions -> Bool
extensionEnabled Extension
Ext_raw_tex Extensions
exts
Text
rawOptions <- forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (f :: * -> *) a. Alternative f => f a -> f [a]
many forall (m :: * -> *). PandocMonad m => LP m Text
rawopt
let beginCommand :: Text
beginCommand = Text
"\\begin{" forall a. Semigroup a => a -> a -> a
<> Text
name forall a. Semigroup a => a -> a -> a
<> Text
"}" forall a. Semigroup a => a -> a -> a
<> Text
rawOptions
SourcePos
pos1 <- forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
if Bool
parseRaw
then do
(Blocks
_, [Tok]
raw) <- forall (m :: * -> *) a. PandocMonad m => LP m a -> LP m (a, [Tok])
withRaw forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env Text
name forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text -> Text -> Blocks
rawBlock Text
"latex"
forall a b. (a -> b) -> a -> b
$ Text
beginCommand forall a. Semigroup a => a -> a -> a
<> [Tok] -> Text
untokenize [Tok]
raw
else do
Blocks
bs <- forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env Text
name forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
SkippedContent Text
beginCommand SourcePos
pos1
SourcePos
pos2 <- forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
SkippedContent (Text
"\\end{" forall a. Semigroup a => a -> a -> a
<> Text
name forall a. Semigroup a => a -> a -> a
<> Text
"}") SourcePos
pos2
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Attr -> Blocks -> Blocks
divWith (Text
"",[Text
name],[]) Blocks
bs
rawVerbEnv :: PandocMonad m => Text -> LP m Blocks
rawVerbEnv :: forall (m :: * -> *). PandocMonad m => Text -> LP m Blocks
rawVerbEnv Text
name = do
SourcePos
pos <- forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
(Text
_, [Tok]
raw) <- forall (m :: * -> *) a. PandocMonad m => LP m a -> LP m (a, [Tok])
withRaw forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => Text -> LP m Text
verbEnv Text
name
let raw' :: Text
raw' = Text
"\\begin{" forall a. Semigroup a => a -> a -> a
<> Text
name forall a. Semigroup a => a -> a -> a
<> Text
"}" forall a. Semigroup a => a -> a -> a
<> [Tok] -> Text
untokenize [Tok]
raw
Extensions
exts <- forall st s (m :: * -> *) t b.
(HasReaderOptions st, Stream s m t) =>
(ReaderOptions -> b) -> ParsecT s st m b
getOption ReaderOptions -> Extensions
readerExtensions
let parseRaw :: Bool
parseRaw = Extension -> Extensions -> Bool
extensionEnabled Extension
Ext_raw_tex Extensions
exts
if Bool
parseRaw
then forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text -> Text -> Blocks
rawBlock Text
"latex" Text
raw'
else do
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
SkippedContent Text
raw' SourcePos
pos
forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
fancyverbEnv :: PandocMonad m => Text -> LP m Blocks
fancyverbEnv :: forall (m :: * -> *). PandocMonad m => Text -> LP m Blocks
fancyverbEnv Text
name = do
[(Text, Text)]
options <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] forall (m :: * -> *). PandocMonad m => LP m [(Text, Text)]
keyvals
let kvs :: [(Text, Text)]
kvs = [ (if Text
k forall a. Eq a => a -> a -> Bool
== Text
"firstnumber"
then Text
"startFrom"
else Text
k, Text
v) | (Text
k,Text
v) <- [(Text, Text)]
options ]
let classes :: [Text]
classes = [ Text
"numberLines" |
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"numbers" [(Text, Text)]
options forall a. Eq a => a -> a -> Bool
== forall a. a -> Maybe a
Just Text
"left" ]
let attr :: Attr
attr = (Text
"",[Text]
classes,[(Text, Text)]
kvs)
Attr -> Text -> Blocks
codeBlockWith Attr
attr forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => Text -> LP m Text
verbEnv Text
name
obeylines :: PandocMonad m => LP m Blocks
obeylines :: forall (m :: * -> *). PandocMonad m => LP m Blocks
obeylines =
Inlines -> Blocks
para forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> Many a
fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inline] -> [Inline]
removeLeadingTrailingBreaks forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall a b. Walkable a b => (a -> a) -> b -> b
walk Inline -> Inline
softBreakToHard forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Many a -> [a]
toList forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env Text
"obeylines" forall (m :: * -> *). PandocMonad m => LP m Inlines
inlines
where softBreakToHard :: Inline -> Inline
softBreakToHard Inline
SoftBreak = Inline
LineBreak
softBreakToHard Inline
x = Inline
x
removeLeadingTrailingBreaks :: [Inline] -> [Inline]
removeLeadingTrailingBreaks = forall a. [a] -> [a]
reverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. (a -> Bool) -> [a] -> [a]
dropWhile Inline -> Bool
isLineBreak forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall a. [a] -> [a]
reverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. (a -> Bool) -> [a] -> [a]
dropWhile Inline -> Bool
isLineBreak
isLineBreak :: Inline -> Bool
isLineBreak Inline
LineBreak = Bool
True
isLineBreak Inline
_ = Bool
False
minted :: PandocMonad m => LP m Blocks
minted :: forall (m :: * -> *). PandocMonad m => LP m Blocks
minted = do
Attr
attr <- forall (m :: * -> *). PandocMonad m => LP m Attr
mintedAttr
Attr -> Text -> Blocks
codeBlockWith Attr
attr forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => Text -> LP m Text
verbEnv Text
"minted"
mintedAttr :: PandocMonad m => LP m Attr
mintedAttr :: forall (m :: * -> *). PandocMonad m => LP m Attr
mintedAttr = do
[(Text, Text)]
options <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] forall (m :: * -> *). PandocMonad m => LP m [(Text, Text)]
keyvals
Text
lang <- [Tok] -> Text
untokenize forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
let kvs :: [(Text, Text)]
kvs = [ (if Text
k forall a. Eq a => a -> a -> Bool
== Text
"firstnumber"
then Text
"startFrom"
else Text
k, Text
v) | (Text
k,Text
v) <- [(Text, Text)]
options ]
let classes :: [Text]
classes = [ Text
lang | Bool -> Bool
not (Text -> Bool
T.null Text
lang) ] forall a. [a] -> [a] -> [a]
++
[ Text
"numberLines" |
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"linenos" [(Text, Text)]
options forall a. Eq a => a -> a -> Bool
== forall a. a -> Maybe a
Just Text
"true" ]
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
"",[Text]
classes,[(Text, Text)]
kvs)
inputMinted :: PandocMonad m => LP m Blocks
inputMinted :: forall (m :: * -> *). PandocMonad m => LP m Blocks
inputMinted = do
SourcePos
pos <- forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Attr
attr <- forall (m :: * -> *). PandocMonad m => LP m Attr
mintedAttr
Text
f <- (Char -> Bool) -> Text -> Text
T.filter (forall a. Eq a => a -> a -> Bool
/=Char
'"') forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
Maybe Text
mbCode <- forall (m :: * -> *). PandocMonad m => String -> LP m (Maybe Text)
readFileFromTexinputs (Text -> String
T.unpack Text
f)
Text
rawcode <- case Maybe Text
mbCode of
Just Text
s -> forall (m :: * -> *) a. Monad m => a -> m a
return Text
s
Maybe Text
Nothing -> do
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
CouldNotLoadIncludeFile Text
f SourcePos
pos
forall (m :: * -> *) a. Monad m => a -> m a
return Text
""
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Attr -> Text -> Blocks
B.codeBlockWith Attr
attr Text
rawcode
letterContents :: PandocMonad m => LP m Blocks
letterContents :: forall (m :: * -> *). PandocMonad m => LP m Blocks
letterContents = do
Blocks
bs <- forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks
LaTeXState
st <- forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
let addr :: Blocks
addr = case Text -> Meta -> Maybe MetaValue
lookupMeta Text
"address" (LaTeXState -> Meta
sMeta LaTeXState
st) of
Just (MetaBlocks [Plain [Inline]
xs]) ->
Inlines -> Blocks
para forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
trimInlines forall a b. (a -> b) -> a -> b
$ forall a. [a] -> Many a
fromList [Inline]
xs
Maybe MetaValue
_ -> forall a. Monoid a => a
mempty
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Blocks
addr forall a. Semigroup a => a -> a -> a
<> Blocks
bs
figure' :: PandocMonad m => LP m Blocks
figure' :: forall (m :: * -> *). PandocMonad m => LP m Blocks
figure' = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *). PandocMonad m => LP m ()
resetCaption
[Either () Blocks]
innerContent <- forall (f :: * -> *) a. Alternative f => f a -> f [a]
many forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall a b. a -> Either a b
Left forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m ()
label) forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (forall a b. b -> Either a b
Right forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m Blocks
block)
let content :: Blocks
content = forall a b. Walkable a b => (a -> a) -> b -> b
walk Block -> Block
go forall a b. (a -> b) -> a -> b
$ forall a. Monoid a => [a] -> a
mconcat forall a b. (a -> b) -> a -> b
$ forall a b. (a, b) -> b
snd forall a b. (a -> b) -> a -> b
$ forall a b. [Either a b] -> ([a], [b])
partitionEithers [Either () Blocks]
innerContent
LaTeXState
st <- forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
let caption' :: Caption
caption' = forall a. a -> Maybe a -> a
fromMaybe Caption
B.emptyCaption forall a b. (a -> b) -> a -> b
$ LaTeXState -> Maybe Caption
sCaption LaTeXState
st
let mblabel :: Maybe Text
mblabel = LaTeXState -> Maybe Text
sLastLabel LaTeXState
st
let attr :: Attr
attr = case Maybe Text
mblabel of
Just Text
lab -> (Text
lab, [], [])
Maybe Text
Nothing -> Attr
nullAttr
case Maybe Text
mblabel of
Maybe Text
Nothing -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
Just Text
lab -> do
DottedNum
num <- forall (m :: * -> *).
Monad m =>
(LaTeXState -> DottedNum) -> LP m DottedNum
getNextNumber LaTeXState -> DottedNum
sLastFigureNum
forall (m :: * -> *) u s. Monad m => u -> ParsecT s u m ()
setState
LaTeXState
st { sLastFigureNum :: DottedNum
sLastFigureNum = DottedNum
num
, sLabels :: Map Text [Inline]
sLabels = forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Text
lab [Text -> Inline
Str (DottedNum -> Text
renderDottedNum DottedNum
num)] (LaTeXState -> Map Text [Inline]
sLabels LaTeXState
st)
}
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Attr -> Caption -> Blocks -> Blocks
B.figureWith Attr
attr Caption
caption' Blocks
content
where
go :: Block -> Block
go (Para [Image Attr
attr [Str Text
"image"] (Text, Text)
target]) = [Inline] -> Block
Plain [Attr -> [Inline] -> (Text, Text) -> Inline
Image Attr
attr [] (Text, Text)
target]
go Block
x = Block
x
coloredBlock :: PandocMonad m => Text -> LP m Blocks
coloredBlock :: forall (m :: * -> *). PandocMonad m => Text -> LP m Blocks
coloredBlock Text
stylename = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts
[Tok]
color <- forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped forall (m :: * -> *). PandocMonad m => LP m Inlines
inline)
let constructor :: Blocks -> Blocks
constructor = Attr -> Blocks -> Blocks
divWith (Text
"",[],[(Text
"style",Text
stylename forall a. Semigroup a => a -> a -> a
<> Text
": " forall a. Semigroup a => a -> a -> a
<> [Tok] -> Text
untokenize [Tok]
color)])
Blocks -> Blocks
constructor forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped forall (m :: * -> *). PandocMonad m => LP m Blocks
block
graphicsPath :: PandocMonad m => LP m Blocks
graphicsPath :: forall (m :: * -> *). PandocMonad m => LP m Blocks
graphicsPath = do
[String]
ps <- forall a b. (a -> b) -> [a] -> [b]
map (Text -> String
T.unpack forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
(forall (m :: * -> *). PandocMonad m => LP m Tok
bgroup forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m ()
spaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill (forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *). PandocMonad m => LP m ()
spaces) forall (m :: * -> *). PandocMonad m => LP m Tok
egroup)
forall (m :: * -> *). PandocMonad m => m [String]
getResourcePath forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *). PandocMonad m => [String] -> m ()
setResourcePath forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. Semigroup a => a -> a -> a
<> [String]
ps)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
splitBibs :: Text -> [Inlines]
splitBibs :: Text -> [Inlines]
splitBibs = forall a b. (a -> b) -> [a] -> [b]
map (Text -> Inlines
str forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b c. (a -> b -> c) -> b -> a -> c
flip String -> String -> String
replaceExtension String
"bib" forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
T.unpack forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
trim) forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> Text -> [Text]
splitTextBy (forall a. Eq a => a -> a -> Bool
==Char
',')
alltt :: Blocks -> Blocks
alltt :: Blocks -> Blocks
alltt = forall a b. Walkable a b => (a -> a) -> b -> b
walk Inline -> Inline
strToCode
where strToCode :: Inline -> Inline
strToCode (Str Text
s) = Attr -> Text -> Inline
Code Attr
nullAttr Text
s
strToCode Inline
Space = Format -> Text -> Inline
RawInline (Text -> Format
Format Text
"latex") Text
"\\ "
strToCode Inline
SoftBreak = Inline
LineBreak
strToCode Inline
x = Inline
x
parseListingsOptions :: [(Text, Text)] -> Attr
parseListingsOptions :: [(Text, Text)] -> Attr
parseListingsOptions [(Text, Text)]
options =
let kvs :: [(Text, Text)]
kvs = [ (if Text
k forall a. Eq a => a -> a -> Bool
== Text
"firstnumber"
then Text
"startFrom"
else Text
k, Text
v) | (Text
k,Text
v) <- [(Text, Text)]
options ]
classes :: [Text]
classes = [ Text
"numberLines" |
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"numbers" [(Text, Text)]
options forall a. Eq a => a -> a -> Bool
== forall a. a -> Maybe a
Just Text
"left" ]
forall a. [a] -> [a] -> [a]
++ forall a. Maybe a -> [a]
maybeToList ([(Text, Text)] -> Maybe Text
listingsLanguage [(Text, Text)]
options)
in (forall a. a -> Maybe a -> a
fromMaybe Text
"" (forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"label" [(Text, Text)]
options), [Text]
classes, [(Text, Text)]
kvs)
inputListing :: PandocMonad m => LP m Blocks
inputListing :: forall (m :: * -> *). PandocMonad m => LP m Blocks
inputListing = do
SourcePos
pos <- forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
[(Text, Text)]
options <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] forall (m :: * -> *). PandocMonad m => LP m [(Text, Text)]
keyvals
Text
f <- (Char -> Bool) -> Text -> Text
T.filter (forall a. Eq a => a -> a -> Bool
/=Char
'"') forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
Maybe Text
mbCode <- forall (m :: * -> *). PandocMonad m => String -> LP m (Maybe Text)
readFileFromTexinputs (Text -> String
T.unpack Text
f)
[Text]
codeLines <- case Maybe Text
mbCode of
Just Text
s -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text -> [Text]
T.lines Text
s
Maybe Text
Nothing -> do
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
CouldNotLoadIncludeFile Text
f SourcePos
pos
forall (m :: * -> *) a. Monad m => a -> m a
return []
let (Text
ident,[Text]
classes,[(Text, Text)]
kvs) = [(Text, Text)] -> Attr
parseListingsOptions [(Text, Text)]
options
let classes' :: [Text]
classes' =
(case [(Text, Text)] -> Maybe Text
listingsLanguage [(Text, Text)]
options of
Maybe Text
Nothing -> (forall a. Int -> [a] -> [a]
take Int
1 (SyntaxMap -> Text -> [Text]
languagesByExtension SyntaxMap
defaultSyntaxMap
(String -> Text
T.pack forall a b. (a -> b) -> a -> b
$ String -> String
takeExtension forall a b. (a -> b) -> a -> b
$ Text -> String
T.unpack Text
f)) forall a. Semigroup a => a -> a -> a
<>)
Just Text
_ -> forall a. a -> a
id) [Text]
classes
let firstline :: Int
firstline = forall a. a -> Maybe a -> a
fromMaybe Int
1 forall a b. (a -> b) -> a -> b
$ forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"firstline" [(Text, Text)]
options forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead
let lastline :: Int
lastline = forall a. a -> Maybe a -> a
fromMaybe (forall (t :: * -> *) a. Foldable t => t a -> Int
length [Text]
codeLines) forall a b. (a -> b) -> a -> b
$
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"lastline" [(Text, Text)]
options forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead
let codeContents :: Text
codeContents = Text -> [Text] -> Text
T.intercalate Text
"\n" forall a b. (a -> b) -> a -> b
$ forall a. Int -> [a] -> [a]
take (Int
1 forall a. Num a => a -> a -> a
+ Int
lastline forall a. Num a => a -> a -> a
- Int
firstline) forall a b. (a -> b) -> a -> b
$
forall a. Int -> [a] -> [a]
drop (Int
firstline forall a. Num a => a -> a -> a
- Int
1) [Text]
codeLines
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Attr -> Text -> Blocks
codeBlockWith (Text
ident,[Text]
classes',[(Text, Text)]
kvs) Text
codeContents
item :: PandocMonad m => LP m Blocks
item :: forall (m :: * -> *). PandocMonad m => LP m Blocks
item = forall (f :: * -> *) a. Functor f => f a -> f ()
void forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq Text
"item" forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m ()
skipopts forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks
descItem :: PandocMonad m => LP m (Inlines, [Blocks])
descItem :: forall (m :: * -> *). PandocMonad m => LP m (Inlines, [Blocks])
descItem = do
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional forall (m :: * -> *). PandocMonad m => LP m ()
spaces1
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq Text
"item"
forall (m :: * -> *). PandocMonad m => LP m ()
sp
Inlines
ils <- forall (m :: * -> *). PandocMonad m => LP m Inlines
opt
Blocks
bs <- forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines
ils, [Blocks
bs])
listenv :: PandocMonad m => Text -> LP m a -> LP m a
listenv :: forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
listenv Text
name LP m a
p = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
Bool
oldInListItem <- LaTeXState -> Bool
sInListItem forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \LaTeXState
st -> LaTeXState
st{ sInListItem :: Bool
sInListItem = Bool
True }
a
res <- forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env Text
name LP m a
p
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \LaTeXState
st -> LaTeXState
st{ sInListItem :: Bool
sInListItem = Bool
oldInListItem }
forall (m :: * -> *) a. Monad m => a -> m a
return a
res
orderedList' :: PandocMonad m => LP m Blocks
orderedList' :: forall (m :: * -> *). PandocMonad m => LP m Blocks
orderedList' = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
let markerSpec :: ParsecT TokStream LaTeXState m ListAttributes
markerSpec = do
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol Char
'['
Text
ts <- [Tok] -> Text
untokenize forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill forall (m :: * -> *). PandocMonad m => LP m Tok
anyTok (forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol Char
']')
case forall s t u a.
Stream s Identity t =>
Parsec s u a -> u -> String -> s -> Either ParseError a
runParser forall s (m :: * -> *).
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s ParserState m ListAttributes
anyOrderedListMarker forall a. Default a => a
def String
"option" Text
ts of
Right ListAttributes
r -> forall (m :: * -> *) a. Monad m => a -> m a
return ListAttributes
r
Left ParseError
_ -> do
SourcePos
pos <- forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
SkippedContent (Text
"[" forall a. Semigroup a => a -> a -> a
<> Text
ts forall a. Semigroup a => a -> a -> a
<> Text
"]") SourcePos
pos
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
1, ListNumberStyle
DefaultStyle, ListNumberDelim
DefaultDelim)
(Int
_, ListNumberStyle
style, ListNumberDelim
delim) <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option (Int
1, ListNumberStyle
DefaultStyle, ListNumberDelim
DefaultDelim) ParsecT TokStream LaTeXState m ListAttributes
markerSpec
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq Text
"setlength"
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped (forall s (m :: * -> *) t u a.
Stream s m t =>
Int -> ParsecT s u m a -> ParsecT s u m [a]
count Int
1 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq Text
"itemindent")
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
Int
start <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Int
1 forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do SourcePos
pos <- forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq Text
"setcounter"
Text
ctr <- [Tok] -> Text
untokenize forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
forall (f :: * -> *). Alternative f => Bool -> f ()
guard forall a b. (a -> b) -> a -> b
$ Text
"enum" Text -> Text -> Bool
`T.isPrefixOf` Text
ctr
forall (f :: * -> *). Alternative f => Bool -> f ()
guard forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> Text -> Bool
T.all (forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Char
'i',Char
'v']) (Int -> Text -> Text
T.drop Int
4 Text
ctr)
forall (m :: * -> *). PandocMonad m => LP m ()
sp
Text
num <- [Tok] -> Text
untokenize forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
case forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead Text
num of
Just Int
i -> forall (m :: * -> *) a. Monad m => a -> m a
return (Int
i forall a. Num a => a -> a -> a
+ Int
1 :: Int)
Maybe Int
Nothing -> do
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
SkippedContent
(Text
"\\setcounter{" forall a. Semigroup a => a -> a -> a
<> Text
ctr forall a. Semigroup a => a -> a -> a
<>
Text
"}{" forall a. Semigroup a => a -> a -> a
<> Text
num forall a. Semigroup a => a -> a -> a
<> Text
"}") SourcePos
pos
forall (m :: * -> *) a. Monad m => a -> m a
return Int
1
[Blocks]
bs <- forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
listenv Text
"enumerate" (forall (f :: * -> *) a. Alternative f => f a -> f [a]
many forall (m :: * -> *). PandocMonad m => LP m Blocks
item)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ ListAttributes -> [Blocks] -> Blocks
orderedListWith (Int
start, ListNumberStyle
style, ListNumberDelim
delim) [Blocks]
bs
block :: PandocMonad m => LP m Blocks
block :: forall (m :: * -> *). PandocMonad m => LP m Blocks
block = do
Tok SourcePos
_ TokType
toktype Text
_ <- forall (m :: * -> *). PandocMonad m => LP m Tok
peekTok
Blocks
res <- (case TokType
toktype of
TokType
Newline -> forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). PandocMonad m => LP m ()
spaces1
TokType
Spaces -> forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). PandocMonad m => LP m ()
spaces1
TokType
Comment -> forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *). PandocMonad m => LP m ()
spaces1
TokType
Word -> forall (m :: * -> *). PandocMonad m => LP m Blocks
paragraph
CtrlSeq Text
"begin" -> forall (m :: * -> *). PandocMonad m => LP m Blocks
environment
CtrlSeq Text
_ -> forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
(Text -> a) -> LP m a
macroDef (Text -> Text -> Blocks
rawBlock Text
"latex")
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (m :: * -> *). PandocMonad m => LP m Blocks
blockCommand
TokType
_ -> forall (m :: * -> *) a. MonadPlus m => m a
mzero)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (m :: * -> *). PandocMonad m => LP m Blocks
paragraph
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped forall (m :: * -> *). PandocMonad m => LP m Blocks
block
forall (m :: * -> *). PandocMonad m => Text -> m ()
trace (Int -> Text -> Text
T.take Int
60 forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> Text
tshow forall a b. (a -> b) -> a -> b
$ forall a. Many a -> [a]
B.toList Blocks
res)
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
res
blocks :: PandocMonad m => LP m Blocks
blocks :: forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks = forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (f :: * -> *) a. Alternative f => f a -> f [a]
many forall (m :: * -> *). PandocMonad m => LP m Blocks
block