{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
module Text.Pandoc.Readers.Org.Inlines
( inline
, inlines
, addToNotesTable
, linkTarget
) where
import Text.Pandoc.Readers.Org.BlockStarts (endOfBlock, noteMarker)
import Text.Pandoc.Readers.Org.ParserState
import Text.Pandoc.Readers.Org.Parsing
import Text.Pandoc.Readers.Org.Shared (cleanLinkText, isImageFilename,
originalLang, translateLang, exportsCode)
import Text.Pandoc.Builder (Inlines)
import qualified Text.Pandoc.Builder as B
import Text.Pandoc.Class.PandocMonad (PandocMonad)
import Text.Pandoc.Definition
import Text.Pandoc.Options
import Text.Pandoc.Readers.LaTeX (inlineCommand, rawLaTeXInline)
import Text.TeXMath (DisplayType (..), readTeX, writePandoc)
import qualified Text.TeXMath.Readers.MathML.EntityMap as MathMLEntityMap
import Control.Monad (guard, mplus, mzero, unless, void, when)
import Control.Monad.Trans (lift)
import Data.Char (isAlphaNum, isSpace)
import Data.List (intersperse)
import qualified Data.Map as M
import Data.Text (Text)
import qualified Data.Text as T
recordAnchorId :: PandocMonad m => Text -> OrgParser m ()
recordAnchorId :: Text -> OrgParser m ()
recordAnchorId Text
i = (OrgParserState -> OrgParserState) -> OrgParser m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((OrgParserState -> OrgParserState) -> OrgParser m ())
-> (OrgParserState -> OrgParserState) -> OrgParser m ()
forall a b. (a -> b) -> a -> b
$ \OrgParserState
s ->
OrgParserState
s{ orgStateAnchorIds :: [Text]
orgStateAnchorIds = Text
i Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
: OrgParserState -> [Text]
orgStateAnchorIds OrgParserState
s }
pushToInlineCharStack :: PandocMonad m => Char -> OrgParser m ()
pushToInlineCharStack :: Char -> OrgParser m ()
pushToInlineCharStack Char
c = (OrgParserState -> OrgParserState) -> OrgParser m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((OrgParserState -> OrgParserState) -> OrgParser m ())
-> (OrgParserState -> OrgParserState) -> OrgParser m ()
forall a b. (a -> b) -> a -> b
$ \OrgParserState
s ->
OrgParserState
s{ orgStateEmphasisCharStack :: [Char]
orgStateEmphasisCharStack = Char
cChar -> [Char] -> [Char]
forall a. a -> [a] -> [a]
:OrgParserState -> [Char]
orgStateEmphasisCharStack OrgParserState
s }
popInlineCharStack :: PandocMonad m => OrgParser m ()
popInlineCharStack :: OrgParser m ()
popInlineCharStack = (OrgParserState -> OrgParserState) -> OrgParser m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((OrgParserState -> OrgParserState) -> OrgParser m ())
-> (OrgParserState -> OrgParserState) -> OrgParser m ()
forall a b. (a -> b) -> a -> b
$ \OrgParserState
s ->
OrgParserState
s{ orgStateEmphasisCharStack :: [Char]
orgStateEmphasisCharStack = Int -> [Char] -> [Char]
forall a. Int -> [a] -> [a]
drop Int
1 ([Char] -> [Char])
-> (OrgParserState -> [Char]) -> OrgParserState -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OrgParserState -> [Char]
orgStateEmphasisCharStack (OrgParserState -> [Char]) -> OrgParserState -> [Char]
forall a b. (a -> b) -> a -> b
$ OrgParserState
s }
surroundingEmphasisChar :: PandocMonad m => OrgParser m [Char]
surroundingEmphasisChar :: OrgParser m [Char]
surroundingEmphasisChar =
Int -> [Char] -> [Char]
forall a. Int -> [a] -> [a]
take Int
1 ([Char] -> [Char])
-> (OrgParserState -> [Char]) -> OrgParserState -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [Char] -> [Char]
forall a. Int -> [a] -> [a]
drop Int
1 ([Char] -> [Char])
-> (OrgParserState -> [Char]) -> OrgParserState -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OrgParserState -> [Char]
orgStateEmphasisCharStack (OrgParserState -> [Char])
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) OrgParserState
-> OrgParser m [Char]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) OrgParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
startEmphasisNewlinesCounting :: PandocMonad m => Int -> OrgParser m ()
startEmphasisNewlinesCounting :: Int -> OrgParser m ()
startEmphasisNewlinesCounting Int
maxNewlines = (OrgParserState -> OrgParserState) -> OrgParser m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((OrgParserState -> OrgParserState) -> OrgParser m ())
-> (OrgParserState -> OrgParserState) -> OrgParser m ()
forall a b. (a -> b) -> a -> b
$ \OrgParserState
s ->
OrgParserState
s{ orgStateEmphasisNewlines :: Maybe Int
orgStateEmphasisNewlines = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
maxNewlines }
decEmphasisNewlinesCount :: PandocMonad m => OrgParser m ()
decEmphasisNewlinesCount :: OrgParser m ()
decEmphasisNewlinesCount = (OrgParserState -> OrgParserState) -> OrgParser m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((OrgParserState -> OrgParserState) -> OrgParser m ())
-> (OrgParserState -> OrgParserState) -> OrgParser m ()
forall a b. (a -> b) -> a -> b
$ \OrgParserState
s ->
OrgParserState
s{ orgStateEmphasisNewlines :: Maybe Int
orgStateEmphasisNewlines = (\Int
n -> Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) (Int -> Int) -> Maybe Int -> Maybe Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OrgParserState -> Maybe Int
orgStateEmphasisNewlines OrgParserState
s }
newlinesCountWithinLimits :: PandocMonad m => OrgParser m Bool
newlinesCountWithinLimits :: OrgParser m Bool
newlinesCountWithinLimits = do
OrgParserState
st <- ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) OrgParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
Bool -> OrgParser m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> OrgParser m Bool) -> Bool -> OrgParser m Bool
forall a b. (a -> b) -> a -> b
$ ((Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0) (Int -> Bool) -> Maybe Int -> Maybe Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OrgParserState -> Maybe Int
orgStateEmphasisNewlines OrgParserState
st) Maybe Bool -> Maybe Bool -> Bool
forall a. Eq a => a -> a -> Bool
/= Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True
resetEmphasisNewlines :: PandocMonad m => OrgParser m ()
resetEmphasisNewlines :: OrgParser m ()
resetEmphasisNewlines = (OrgParserState -> OrgParserState) -> OrgParser m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((OrgParserState -> OrgParserState) -> OrgParser m ())
-> (OrgParserState -> OrgParserState) -> OrgParser m ()
forall a b. (a -> b) -> a -> b
$ \OrgParserState
s ->
OrgParserState
s{ orgStateEmphasisNewlines :: Maybe Int
orgStateEmphasisNewlines = Maybe Int
forall a. Maybe a
Nothing }
addToNotesTable :: PandocMonad m => OrgNoteRecord -> OrgParser m ()
addToNotesTable :: OrgNoteRecord -> OrgParser m ()
addToNotesTable OrgNoteRecord
note = do
OrgNoteTable
oldnotes <- OrgParserState -> OrgNoteTable
orgStateNotes' (OrgParserState -> OrgNoteTable)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) OrgParserState
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) OrgNoteTable
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) OrgParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
(OrgParserState -> OrgParserState) -> OrgParser m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((OrgParserState -> OrgParserState) -> OrgParser m ())
-> (OrgParserState -> OrgParserState) -> OrgParser m ()
forall a b. (a -> b) -> a -> b
$ \OrgParserState
s -> OrgParserState
s{ orgStateNotes' :: OrgNoteTable
orgStateNotes' = OrgNoteRecord
noteOrgNoteRecord -> OrgNoteTable -> OrgNoteTable
forall a. a -> [a] -> [a]
:OrgNoteTable
oldnotes }
inline :: PandocMonad m => OrgParser m (F Inlines)
inline :: OrgParser m (F Inlines)
inline =
[OrgParser m (F Inlines)] -> OrgParser m (F Inlines)
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [ OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
whitespace
, OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
linebreak
, OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
cite
, OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
footnote
, OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
linkOrImage
, OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
anchor
, OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inlineCodeBlock
, OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
str
, OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
endline
, OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
emphasizedText
, OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
code
, OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
math
, OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
displayMath
, OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
verbatim
, OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
subscript
, OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
superscript
, OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inlineLaTeX
, OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
exportSnippet
, OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
macro
, OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
smart
, OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
symbol
] OrgParser m (F Inlines)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* (Bool -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ())
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
forall (m :: * -> *). PandocMonad m => OrgParser m Bool
newlinesCountWithinLimits)
OrgParser m (F Inlines) -> [Char] -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"inline"
inlines :: PandocMonad m => OrgParser m (F Inlines)
inlines :: OrgParser m (F Inlines)
inlines = F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF (F Inlines -> F Inlines)
-> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
-> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OrgParser m (F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inline
specialChars :: [Char]
specialChars :: [Char]
specialChars = [Char]
"\"$'()*+-,./:;<=>@[\\]^_{|}~"
whitespace :: PandocMonad m => OrgParser m (F Inlines)
whitespace :: OrgParser m (F Inlines)
whitespace = Inlines -> F Inlines
forall (f :: * -> *) a. Applicative f => a -> f a
pure Inlines
B.space F Inlines
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
spaceChar
OrgParser m (F Inlines)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *). Monad m => OrgParser m ()
updateLastPreCharPos
OrgParser m (F Inlines)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *). Monad m => OrgParser m ()
updateLastForbiddenCharPos
OrgParser m (F Inlines) -> [Char] -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"whitespace"
linebreak :: PandocMonad m => OrgParser m (F Inlines)
linebreak :: OrgParser m (F Inlines)
linebreak = OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (F Inlines) -> OrgParser m (F Inlines))
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ Inlines -> F Inlines
forall (f :: * -> *) a. Applicative f => a -> f a
pure Inlines
B.linebreak F Inlines
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"\\\\" OrgParser m (F Inlines)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
skipSpaces OrgParser m (F Inlines)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall (m :: * -> *). Monad m => OrgParser m Char
newline
str :: PandocMonad m => OrgParser m (F Inlines)
str :: OrgParser m (F Inlines)
str = Inlines -> F Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines) -> (Text -> Inlines) -> Text -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines
B.str (Text -> F Inlines)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
-> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
many1Char ([Char]
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
noneOf ([Char]
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char)
-> [Char]
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall a b. (a -> b) -> a -> b
$ [Char]
specialChars [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"\n\r ")
OrgParser m (F Inlines)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) a st.
(Stream s m a, HasLastStrPosition st) =>
ParserT s st m ()
updateLastStrPos
endline :: PandocMonad m => OrgParser m (F Inlines)
endline :: OrgParser m (F Inlines)
endline = OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (F Inlines) -> OrgParser m (F Inlines))
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
OrgParser m Char
forall (m :: * -> *). Monad m => OrgParser m Char
newline
ParserT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall b s (m :: * -> *) a st.
(Show b, Stream s m a) =>
ParserT s st m b -> ParserT s st m ()
notFollowedBy' ParserT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *). Monad m => OrgParser m ()
endOfBlock
ParserT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *). PandocMonad m => OrgParser m ()
decEmphasisNewlinesCount
Bool -> ParserT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParserT Text OrgParserState (ReaderT OrgParserLocal m) ())
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
forall (m :: * -> *). PandocMonad m => OrgParser m Bool
newlinesCountWithinLimits
ParserT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *). Monad m => OrgParser m ()
updateLastPreCharPos
Bool
useHardBreaks <- ExportSettings -> Bool
exportPreserveBreaks (ExportSettings -> Bool)
-> (OrgParserState -> ExportSettings) -> OrgParserState -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OrgParserState -> ExportSettings
orgStateExportSettings (OrgParserState -> Bool)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) OrgParserState
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) OrgParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
Inlines -> OrgParser m (F Inlines)
forall (m :: * -> *) a s. Monad m => a -> m (Future s a)
returnF (if Bool
useHardBreaks then Inlines
B.linebreak else Inlines
B.softbreak)
cite :: PandocMonad m => OrgParser m (F Inlines)
cite :: OrgParser m (F Inlines)
cite = OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (F Inlines) -> OrgParser m (F Inlines))
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
berkeleyCite OrgParser m (F Inlines)
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> do
Extension
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParserT s st m ()
guardEnabled Extension
Ext_citations
(F [Citation]
cs, Text
raw) <- ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (F [Citation])
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (F [Citation], Text)
forall (m :: * -> *) st a.
Monad m =>
ParsecT Text st m a -> ParsecT Text st m (a, Text)
withRaw (ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (F [Citation])
-> ParsecT
Text
OrgParserState
(ReaderT OrgParserLocal m)
(F [Citation], Text))
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (F [Citation])
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (F [Citation], Text)
forall a b. (a -> b) -> a -> b
$ [ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (F [Citation])]
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (F [Citation])
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
[ ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (F [Citation])
forall (m :: * -> *). PandocMonad m => OrgParser m (F [Citation])
pandocOrgCite
, ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (F [Citation])
forall (m :: * -> *). PandocMonad m => OrgParser m (F [Citation])
orgRefCite
, ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (F [Citation])
forall (m :: * -> *). PandocMonad m => OrgParser m (F [Citation])
berkeleyTextualCite
]
F Inlines -> OrgParser m (F Inlines)
forall (m :: * -> *) a. Monad m => a -> m a
return (F Inlines -> OrgParser m (F Inlines))
-> F Inlines -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ ([Citation] -> Inlines -> Inlines)
-> Inlines -> [Citation] -> Inlines
forall a b c. (a -> b -> c) -> b -> a -> c
flip [Citation] -> Inlines -> Inlines
B.cite (Text -> Inlines
B.text Text
raw) ([Citation] -> Inlines) -> F [Citation] -> F Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> F [Citation]
cs
pandocOrgCite :: PandocMonad m => OrgParser m (F [Citation])
pandocOrgCite :: OrgParser m (F [Citation])
pandocOrgCite = OrgParser m (F [Citation]) -> OrgParser m (F [Citation])
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (F [Citation]) -> OrgParser m (F [Citation]))
-> OrgParser m (F [Citation]) -> OrgParser m (F [Citation])
forall a b. (a -> b) -> a -> b
$
Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'[' ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
skipSpaces ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> OrgParser m (F [Citation]) -> OrgParser m (F [Citation])
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> OrgParser m (F [Citation])
forall (m :: * -> *). PandocMonad m => OrgParser m (F [Citation])
citeList OrgParser m (F [Citation])
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> OrgParser m (F [Citation])
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
skipSpaces OrgParser m (F [Citation])
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> OrgParser m (F [Citation])
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
']'
orgRefCite :: PandocMonad m => OrgParser m (F [Citation])
orgRefCite :: OrgParser m (F [Citation])
orgRefCite = OrgParser m (F [Citation]) -> OrgParser m (F [Citation])
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (F [Citation]) -> OrgParser m (F [Citation]))
-> OrgParser m (F [Citation]) -> OrgParser m (F [Citation])
forall a b. (a -> b) -> a -> b
$ [OrgParser m (F [Citation])] -> OrgParser m (F [Citation])
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
[ OrgParser m (F [Citation])
forall (m :: * -> *). PandocMonad m => OrgParser m (F [Citation])
normalOrgRefCite
, (Citation -> [Citation])
-> Future OrgParserState Citation -> F [Citation]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Citation -> [Citation] -> [Citation]
forall a. a -> [a] -> [a]
:[]) (Future OrgParserState Citation -> F [Citation])
-> ParsecT
Text
OrgParserState
(ReaderT OrgParserLocal m)
(Future OrgParserState Citation)
-> OrgParser m (F [Citation])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
Text
OrgParserState
(ReaderT OrgParserLocal m)
(Future OrgParserState Citation)
forall (m :: * -> *).
PandocMonad m =>
OrgParser m (Future OrgParserState Citation)
linkLikeOrgRefCite
]
normalOrgRefCite :: PandocMonad m => OrgParser m (F [Citation])
normalOrgRefCite :: OrgParser m (F [Citation])
normalOrgRefCite = OrgParser m (F [Citation]) -> OrgParser m (F [Citation])
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (F [Citation]) -> OrgParser m (F [Citation]))
-> OrgParser m (F [Citation]) -> OrgParser m (F [Citation])
forall a b. (a -> b) -> a -> b
$ do
CitationMode
mode <- OrgParser m CitationMode
forall (m :: * -> *). PandocMonad m => OrgParser m CitationMode
orgRefCiteMode
Future OrgParserState Citation
firstCitation <- CitationMode -> OrgParser m (Future OrgParserState Citation)
forall (m :: * -> *).
PandocMonad m =>
CitationMode -> OrgParser m (Future OrgParserState Citation)
orgRefCiteList CitationMode
mode
[Future OrgParserState Citation]
moreCitations <- OrgParser m (Future OrgParserState Citation)
-> ParsecT
Text
OrgParserState
(ReaderT OrgParserLocal m)
[Future OrgParserState Citation]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (OrgParser m (Future OrgParserState Citation)
-> OrgParser m (Future OrgParserState Citation)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (Future OrgParserState Citation)
-> OrgParser m (Future OrgParserState Citation))
-> OrgParser m (Future OrgParserState Citation)
-> OrgParser m (Future OrgParserState Citation)
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
',' ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> OrgParser m (Future OrgParserState Citation)
-> OrgParser m (Future OrgParserState Citation)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> CitationMode -> OrgParser m (Future OrgParserState Citation)
forall (m :: * -> *).
PandocMonad m =>
CitationMode -> OrgParser m (Future OrgParserState Citation)
orgRefCiteList CitationMode
mode)
F [Citation] -> OrgParser m (F [Citation])
forall (m :: * -> *) a. Monad m => a -> m a
return (F [Citation] -> OrgParser m (F [Citation]))
-> ([Future OrgParserState Citation] -> F [Citation])
-> [Future OrgParserState Citation]
-> OrgParser m (F [Citation])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Future OrgParserState Citation] -> F [Citation]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence ([Future OrgParserState Citation] -> OrgParser m (F [Citation]))
-> [Future OrgParserState Citation] -> OrgParser m (F [Citation])
forall a b. (a -> b) -> a -> b
$ Future OrgParserState Citation
firstCitation Future OrgParserState Citation
-> [Future OrgParserState Citation]
-> [Future OrgParserState Citation]
forall a. a -> [a] -> [a]
: [Future OrgParserState Citation]
moreCitations
where
orgRefCiteList :: PandocMonad m => CitationMode -> OrgParser m (F Citation)
orgRefCiteList :: CitationMode -> OrgParser m (Future OrgParserState Citation)
orgRefCiteList CitationMode
citeMode = OrgParser m (Future OrgParserState Citation)
-> OrgParser m (Future OrgParserState Citation)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (Future OrgParserState Citation)
-> OrgParser m (Future OrgParserState Citation))
-> OrgParser m (Future OrgParserState Citation)
-> OrgParser m (Future OrgParserState Citation)
forall a b. (a -> b) -> a -> b
$ do
Text
key <- OrgParser m Text
forall (m :: * -> *). PandocMonad m => OrgParser m Text
orgRefCiteKey
Citation -> OrgParser m (Future OrgParserState Citation)
forall (m :: * -> *) a s. Monad m => a -> m (Future s a)
returnF Citation :: Text
-> [Inline] -> [Inline] -> CitationMode -> Int -> Int -> Citation
Citation
{ citationId :: Text
citationId = Text
key
, citationPrefix :: [Inline]
citationPrefix = [Inline]
forall a. Monoid a => a
mempty
, citationSuffix :: [Inline]
citationSuffix = [Inline]
forall a. Monoid a => a
mempty
, citationMode :: CitationMode
citationMode = CitationMode
citeMode
, citationNoteNum :: Int
citationNoteNum = Int
0
, citationHash :: Int
citationHash = Int
0
}
berkeleyCite :: PandocMonad m => OrgParser m (F Inlines)
berkeleyCite :: OrgParser m (F Inlines)
berkeleyCite = OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (F Inlines) -> OrgParser m (F Inlines))
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
F BerkeleyCitationList
bcl <- OrgParser m (F BerkeleyCitationList)
forall (m :: * -> *).
PandocMonad m =>
OrgParser m (F BerkeleyCitationList)
berkeleyCitationList
F Inlines -> OrgParser m (F Inlines)
forall (m :: * -> *) a. Monad m => a -> m a
return (F Inlines -> OrgParser m (F Inlines))
-> F Inlines -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
Bool
parens <- BerkeleyCitationList -> Bool
berkeleyCiteParens (BerkeleyCitationList -> Bool)
-> F BerkeleyCitationList -> Future OrgParserState Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> F BerkeleyCitationList
bcl
Maybe Inlines
prefix <- BerkeleyCitationList -> Maybe Inlines
berkeleyCiteCommonPrefix (BerkeleyCitationList -> Maybe Inlines)
-> F BerkeleyCitationList -> Future OrgParserState (Maybe Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> F BerkeleyCitationList
bcl
Maybe Inlines
suffix <- BerkeleyCitationList -> Maybe Inlines
berkeleyCiteCommonSuffix (BerkeleyCitationList -> Maybe Inlines)
-> F BerkeleyCitationList -> Future OrgParserState (Maybe Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> F BerkeleyCitationList
bcl
[Citation]
citationList <- BerkeleyCitationList -> [Citation]
berkeleyCiteCitations (BerkeleyCitationList -> [Citation])
-> F BerkeleyCitationList -> F [Citation]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> F BerkeleyCitationList
bcl
Inlines -> F Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines) -> Inlines -> F Inlines
forall a b. (a -> b) -> a -> b
$
if Bool
parens
then [Citation] -> Inlines
toCite
([Citation] -> Inlines)
-> ([Citation] -> [Citation]) -> [Citation] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Citation] -> [Citation])
-> (Inlines -> [Citation] -> [Citation])
-> Maybe Inlines
-> [Citation]
-> [Citation]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [Citation] -> [Citation]
forall a. a -> a
id ((Citation -> Citation) -> [Citation] -> [Citation]
forall a. (a -> a) -> [a] -> [a]
alterFirst ((Citation -> Citation) -> [Citation] -> [Citation])
-> (Inlines -> Citation -> Citation)
-> Inlines
-> [Citation]
-> [Citation]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Citation -> Citation
prependPrefix) Maybe Inlines
prefix
([Citation] -> [Citation])
-> ([Citation] -> [Citation]) -> [Citation] -> [Citation]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Citation] -> [Citation])
-> (Inlines -> [Citation] -> [Citation])
-> Maybe Inlines
-> [Citation]
-> [Citation]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [Citation] -> [Citation]
forall a. a -> a
id ((Citation -> Citation) -> [Citation] -> [Citation]
forall a. (a -> a) -> [a] -> [a]
alterLast ((Citation -> Citation) -> [Citation] -> [Citation])
-> (Inlines -> Citation -> Citation)
-> Inlines
-> [Citation]
-> [Citation]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Citation -> Citation
appendSuffix) Maybe Inlines
suffix
([Citation] -> Inlines) -> [Citation] -> Inlines
forall a b. (a -> b) -> a -> b
$ [Citation]
citationList
else Inlines -> (Inlines -> Inlines) -> Maybe Inlines -> Inlines
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Inlines
forall a. Monoid a => a
mempty (Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
" ") Maybe Inlines
prefix
Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> [Citation] -> Inlines
toListOfCites ((Citation -> Citation) -> [Citation] -> [Citation]
forall a b. (a -> b) -> [a] -> [b]
map Citation -> Citation
toInTextMode [Citation]
citationList)
Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines -> (Inlines -> Inlines) -> Maybe Inlines -> Inlines
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Inlines
forall a. Monoid a => a
mempty (Inlines
", " Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<>) Maybe Inlines
suffix
where
toCite :: [Citation] -> Inlines
toCite :: [Citation] -> Inlines
toCite [Citation]
cs = [Citation] -> Inlines -> Inlines
B.cite [Citation]
cs Inlines
forall a. Monoid a => a
mempty
toListOfCites :: [Citation] -> Inlines
toListOfCites :: [Citation] -> Inlines
toListOfCites = [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ([Citation] -> [Inlines]) -> [Citation] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> [Inlines] -> [Inlines]
forall a. a -> [a] -> [a]
intersperse Inlines
", " ([Inlines] -> [Inlines])
-> ([Citation] -> [Inlines]) -> [Citation] -> [Inlines]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Citation -> Inlines) -> [Citation] -> [Inlines]
forall a b. (a -> b) -> [a] -> [b]
map (\Citation
c -> [Citation] -> Inlines -> Inlines
B.cite [Citation
c] Inlines
forall a. Monoid a => a
mempty)
toInTextMode :: Citation -> Citation
toInTextMode :: Citation -> Citation
toInTextMode Citation
c = Citation
c { citationMode :: CitationMode
citationMode = CitationMode
AuthorInText }
alterFirst, alterLast :: (a -> a) -> [a] -> [a]
alterFirst :: (a -> a) -> [a] -> [a]
alterFirst a -> a
_ [] = []
alterFirst a -> a
f (a
c:[a]
cs) = a -> a
f a
c a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
cs
alterLast :: (a -> a) -> [a] -> [a]
alterLast a -> a
f = [a] -> [a]
forall a. [a] -> [a]
reverse ([a] -> [a]) -> ([a] -> [a]) -> [a] -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> a) -> [a] -> [a]
forall a. (a -> a) -> [a] -> [a]
alterFirst a -> a
f ([a] -> [a]) -> ([a] -> [a]) -> [a] -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> [a]
forall a. [a] -> [a]
reverse
prependPrefix, appendSuffix :: Inlines -> Citation -> Citation
prependPrefix :: Inlines -> Citation -> Citation
prependPrefix Inlines
pre Citation
c = Citation
c { citationPrefix :: [Inline]
citationPrefix = Inlines -> [Inline]
forall a. Many a -> [a]
B.toList Inlines
pre [Inline] -> [Inline] -> [Inline]
forall a. Semigroup a => a -> a -> a
<> Citation -> [Inline]
citationPrefix Citation
c }
appendSuffix :: Inlines -> Citation -> Citation
appendSuffix Inlines
suf Citation
c = Citation
c { citationSuffix :: [Inline]
citationSuffix = Citation -> [Inline]
citationSuffix Citation
c [Inline] -> [Inline] -> [Inline]
forall a. Semigroup a => a -> a -> a
<> Inlines -> [Inline]
forall a. Many a -> [a]
B.toList Inlines
suf }
data BerkeleyCitationList = BerkeleyCitationList
{ BerkeleyCitationList -> Bool
berkeleyCiteParens :: Bool
, BerkeleyCitationList -> Maybe Inlines
berkeleyCiteCommonPrefix :: Maybe Inlines
, BerkeleyCitationList -> Maybe Inlines
berkeleyCiteCommonSuffix :: Maybe Inlines
, BerkeleyCitationList -> [Citation]
berkeleyCiteCitations :: [Citation]
}
berkeleyCitationList :: PandocMonad m => OrgParser m (F BerkeleyCitationList)
berkeleyCitationList :: OrgParser m (F BerkeleyCitationList)
berkeleyCitationList = OrgParser m (F BerkeleyCitationList)
-> OrgParser m (F BerkeleyCitationList)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (F BerkeleyCitationList)
-> OrgParser m (F BerkeleyCitationList))
-> OrgParser m (F BerkeleyCitationList)
-> OrgParser m (F BerkeleyCitationList)
forall a b. (a -> b) -> a -> b
$ do
Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'['
Bool
parens <- [ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [ Bool
False Bool
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *). PandocMonad m => OrgParser m ()
berkeleyBareTag, Bool
True Bool
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *). PandocMonad m => OrgParser m ()
berkeleyParensTag ]
Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
':'
ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
skipSpaces
Maybe (F Inlines)
commonPrefix <- ParsecT Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (Maybe (F Inlines))
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (ParsecT Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines))
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
forall a b. (a -> b) -> a -> b
$ ParsecT Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
citationListPart ParsecT Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
';')
F [Citation]
citations <- OrgParser m (F [Citation])
forall (m :: * -> *). PandocMonad m => OrgParser m (F [Citation])
citeList
Maybe (F Inlines)
commonSuffix <- ParsecT Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (Maybe (F Inlines))
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (ParsecT Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
citationListPart)
Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
']'
F BerkeleyCitationList -> OrgParser m (F BerkeleyCitationList)
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
-> Maybe Inlines
-> Maybe Inlines
-> [Citation]
-> BerkeleyCitationList
BerkeleyCitationList Bool
parens
(Maybe Inlines
-> Maybe Inlines -> [Citation] -> BerkeleyCitationList)
-> Future OrgParserState (Maybe Inlines)
-> Future
OrgParserState
(Maybe Inlines -> [Citation] -> BerkeleyCitationList)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (F Inlines) -> Future OrgParserState (Maybe Inlines)
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence Maybe (F Inlines)
commonPrefix
Future
OrgParserState
(Maybe Inlines -> [Citation] -> BerkeleyCitationList)
-> Future OrgParserState (Maybe Inlines)
-> Future OrgParserState ([Citation] -> BerkeleyCitationList)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe (F Inlines) -> Future OrgParserState (Maybe Inlines)
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence Maybe (F Inlines)
commonSuffix
Future OrgParserState ([Citation] -> BerkeleyCitationList)
-> F [Citation] -> F BerkeleyCitationList
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> F [Citation]
citations)
where
citationListPart :: PandocMonad m => OrgParser m (F Inlines)
citationListPart :: OrgParser m (F Inlines)
citationListPart = ([F Inlines] -> F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
-> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF (F Inlines -> F Inlines)
-> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat) (ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
-> OrgParser m (F Inlines))
-> (OrgParser m (F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines])
-> OrgParser m (F Inlines)
-> OrgParser m (F Inlines)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines])
-> (OrgParser m (F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines])
-> OrgParser m (F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OrgParser m (F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (OrgParser m (F Inlines) -> OrgParser m (F Inlines))
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
ParserT Text OrgParserState (ReaderT OrgParserLocal m) (Bool, Text)
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall b s (m :: * -> *) a st.
(Show b, Stream s m a) =>
ParserT s st m b -> ParserT s st m ()
notFollowedBy' ParserT Text OrgParserState (ReaderT OrgParserLocal m) (Bool, Text)
forall s (m :: * -> *) st.
(Stream s m Char, HasLastStrPosition st) =>
ParserT s st m (Bool, Text)
citeKey
ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ([Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
oneOf [Char]
";]")
OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inline
berkeleyBareTag :: PandocMonad m => OrgParser m ()
berkeleyBareTag :: OrgParser m ()
berkeleyBareTag = OrgParser m () -> OrgParser m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m () -> OrgParser m ())
-> OrgParser m () -> OrgParser m ()
forall a b. (a -> b) -> a -> b
$ OrgParser m () -> OrgParser m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void OrgParser m ()
forall (m :: * -> *). PandocMonad m => OrgParser m ()
berkeleyBareTag'
berkeleyParensTag :: PandocMonad m => OrgParser m ()
berkeleyParensTag :: OrgParser m ()
berkeleyParensTag = OrgParser m () -> OrgParser m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m () -> OrgParser m ())
-> (ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [()]
-> OrgParser m ())
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [()]
-> OrgParser m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [()]
-> OrgParser m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [()]
-> OrgParser m ())
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [()]
-> OrgParser m ()
forall a b. (a -> b) -> a -> b
$ Char
-> Char
-> OrgParser m ()
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [()]
forall (m :: * -> *) a.
PandocMonad m =>
Char -> Char -> OrgParser m a -> OrgParser m [a]
enclosedByPair1 Char
'(' Char
')' OrgParser m ()
forall (m :: * -> *). PandocMonad m => OrgParser m ()
berkeleyBareTag'
berkeleyBareTag' :: PandocMonad m => OrgParser m ()
berkeleyBareTag' :: OrgParser m ()
berkeleyBareTag' = OrgParser m () -> OrgParser m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m () -> OrgParser m ())
-> OrgParser m () -> OrgParser m ()
forall a b. (a -> b) -> a -> b
$ ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> OrgParser m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void ([Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"cite")
berkeleyTextualCite :: PandocMonad m => OrgParser m (F [Citation])
berkeleyTextualCite :: OrgParser m (F [Citation])
berkeleyTextualCite = OrgParser m (F [Citation]) -> OrgParser m (F [Citation])
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (F [Citation]) -> OrgParser m (F [Citation]))
-> OrgParser m (F [Citation]) -> OrgParser m (F [Citation])
forall a b. (a -> b) -> a -> b
$ do
(Bool
suppressAuthor, Text
key) <- ParserT Text OrgParserState (ReaderT OrgParserLocal m) (Bool, Text)
forall s (m :: * -> *) st.
(Stream s m Char, HasLastStrPosition st) =>
ParserT s st m (Bool, Text)
citeKey
[Citation] -> OrgParser m (F [Citation])
forall (m :: * -> *) a s. Monad m => a -> m (Future s a)
returnF ([Citation] -> OrgParser m (F [Citation]))
-> (Citation -> [Citation])
-> Citation
-> OrgParser m (F [Citation])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Citation -> [Citation]
forall (m :: * -> *) a. Monad m => a -> m a
return (Citation -> OrgParser m (F [Citation]))
-> Citation -> OrgParser m (F [Citation])
forall a b. (a -> b) -> a -> b
$ Citation :: Text
-> [Inline] -> [Inline] -> CitationMode -> Int -> Int -> Citation
Citation
{ citationId :: Text
citationId = Text
key
, citationPrefix :: [Inline]
citationPrefix = [Inline]
forall a. Monoid a => a
mempty
, citationSuffix :: [Inline]
citationSuffix = [Inline]
forall a. Monoid a => a
mempty
, citationMode :: CitationMode
citationMode = if Bool
suppressAuthor then CitationMode
SuppressAuthor else CitationMode
AuthorInText
, citationNoteNum :: Int
citationNoteNum = Int
0
, citationHash :: Int
citationHash = Int
0
}
linkLikeOrgRefCite :: PandocMonad m => OrgParser m (F Citation)
linkLikeOrgRefCite :: OrgParser m (Future OrgParserState Citation)
linkLikeOrgRefCite = OrgParser m (Future OrgParserState Citation)
-> OrgParser m (Future OrgParserState Citation)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (Future OrgParserState Citation)
-> OrgParser m (Future OrgParserState Citation))
-> OrgParser m (Future OrgParserState Citation)
-> OrgParser m (Future OrgParserState Citation)
forall a b. (a -> b) -> a -> b
$ do
[Char]
_ <- [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"[["
CitationMode
mode <- OrgParser m CitationMode
forall (m :: * -> *). PandocMonad m => OrgParser m CitationMode
orgRefCiteMode
Text
key <- OrgParser m Text
forall (m :: * -> *). PandocMonad m => OrgParser m Text
orgRefCiteKey
[Char]
_ <- [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"]["
F Inlines
pre <- F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF (F Inlines -> F Inlines)
-> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
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 ParsecT Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inline (ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char])
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall a b. (a -> b) -> a -> b
$ [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"::")
Bool
spc <- Bool
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Bool
False (Bool
True Bool
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
spaceChar)
F Inlines
suf <- F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF (F Inlines -> F Inlines)
-> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
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 ParsecT Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inline (ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char])
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall a b. (a -> b) -> a -> b
$ [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"]]")
Future OrgParserState Citation
-> OrgParser m (Future OrgParserState Citation)
forall (m :: * -> *) a. Monad m => a -> m a
return (Future OrgParserState Citation
-> OrgParser m (Future OrgParserState Citation))
-> Future OrgParserState Citation
-> OrgParser m (Future OrgParserState Citation)
forall a b. (a -> b) -> a -> b
$ do
Inlines
pre' <- F Inlines
pre
Inlines
suf' <- F Inlines
suf
Citation -> Future OrgParserState Citation
forall (m :: * -> *) a. Monad m => a -> m a
return Citation :: Text
-> [Inline] -> [Inline] -> CitationMode -> Int -> Int -> Citation
Citation
{ citationId :: Text
citationId = Text
key
, citationPrefix :: [Inline]
citationPrefix = Inlines -> [Inline]
forall a. Many a -> [a]
B.toList Inlines
pre'
, citationSuffix :: [Inline]
citationSuffix = Inlines -> [Inline]
forall a. Many a -> [a]
B.toList (if Bool
spc then Inlines
B.space Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
suf' else Inlines
suf')
, citationMode :: CitationMode
citationMode = CitationMode
mode
, citationNoteNum :: Int
citationNoteNum = Int
0
, citationHash :: Int
citationHash = Int
0
}
orgRefCiteKey :: PandocMonad m => OrgParser m Text
orgRefCiteKey :: OrgParser m Text
orgRefCiteKey =
let citeKeySpecialChars :: [Char]
citeKeySpecialChars = [Char]
"-_:\\./," :: String
isCiteKeySpecialChar :: Char -> Bool
isCiteKeySpecialChar Char
c = Char
c Char -> [Char] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Char]
citeKeySpecialChars
isCiteKeyChar :: Char -> Bool
isCiteKeyChar Char
c = Char -> Bool
isAlphaNum Char
c Bool -> Bool -> Bool
|| Char -> Bool
isCiteKeySpecialChar Char
c
endOfCitation :: ParsecT Text u (ReaderT OrgParserLocal m) Char
endOfCitation = ParsecT Text u (ReaderT OrgParserLocal m) Char
-> ParsecT Text u (ReaderT OrgParserLocal m) Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text u (ReaderT OrgParserLocal m) Char
-> ParsecT Text u (ReaderT OrgParserLocal m) Char)
-> ParsecT Text u (ReaderT OrgParserLocal m) Char
-> ParsecT Text u (ReaderT OrgParserLocal m) Char
forall a b. (a -> b) -> a -> b
$ do
ParsecT Text u (ReaderT OrgParserLocal m) Char
-> ParsecT Text u (ReaderT OrgParserLocal m) [Char]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (ParsecT Text u (ReaderT OrgParserLocal m) Char
-> ParsecT Text u (ReaderT OrgParserLocal m) [Char])
-> ParsecT Text u (ReaderT OrgParserLocal m) Char
-> ParsecT Text u (ReaderT OrgParserLocal m) [Char]
forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> ParsecT Text u (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
satisfy Char -> Bool
isCiteKeySpecialChar
(Char -> Bool) -> ParsecT Text u (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
satisfy ((Char -> Bool) -> ParsecT Text u (ReaderT OrgParserLocal m) Char)
-> (Char -> Bool) -> ParsecT Text u (ReaderT OrgParserLocal m) Char
forall a b. (a -> b) -> a -> b
$ Bool -> Bool
not (Bool -> Bool) -> (Char -> Bool) -> Char -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Bool
isCiteKeyChar
in OrgParser m Text -> OrgParser m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m Text -> OrgParser m Text)
-> OrgParser m Text -> OrgParser m Text
forall a b. (a -> b) -> a -> b
$ (Char -> Bool)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
satisfy Char -> Bool
isCiteKeyChar ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> OrgParser m Text
forall end s (m :: * -> *) t st.
(Show end, Stream s m t) =>
ParserT s st m Char -> ParserT s st m end -> ParserT s st m Text
`many1TillChar` ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall u. ParsecT Text u (ReaderT OrgParserLocal m) Char
endOfCitation
orgRefCiteMode :: PandocMonad m => OrgParser m CitationMode
orgRefCiteMode :: OrgParser m CitationMode
orgRefCiteMode =
[OrgParser m CitationMode] -> OrgParser m CitationMode
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice ([OrgParser m CitationMode] -> OrgParser m CitationMode)
-> [OrgParser m CitationMode] -> OrgParser m CitationMode
forall a b. (a -> b) -> a -> b
$ (([Char], CitationMode) -> OrgParser m CitationMode)
-> [([Char], CitationMode)] -> [OrgParser m CitationMode]
forall a b. (a -> b) -> [a] -> [b]
map (\([Char]
s, CitationMode
mode) -> CitationMode
mode CitationMode
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> OrgParser m CitationMode
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ([Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
s ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
':'))
[ ([Char]
"cite", CitationMode
AuthorInText)
, ([Char]
"citep", CitationMode
NormalCitation)
, ([Char]
"citep*", CitationMode
NormalCitation)
, ([Char]
"citet", CitationMode
AuthorInText)
, ([Char]
"citet*", CitationMode
AuthorInText)
, ([Char]
"citeyear", CitationMode
SuppressAuthor)
]
citeList :: PandocMonad m => OrgParser m (F [Citation])
citeList :: OrgParser m (F [Citation])
citeList = [Future OrgParserState Citation] -> F [Citation]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence ([Future OrgParserState Citation] -> F [Citation])
-> ParsecT
Text
OrgParserState
(ReaderT OrgParserLocal m)
[Future OrgParserState Citation]
-> OrgParser m (F [Citation])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
Text
OrgParserState
(ReaderT OrgParserLocal m)
(Future OrgParserState Citation)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT
Text
OrgParserState
(ReaderT OrgParserLocal m)
[Future OrgParserState Citation]
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]
sepEndBy1 ParsecT
Text
OrgParserState
(ReaderT OrgParserLocal m)
(Future OrgParserState Citation)
forall (m :: * -> *).
PandocMonad m =>
OrgParser m (Future OrgParserState Citation)
citation (ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ())
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
';' ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
skipSpaces)
citation :: PandocMonad m => OrgParser m (F Citation)
citation :: OrgParser m (Future OrgParserState Citation)
citation = OrgParser m (Future OrgParserState Citation)
-> OrgParser m (Future OrgParserState Citation)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (Future OrgParserState Citation)
-> OrgParser m (Future OrgParserState Citation))
-> OrgParser m (Future OrgParserState Citation)
-> OrgParser m (Future OrgParserState Citation)
forall a b. (a -> b) -> a -> b
$ do
F Inlines
pref <- ParsecT Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
prefix
(Bool
suppress_author, Text
key) <- ParserT Text OrgParserState (ReaderT OrgParserLocal m) (Bool, Text)
forall s (m :: * -> *) st.
(Stream s m Char, HasLastStrPosition st) =>
ParserT s st m (Bool, Text)
citeKey
F Inlines
suff <- ParsecT Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
suffix
Future OrgParserState Citation
-> OrgParser m (Future OrgParserState Citation)
forall (m :: * -> *) a. Monad m => a -> m a
return (Future OrgParserState Citation
-> OrgParser m (Future OrgParserState Citation))
-> Future OrgParserState Citation
-> OrgParser m (Future OrgParserState Citation)
forall a b. (a -> b) -> a -> b
$ do
Inlines
x <- F Inlines
pref
Inlines
y <- F Inlines
suff
Citation -> Future OrgParserState Citation
forall (m :: * -> *) a. Monad m => a -> m a
return Citation :: Text
-> [Inline] -> [Inline] -> CitationMode -> Int -> Int -> Citation
Citation
{ citationId :: Text
citationId = Text
key
, citationPrefix :: [Inline]
citationPrefix = Inlines -> [Inline]
forall a. Many a -> [a]
B.toList Inlines
x
, citationSuffix :: [Inline]
citationSuffix = Inlines -> [Inline]
forall a. Many a -> [a]
B.toList Inlines
y
, citationMode :: CitationMode
citationMode = if Bool
suppress_author
then CitationMode
SuppressAuthor
else CitationMode
NormalCitation
, citationNoteNum :: Int
citationNoteNum = Int
0
, citationHash :: Int
citationHash = Int
0
}
where
prefix :: ParsecT Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
prefix = F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF (F Inlines -> F Inlines)
-> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
ParsecT Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
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 ParsecT Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inline (Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
']' ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Char
']' Char
-> ParserT
Text OrgParserState (ReaderT OrgParserLocal m) (Bool, Text)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParserT Text OrgParserState (ReaderT OrgParserLocal m) (Bool, Text)
-> ParserT
Text OrgParserState (ReaderT OrgParserLocal m) (Bool, Text)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead ParserT Text OrgParserState (ReaderT OrgParserLocal m) (Bool, Text)
forall s (m :: * -> *) st.
(Stream s m Char, HasLastStrPosition st) =>
ParserT s st m (Bool, Text)
citeKey))
suffix :: ParsecT Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
suffix = ParsecT Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines))
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
Bool
hasSpace <- Bool
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Bool
False (ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
nonspaceChar ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True)
ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
skipSpaces
F Inlines
rest <- F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF (F Inlines -> F Inlines)
-> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
ParsecT Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ([Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
oneOf [Char]
";]") ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inline)
F Inlines
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
forall (m :: * -> *) a. Monad m => a -> m a
return (F Inlines
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines))
-> F Inlines
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
forall a b. (a -> b) -> a -> b
$ if Bool
hasSpace
then (Inlines
B.space Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<>) (Inlines -> Inlines) -> F Inlines -> F Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> F Inlines
rest
else F Inlines
rest
footnote :: PandocMonad m => OrgParser m (F Inlines)
= OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (F Inlines) -> OrgParser m (F Inlines))
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
F Inlines
note <- OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inlineNote OrgParser m (F Inlines)
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
referencedNote
Bool
withNote <- (ExportSettings -> Bool) -> OrgParser m Bool
forall (m :: * -> *) a.
Monad m =>
(ExportSettings -> a) -> OrgParser m a
getExportSetting ExportSettings -> Bool
exportWithFootnotes
F Inlines -> OrgParser m (F Inlines)
forall (m :: * -> *) a. Monad m => a -> m a
return (F Inlines -> OrgParser m (F Inlines))
-> F Inlines -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ if Bool
withNote then F Inlines
note else F Inlines
forall a. Monoid a => a
mempty
inlineNote :: PandocMonad m => OrgParser m (F Inlines)
inlineNote :: OrgParser m (F Inlines)
inlineNote = OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (F Inlines) -> OrgParser m (F Inlines))
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
[Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"[fn:"
Text
ref <- ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
manyChar ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
alphaNum
Char -> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
':'
Future OrgParserState Blocks
note <- (Inlines -> Blocks) -> F Inlines -> Future OrgParserState Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Blocks
B.para (F Inlines -> Future OrgParserState Blocks)
-> ([F Inlines] -> F Inlines)
-> [F Inlines]
-> Future OrgParserState Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF (F Inlines -> F Inlines)
-> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> Future OrgParserState Blocks)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
-> ParsecT
Text
OrgParserState
(ReaderT OrgParserLocal m)
(Future OrgParserState Blocks)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OrgParser m (F Inlines)
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParserT s st m a -> ParserT s st m end -> ParserT s st m [a]
many1Till OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inline (Char -> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
']')
Bool
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Text -> Bool
T.null Text
ref) (ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ())
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall a b. (a -> b) -> a -> b
$
OrgNoteRecord
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *).
PandocMonad m =>
OrgNoteRecord -> OrgParser m ()
addToNotesTable (Text
"fn:" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
ref, Future OrgParserState Blocks
note)
F Inlines -> OrgParser m (F Inlines)
forall (m :: * -> *) a. Monad m => a -> m a
return (F Inlines -> OrgParser m (F Inlines))
-> F Inlines -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ Blocks -> Inlines
B.note (Blocks -> Inlines) -> Future OrgParserState Blocks -> F Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Future OrgParserState Blocks
note
referencedNote :: PandocMonad m => OrgParser m (F Inlines)
referencedNote :: OrgParser m (F Inlines)
referencedNote = OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (F Inlines) -> OrgParser m (F Inlines))
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
Text
ref <- OrgParser m Text
forall (m :: * -> *). Monad m => OrgParser m Text
noteMarker
F Inlines -> OrgParser m (F Inlines)
forall (m :: * -> *) a. Monad m => a -> m a
return (F Inlines -> OrgParser m (F Inlines))
-> F Inlines -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
OrgNoteTable
notes <- (OrgParserState -> OrgNoteTable)
-> Future OrgParserState OrgNoteTable
forall s a. (s -> a) -> Future s a
asksF OrgParserState -> OrgNoteTable
orgStateNotes'
case Text -> OrgNoteTable -> Maybe (Future OrgParserState Blocks)
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
ref OrgNoteTable
notes of
Maybe (Future OrgParserState Blocks)
Nothing -> Inlines -> F Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines) -> (Text -> Inlines) -> Text -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines
B.str (Text -> F Inlines) -> Text -> F Inlines
forall a b. (a -> b) -> a -> b
$ Text
"[" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
ref Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"]"
Just Future OrgParserState Blocks
contents -> do
OrgParserState
st <- Future OrgParserState OrgParserState
forall s. Future s s
askF
let contents' :: Blocks
contents' = Future OrgParserState Blocks -> OrgParserState -> Blocks
forall s a. Future s a -> s -> a
runF Future OrgParserState Blocks
contents OrgParserState
st{ orgStateNotes' :: OrgNoteTable
orgStateNotes' = [] }
Inlines -> F Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines) -> Inlines -> F Inlines
forall a b. (a -> b) -> a -> b
$ Blocks -> Inlines
B.note Blocks
contents'
linkOrImage :: PandocMonad m => OrgParser m (F Inlines)
linkOrImage :: OrgParser m (F Inlines)
linkOrImage = OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
explicitOrImageLink
OrgParser m (F Inlines)
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
selflinkOrImage
OrgParser m (F Inlines)
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
angleLink
OrgParser m (F Inlines)
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
plainLink
OrgParser m (F Inlines) -> [Char] -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"link or image"
explicitOrImageLink :: PandocMonad m => OrgParser m (F Inlines)
explicitOrImageLink :: OrgParser m (F Inlines)
explicitOrImageLink = OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (F Inlines) -> OrgParser m (F Inlines))
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'['
F Text
srcF <- Text -> OrgParser m (F Text)
forall (m :: * -> *). Text -> OrgParser m (F Text)
applyCustomLinkFormat (Text -> OrgParser m (F Text))
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
-> OrgParser m (F Text)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall (m :: * -> *). PandocMonad m => OrgParser m Text
possiblyEmptyLinkTarget
Text
descr <- ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall (m :: * -> *) b a.
(PandocMonad m, Show b) =>
OrgParser m a -> OrgParser m b -> OrgParser m Text
enclosedRaw (Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'[') (Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
']')
F Inlines
titleF <- OrgParser m (F Inlines) -> Text -> OrgParser m (F Inlines)
forall (m :: * -> *) a.
Monad m =>
OrgParser m a -> Text -> OrgParser m a
parseFromString ([F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
-> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OrgParser m (F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inline) Text
descr
Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
']'
F Inlines -> OrgParser m (F Inlines)
forall (m :: * -> *) a. Monad m => a -> m a
return (F Inlines -> OrgParser m (F Inlines))
-> F Inlines -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
Text
src <- F Text
srcF
Inlines
title <- F Inlines
titleF
case Text -> Maybe Text
cleanLinkText Text
descr of
Just Text
imgSrc | Text -> Bool
isImageFilename Text
imgSrc ->
Inlines -> F Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines)
-> (Inlines -> Inlines) -> Inlines -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Inlines -> Inlines
B.link Text
src Text
"" (Inlines -> F Inlines) -> Inlines -> F Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines -> Inlines
B.image Text
imgSrc Text
forall a. Monoid a => a
mempty Inlines
forall a. Monoid a => a
mempty
Maybe Text
_ ->
Text -> Inlines -> F Inlines
linkToInlinesF Text
src Inlines
title
selflinkOrImage :: PandocMonad m => OrgParser m (F Inlines)
selflinkOrImage :: OrgParser m (F Inlines)
selflinkOrImage = OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (F Inlines) -> OrgParser m (F Inlines))
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
Text
target <- Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'[' ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall (m :: * -> *). PandocMonad m => OrgParser m Text
linkTarget ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
']'
case Text -> Maybe Text
cleanLinkText Text
target of
Maybe Text
Nothing -> case Text -> Maybe (Char, Text)
T.uncons Text
target of
Just (Char
'#', Text
_) -> Inlines -> OrgParser m (F Inlines)
forall (m :: * -> *) a s. Monad m => a -> m (Future s a)
returnF (Inlines -> OrgParser m (F Inlines))
-> Inlines -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines -> Inlines
B.link Text
target Text
"" (Text -> Inlines
B.str Text
target)
Maybe (Char, Text)
_ -> F Inlines -> OrgParser m (F Inlines)
forall (m :: * -> *) a. Monad m => a -> m a
return (F Inlines -> OrgParser m (F Inlines))
-> F Inlines -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ Text -> Inlines -> F Inlines
internalLink Text
target (Text -> Inlines
B.str Text
target)
Just Text
nonDocTgt -> if Text -> Bool
isImageFilename Text
nonDocTgt
then Inlines -> OrgParser m (F Inlines)
forall (m :: * -> *) a s. Monad m => a -> m (Future s a)
returnF (Inlines -> OrgParser m (F Inlines))
-> Inlines -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines -> Inlines
B.image Text
nonDocTgt Text
"" Inlines
""
else Inlines -> OrgParser m (F Inlines)
forall (m :: * -> *) a s. Monad m => a -> m (Future s a)
returnF (Inlines -> OrgParser m (F Inlines))
-> Inlines -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines -> Inlines
B.link Text
nonDocTgt Text
"" (Text -> Inlines
B.str Text
target)
plainLink :: PandocMonad m => OrgParser m (F Inlines)
plainLink :: OrgParser m (F Inlines)
plainLink = OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (F Inlines) -> OrgParser m (F Inlines))
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
(Text
orig, Text
src) <- ParserT Text OrgParserState (ReaderT OrgParserLocal m) (Text, Text)
forall s (m :: * -> *) st.
Stream s m Char =>
ParserT s st m (Text, Text)
uri
Inlines -> OrgParser m (F Inlines)
forall (m :: * -> *) a s. Monad m => a -> m (Future s a)
returnF (Inlines -> OrgParser m (F Inlines))
-> Inlines -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines -> Inlines
B.link Text
src Text
"" (Text -> Inlines
B.str Text
orig)
angleLink :: PandocMonad m => OrgParser m (F Inlines)
angleLink :: OrgParser m (F Inlines)
angleLink = OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (F Inlines) -> OrgParser m (F Inlines))
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'<'
F Inlines
link <- OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
plainLink
Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'>'
F Inlines -> OrgParser m (F Inlines)
forall (m :: * -> *) a. Monad m => a -> m a
return F Inlines
link
linkTarget :: PandocMonad m => OrgParser m Text
linkTarget :: OrgParser m Text
linkTarget = [Char] -> Text
T.pack ([Char] -> Text)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> OrgParser m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Char
-> Char
-> OrgParser m Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall (m :: * -> *) a.
PandocMonad m =>
Char -> Char -> OrgParser m a -> OrgParser m [a]
enclosedByPair1 Char
'[' Char
']' ([Char] -> OrgParser m Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
noneOf [Char]
"\n\r[]")
possiblyEmptyLinkTarget :: PandocMonad m => OrgParser m Text
possiblyEmptyLinkTarget :: OrgParser m Text
possiblyEmptyLinkTarget = OrgParser m Text -> OrgParser m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try OrgParser m Text
forall (m :: * -> *). PandocMonad m => OrgParser m Text
linkTarget OrgParser m Text -> OrgParser m Text -> OrgParser m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Text
"" Text
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> OrgParser m Text
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"[]")
applyCustomLinkFormat :: Text -> OrgParser m (F Text)
applyCustomLinkFormat :: Text -> OrgParser m (F Text)
applyCustomLinkFormat Text
link = do
let (Text
linkType, Text
rest) = (Char -> Bool) -> Text -> (Text, Text)
T.break (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
':') Text
link
F Text -> OrgParser m (F Text)
forall (m :: * -> *) a. Monad m => a -> m a
return (F Text -> OrgParser m (F Text)) -> F Text -> OrgParser m (F Text)
forall a b. (a -> b) -> a -> b
$ do
Maybe (Text -> Text)
formatter <- Text -> Map Text (Text -> Text) -> Maybe (Text -> Text)
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Text
linkType (Map Text (Text -> Text) -> Maybe (Text -> Text))
-> Future OrgParserState (Map Text (Text -> Text))
-> Future OrgParserState (Maybe (Text -> Text))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (OrgParserState -> Map Text (Text -> Text))
-> Future OrgParserState (Map Text (Text -> Text))
forall s a. (s -> a) -> Future s a
asksF OrgParserState -> Map Text (Text -> Text)
orgStateLinkFormatters
Text -> F Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> F Text) -> Text -> F Text
forall a b. (a -> b) -> a -> b
$ Text -> ((Text -> Text) -> Text) -> Maybe (Text -> Text) -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
link ((Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Int -> Text -> Text
T.drop Int
1 Text
rest) Maybe (Text -> Text)
formatter
linkToInlinesF :: Text -> Inlines -> F Inlines
linkToInlinesF :: Text -> Inlines -> F Inlines
linkToInlinesF Text
linkStr =
case Text -> Maybe (Char, Text)
T.uncons Text
linkStr of
Maybe (Char, Text)
Nothing -> Inlines -> F Inlines
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Inlines -> F Inlines)
-> (Inlines -> Inlines) -> Inlines -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Inlines -> Inlines
B.link Text
forall a. Monoid a => a
mempty Text
""
Just (Char
'#', Text
_) -> Inlines -> F Inlines
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Inlines -> F Inlines)
-> (Inlines -> Inlines) -> Inlines -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Inlines -> Inlines
B.link Text
linkStr Text
""
Maybe (Char, Text)
_ -> case Text -> Maybe Text
cleanLinkText Text
linkStr of
Just Text
extTgt -> Inlines -> F Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines)
-> (Inlines -> Inlines) -> Inlines -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Inlines -> Inlines
B.link Text
extTgt Text
""
Maybe Text
Nothing -> Text -> Inlines -> F Inlines
internalLink Text
linkStr
internalLink :: Text -> Inlines -> F Inlines
internalLink :: Text -> Inlines -> F Inlines
internalLink Text
link Inlines
title = do
[Text]
ids <- (OrgParserState -> [Text]) -> Future OrgParserState [Text]
forall s a. (s -> a) -> Future s a
asksF OrgParserState -> [Text]
orgStateAnchorIds
if Text
link Text -> [Text] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Text]
ids
then Inlines -> F Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines) -> Inlines -> F Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines -> Inlines
B.link (Text
"#" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
link) Text
"" Inlines
title
else let attr' :: (Text, [Text], [(Text, Text)])
attr' = (Text
"", [Text
"spurious-link"] , [(Text
"target", Text
link)])
in Inlines -> F Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines) -> Inlines -> F Inlines
forall a b. (a -> b) -> a -> b
$ (Text, [Text], [(Text, Text)]) -> Inlines -> Inlines
B.spanWith (Text, [Text], [(Text, Text)])
attr' (Inlines -> Inlines
B.emph Inlines
title)
anchor :: PandocMonad m => OrgParser m (F Inlines)
anchor :: OrgParser m (F Inlines)
anchor = OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (F Inlines) -> OrgParser m (F Inlines))
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
Text
anchorId <- ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall u. ParsecT Text u (ReaderT OrgParserLocal m) Text
parseAnchor
Text -> OrgParser m ()
forall (m :: * -> *). PandocMonad m => Text -> OrgParser m ()
recordAnchorId Text
anchorId
Inlines -> OrgParser m (F Inlines)
forall (m :: * -> *) a s. Monad m => a -> m (Future s a)
returnF (Inlines -> OrgParser m (F Inlines))
-> Inlines -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ (Text, [Text], [(Text, Text)]) -> Inlines -> Inlines
B.spanWith (Text -> Text
solidify Text
anchorId, [], []) Inlines
forall a. Monoid a => a
mempty
where
parseAnchor :: ParsecT Text u (ReaderT OrgParserLocal m) Text
parseAnchor = [Char] -> ParsecT Text u (ReaderT OrgParserLocal m) [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"<<"
ParsecT Text u (ReaderT OrgParserLocal m) [Char]
-> ParsecT Text u (ReaderT OrgParserLocal m) Text
-> ParsecT Text u (ReaderT OrgParserLocal m) Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParserT Text u (ReaderT OrgParserLocal m) Char
-> ParsecT Text u (ReaderT OrgParserLocal m) Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
many1Char ([Char] -> ParserT Text u (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
noneOf [Char]
"\t\n\r<>\"' ")
ParsecT Text u (ReaderT OrgParserLocal m) Text
-> ParsecT Text u (ReaderT OrgParserLocal m) [Char]
-> ParsecT Text u (ReaderT OrgParserLocal m) Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* [Char] -> ParsecT Text u (ReaderT OrgParserLocal m) [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
">>"
ParsecT Text u (ReaderT OrgParserLocal m) Text
-> ParsecT Text u (ReaderT OrgParserLocal m) ()
-> ParsecT Text u (ReaderT OrgParserLocal m) Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text u (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
skipSpaces
solidify :: Text -> Text
solidify :: Text -> Text
solidify = (Char -> Char) -> Text -> Text
T.map Char -> Char
replaceSpecialChar
where replaceSpecialChar :: Char -> Char
replaceSpecialChar Char
c
| Char -> Bool
isAlphaNum Char
c = Char
c
| Char
c Char -> [Char] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` ([Char]
"_.-:" :: String) = Char
c
| Bool
otherwise = Char
'-'
inlineCodeBlock :: PandocMonad m => OrgParser m (F Inlines)
inlineCodeBlock :: OrgParser m (F Inlines)
inlineCodeBlock = OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (F Inlines) -> OrgParser m (F Inlines))
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
[Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"src_"
Text
lang <- ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
many1Char ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall (m :: * -> *). Monad m => OrgParser m Char
orgArgWordChar
[(Text, Text)]
opts <- [(Text, Text)]
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [(Text, Text)]
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [(Text, Text)]
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] (ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [(Text, Text)]
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [(Text, Text)])
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [(Text, Text)]
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [(Text, Text)]
forall a b. (a -> b) -> a -> b
$ Char
-> Char
-> OrgParser m (Text, Text)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [(Text, Text)]
forall (m :: * -> *) a.
PandocMonad m =>
Char -> Char -> OrgParser m a -> OrgParser m [a]
enclosedByPair Char
'[' Char
']' OrgParser m (Text, Text)
forall (m :: * -> *). PandocMonad m => OrgParser m (Text, Text)
inlineBlockOption
Text
inlineCode <- [Char] -> Text
T.pack ([Char] -> Text)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Char
-> Char
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall (m :: * -> *) a.
PandocMonad m =>
Char -> Char -> OrgParser m a -> OrgParser m [a]
enclosedByPair1 Char
'{' Char
'}' ([Char]
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
noneOf [Char]
"\n\r")
let attrClasses :: [Text]
attrClasses = [Text -> Text
translateLang Text
lang]
let attrKeyVal :: [(Text, Text)]
attrKeyVal = Text -> [(Text, Text)]
originalLang Text
lang [(Text, Text)] -> [(Text, Text)] -> [(Text, Text)]
forall a. Semigroup a => a -> a -> a
<> [(Text, Text)]
opts
let codeInlineBlck :: Inlines
codeInlineBlck = (Text, [Text], [(Text, Text)]) -> Text -> Inlines
B.codeWith (Text
"", [Text]
attrClasses, [(Text, Text)]
attrKeyVal) Text
inlineCode
Inlines -> OrgParser m (F Inlines)
forall (m :: * -> *) a s. Monad m => a -> m (Future s a)
returnF (Inlines -> OrgParser m (F Inlines))
-> Inlines -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ if [(Text, Text)] -> Bool
exportsCode [(Text, Text)]
opts then Inlines
codeInlineBlck else Inlines
forall a. Monoid a => a
mempty
where
inlineBlockOption :: PandocMonad m => OrgParser m (Text, Text)
inlineBlockOption :: OrgParser m (Text, Text)
inlineBlockOption = OrgParser m (Text, Text) -> OrgParser m (Text, Text)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (Text, Text) -> OrgParser m (Text, Text))
-> OrgParser m (Text, Text) -> OrgParser m (Text, Text)
forall a b. (a -> b) -> a -> b
$ do
Text
argKey <- OrgParser m Text
forall (m :: * -> *). Monad m => OrgParser m Text
orgArgKey
Text
paramValue <- Text -> OrgParser m Text -> OrgParser m Text
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Text
"yes" OrgParser m Text
forall (m :: * -> *). PandocMonad m => OrgParser m Text
orgInlineParamValue
(Text, Text) -> OrgParser m (Text, Text)
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
argKey, Text
paramValue)
orgInlineParamValue :: PandocMonad m => OrgParser m Text
orgInlineParamValue :: OrgParser m Text
orgInlineParamValue = OrgParser m Text -> OrgParser m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m Text -> OrgParser m Text)
-> OrgParser m Text -> OrgParser m Text
forall a b. (a -> b) -> a -> b
$
ParserT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
skipSpaces
ParserT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
':')
ParserT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> OrgParser m Text -> OrgParser m Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> OrgParser m Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
many1Char ([Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
noneOf [Char]
"\t\n\r ]")
OrgParser m Text
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> OrgParser m Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParserT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
skipSpaces
emphasizedText :: PandocMonad m => OrgParser m (F Inlines)
emphasizedText :: OrgParser m (F Inlines)
emphasizedText = do
OrgParserState
state <- ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) OrgParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
Bool -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ())
-> (OrgParserState -> Bool)
-> OrgParserState
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExportSettings -> Bool
exportEmphasizedText (ExportSettings -> Bool)
-> (OrgParserState -> ExportSettings) -> OrgParserState -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OrgParserState -> ExportSettings
orgStateExportSettings (OrgParserState
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ())
-> OrgParserState
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall a b. (a -> b) -> a -> b
$ OrgParserState
state
OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (F Inlines) -> OrgParser m (F Inlines))
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ [OrgParser m (F Inlines)] -> OrgParser m (F Inlines)
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
[ OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
emph
, OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
strong
, OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
strikeout
, OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
underline
]
enclosedByPair :: PandocMonad m
=> Char
-> Char
-> OrgParser m a
-> OrgParser m [a]
enclosedByPair :: Char -> Char -> OrgParser m a -> OrgParser m [a]
enclosedByPair Char
s Char
e OrgParser m a
p = Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
s ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> OrgParser m [a] -> OrgParser m [a]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> OrgParser m a
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> OrgParser m [a]
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 OrgParser m a
p (Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
e)
enclosedByPair1 :: PandocMonad m
=> Char
-> Char
-> OrgParser m a
-> OrgParser m [a]
enclosedByPair1 :: Char -> Char -> OrgParser m a -> OrgParser m [a]
enclosedByPair1 Char
s Char
e OrgParser m a
p = Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
s ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> OrgParser m [a] -> OrgParser m [a]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> OrgParser m a
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> OrgParser m [a]
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParserT s st m a -> ParserT s st m end -> ParserT s st m [a]
many1Till OrgParser m a
p (Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
e)
emph :: PandocMonad m => OrgParser m (F Inlines)
emph :: OrgParser m (F Inlines)
emph = (Inlines -> Inlines) -> F Inlines -> F Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Inlines
B.emph (F Inlines -> F Inlines)
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Char -> OrgParser m (F Inlines)
forall (m :: * -> *).
PandocMonad m =>
Char -> OrgParser m (F Inlines)
emphasisBetween Char
'/'
strong :: PandocMonad m => OrgParser m (F Inlines)
strong :: OrgParser m (F Inlines)
strong = (Inlines -> Inlines) -> F Inlines -> F Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Inlines
B.strong (F Inlines -> F Inlines)
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Char -> OrgParser m (F Inlines)
forall (m :: * -> *).
PandocMonad m =>
Char -> OrgParser m (F Inlines)
emphasisBetween Char
'*'
strikeout :: PandocMonad m => OrgParser m (F Inlines)
strikeout :: OrgParser m (F Inlines)
strikeout = (Inlines -> Inlines) -> F Inlines -> F Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Inlines
B.strikeout (F Inlines -> F Inlines)
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Char -> OrgParser m (F Inlines)
forall (m :: * -> *).
PandocMonad m =>
Char -> OrgParser m (F Inlines)
emphasisBetween Char
'+'
underline :: PandocMonad m => OrgParser m (F Inlines)
underline :: OrgParser m (F Inlines)
underline = (Inlines -> Inlines) -> F Inlines -> F Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Inlines
B.underline (F Inlines -> F Inlines)
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Char -> OrgParser m (F Inlines)
forall (m :: * -> *).
PandocMonad m =>
Char -> OrgParser m (F Inlines)
emphasisBetween Char
'_'
verbatim :: PandocMonad m => OrgParser m (F Inlines)
verbatim :: OrgParser m (F Inlines)
verbatim = Inlines -> F Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines) -> (Text -> Inlines) -> Text -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines
B.code (Text -> F Inlines)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
-> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Text
verbatimBetween Char
'='
code :: PandocMonad m => OrgParser m (F Inlines)
code :: OrgParser m (F Inlines)
code = Inlines -> F Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines) -> (Text -> Inlines) -> Text -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines
B.code (Text -> F Inlines)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
-> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Text
verbatimBetween Char
'~'
subscript :: PandocMonad m => OrgParser m (F Inlines)
subscript :: OrgParser m (F Inlines)
subscript = (Inlines -> Inlines) -> F Inlines -> F Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Inlines
B.subscript (F Inlines -> F Inlines)
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'_' ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
subOrSuperExpr)
superscript :: PandocMonad m => OrgParser m (F Inlines)
superscript :: OrgParser m (F Inlines)
superscript = (Inlines -> Inlines) -> F Inlines -> F Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Inlines
B.superscript (F Inlines -> F Inlines)
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'^' ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
subOrSuperExpr)
math :: PandocMonad m => OrgParser m (F Inlines)
math :: OrgParser m (F Inlines)
math = Inlines -> F Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines) -> (Text -> Inlines) -> Text -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines
B.math (Text -> F Inlines)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
-> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [ Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Text
math1CharBetween Char
'$'
, Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Text
mathTextBetween Char
'$'
, Text
-> Text
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> OrgParser m Text
rawMathBetween Text
"\\(" Text
"\\)"
]
displayMath :: PandocMonad m => OrgParser m (F Inlines)
displayMath :: OrgParser m (F Inlines)
displayMath = Inlines -> F Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines) -> (Text -> Inlines) -> Text -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines
B.displayMath (Text -> F Inlines)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
-> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [ Text
-> Text
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> OrgParser m Text
rawMathBetween Text
"\\[" Text
"\\]"
, Text
-> Text
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> OrgParser m Text
rawMathBetween Text
"$$" Text
"$$"
]
updatePositions :: PandocMonad m
=> Char
-> OrgParser m Char
updatePositions :: Char -> OrgParser m Char
updatePositions Char
c = do
OrgParserState
st <- ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) OrgParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
let emphasisPreChars :: [Char]
emphasisPreChars = OrgParserState -> [Char]
orgStateEmphasisPreChars OrgParserState
st
Bool
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Char
c Char -> [Char] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Char]
emphasisPreChars) ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *). Monad m => OrgParser m ()
updateLastPreCharPos
Bool
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Char
c Char -> [Char] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Char]
emphasisForbiddenBorderChars) ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *). Monad m => OrgParser m ()
updateLastForbiddenCharPos
Char -> OrgParser m Char
forall (m :: * -> *) a. Monad m => a -> m a
return Char
c
symbol :: PandocMonad m => OrgParser m (F Inlines)
symbol :: OrgParser m (F Inlines)
symbol = Inlines -> F Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines) -> (Char -> Inlines) -> Char -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines
B.str (Text -> Inlines) -> (Char -> Text) -> Char -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Text
T.singleton (Char -> F Inlines)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
oneOf [Char]
specialChars ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> (Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
updatePositions)
emphasisBetween :: PandocMonad m
=> Char
-> OrgParser m (F Inlines)
emphasisBetween :: Char -> OrgParser m (F Inlines)
emphasisBetween Char
c = OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (F Inlines) -> OrgParser m (F Inlines))
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
Int -> OrgParser m ()
forall (m :: * -> *). PandocMonad m => Int -> OrgParser m ()
startEmphasisNewlinesCounting Int
emphasisAllowedNewlines
F Inlines
res <- OrgParser m Char -> OrgParser m Char -> OrgParser m (F Inlines)
forall (m :: * -> *) b a.
(PandocMonad m, Show b) =>
OrgParser m a -> OrgParser m b -> OrgParser m (F Inlines)
enclosedInlines (Char -> OrgParser m Char
forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
emphasisStart Char
c) (Char -> OrgParser m Char
forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
emphasisEnd Char
c)
Bool
isTopLevelEmphasis <- [Char] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Char] -> Bool)
-> (OrgParserState -> [Char]) -> OrgParserState -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OrgParserState -> [Char]
orgStateEmphasisCharStack (OrgParserState -> Bool)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) OrgParserState
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) OrgParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
Bool -> OrgParser m () -> OrgParser m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
isTopLevelEmphasis
OrgParser m ()
forall (m :: * -> *). PandocMonad m => OrgParser m ()
resetEmphasisNewlines
F Inlines -> OrgParser m (F Inlines)
forall (m :: * -> *) a. Monad m => a -> m a
return F Inlines
res
verbatimBetween :: PandocMonad m
=> Char
-> OrgParser m Text
verbatimBetween :: Char -> OrgParser m Text
verbatimBetween Char
c = OrgParser m Text -> OrgParser m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m Text -> OrgParser m Text)
-> OrgParser m Text -> OrgParser m Text
forall a b. (a -> b) -> a -> b
$
Char -> OrgParser m Char
forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
emphasisStart Char
c OrgParser m Char -> OrgParser m Text -> OrgParser m Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
Int -> OrgParser m Char -> OrgParser m Char -> OrgParser m Text
forall (m :: * -> *) a.
PandocMonad m =>
Int -> OrgParser m Char -> OrgParser m a -> OrgParser m Text
many1TillNOrLessNewlines Int
1 OrgParser m Char
verbatimChar (Char -> OrgParser m Char
forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
emphasisEnd Char
c)
where
verbatimChar :: OrgParser m Char
verbatimChar = [Char] -> OrgParser m Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
noneOf [Char]
"\n\r" OrgParser m Char -> (Char -> OrgParser m Char) -> OrgParser m Char
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Char -> OrgParser m Char
forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
updatePositions
mathTextBetween :: PandocMonad m
=> Char
-> OrgParser m Text
mathTextBetween :: Char -> OrgParser m Text
mathTextBetween Char
c = OrgParser m Text -> OrgParser m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m Text -> OrgParser m Text)
-> OrgParser m Text -> OrgParser m Text
forall a b. (a -> b) -> a -> b
$ do
Char -> OrgParser m Char
forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
mathStart Char
c
Text
body <- Int -> OrgParser m Char -> OrgParser m Char -> OrgParser m Text
forall (m :: * -> *) a.
PandocMonad m =>
Int -> OrgParser m Char -> OrgParser m a -> OrgParser m Text
many1TillNOrLessNewlines Int
mathAllowedNewlines
([Char] -> OrgParser m Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
noneOf (Char
cChar -> [Char] -> [Char]
forall a. a -> [a] -> [a]
:[Char]
"\n\r"))
(OrgParser m Char -> OrgParser m Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (OrgParser m Char -> OrgParser m Char)
-> OrgParser m Char -> OrgParser m Char
forall a b. (a -> b) -> a -> b
$ Char -> OrgParser m Char
forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
mathEnd Char
c)
Char
final <- Char -> OrgParser m Char
forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
mathEnd Char
c
Text -> OrgParser m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> OrgParser m Text) -> Text -> OrgParser m Text
forall a b. (a -> b) -> a -> b
$ Text -> Char -> Text
T.snoc Text
body Char
final
math1CharBetween :: PandocMonad m
=> Char
-> OrgParser m Text
math1CharBetween :: Char -> OrgParser m Text
math1CharBetween Char
c = OrgParser m Text -> OrgParser m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m Text -> OrgParser m Text)
-> OrgParser m Text -> OrgParser m Text
forall a b. (a -> b) -> a -> b
$ do
Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
c
Char
res <- [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
noneOf ([Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char)
-> [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall a b. (a -> b) -> a -> b
$ Char
cChar -> [Char] -> [Char]
forall a. a -> [a] -> [a]
:[Char]
mathForbiddenBorderChars
Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
c
ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> () ()
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead ([Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
oneOf [Char]
mathPostChars)
Text -> OrgParser m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> OrgParser m Text) -> Text -> OrgParser m Text
forall a b. (a -> b) -> a -> b
$ Char -> Text
T.singleton Char
res
rawMathBetween :: PandocMonad m
=> Text
-> Text
-> OrgParser m Text
rawMathBetween :: Text -> Text -> OrgParser m Text
rawMathBetween Text
s Text
e = OrgParser m Text -> OrgParser m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m Text -> OrgParser m Text)
-> OrgParser m Text -> OrgParser m Text
forall a b. (a -> b) -> a -> b
$ Text -> OrgParser m Text
forall s (m :: * -> *) u.
Stream s m Char =>
Text -> ParsecT s u m Text
textStr Text
s OrgParser m Text -> OrgParser m Text -> OrgParser m Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> OrgParser m Text -> OrgParser m Text
forall s (m :: * -> *) t st a.
Stream s m t =>
ParserT s st m Char -> ParserT s st m a -> ParserT s st m Text
manyTillChar ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
anyChar (OrgParser m Text -> OrgParser m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m Text -> OrgParser m Text)
-> OrgParser m Text -> OrgParser m Text
forall a b. (a -> b) -> a -> b
$ Text -> OrgParser m Text
forall s (m :: * -> *) u.
Stream s m Char =>
Text -> ParsecT s u m Text
textStr Text
e)
emphasisStart :: PandocMonad m => Char -> OrgParser m Char
emphasisStart :: Char -> OrgParser m Char
emphasisStart Char
c = OrgParser m Char -> OrgParser m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m Char -> OrgParser m Char)
-> OrgParser m Char -> OrgParser m Char
forall a b. (a -> b) -> a -> b
$ do
Bool -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ())
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
forall (m :: * -> *). PandocMonad m => OrgParser m Bool
afterEmphasisPreChar
Bool -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ())
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
forall s (m :: * -> *) a st.
(Stream s m a, HasLastStrPosition st) =>
ParserT s st m Bool
notAfterString
Char -> OrgParser m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
c
OrgParser m Char -> OrgParser m Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead ([Char] -> OrgParser m Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
noneOf [Char]
emphasisForbiddenBorderChars)
Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *). PandocMonad m => Char -> OrgParser m ()
pushToInlineCharStack Char
c
ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *). Monad m => OrgParser m ()
updateLastPreCharPos
Char -> OrgParser m Char
forall (m :: * -> *) a. Monad m => a -> m a
return Char
c
emphasisEnd :: PandocMonad m => Char -> OrgParser m Char
emphasisEnd :: Char -> OrgParser m Char
emphasisEnd Char
c = OrgParser m Char -> OrgParser m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m Char -> OrgParser m Char)
-> OrgParser m Char -> OrgParser m Char
forall a b. (a -> b) -> a -> b
$ do
Bool -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ())
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
forall (m :: * -> *). PandocMonad m => OrgParser m Bool
notAfterForbiddenBorderChar
Char -> OrgParser m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
c
ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> () ()
-> OrgParser m Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ OrgParser m Char -> OrgParser m Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead OrgParser m Char
acceptablePostChars
ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) a st.
(Stream s m a, HasLastStrPosition st) =>
ParserT s st m ()
updateLastStrPos
ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *). PandocMonad m => OrgParser m ()
popInlineCharStack
Char -> OrgParser m Char
forall (m :: * -> *) a. Monad m => a -> m a
return Char
c
where
acceptablePostChars :: OrgParser m Char
acceptablePostChars = do
[Char]
emphasisPostChars <- OrgParserState -> [Char]
orgStateEmphasisPostChars (OrgParserState -> [Char])
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) OrgParserState
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) OrgParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall (m :: * -> *). PandocMonad m => OrgParser m [Char]
surroundingEmphasisChar ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ([Char] -> OrgParser m Char) -> OrgParser m Char
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \[Char]
x -> [Char] -> OrgParser m Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
oneOf ([Char]
x [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
emphasisPostChars)
mathStart :: PandocMonad m => Char -> OrgParser m Char
mathStart :: Char -> OrgParser m Char
mathStart Char
c = OrgParser m Char -> OrgParser m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m Char -> OrgParser m Char)
-> OrgParser m Char -> OrgParser m Char
forall a b. (a -> b) -> a -> b
$
Char -> OrgParser m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
c OrgParser m Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> OrgParser m Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* OrgParser m Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall b s (m :: * -> *) a st.
(Show b, Stream s m a) =>
ParserT s st m b -> ParserT s st m ()
notFollowedBy' ([Char] -> OrgParser m Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
oneOf (Char
cChar -> [Char] -> [Char]
forall a. a -> [a] -> [a]
:[Char]
mathForbiddenBorderChars))
mathEnd :: PandocMonad m => Char -> OrgParser m Char
mathEnd :: Char -> OrgParser m Char
mathEnd Char
c = OrgParser m Char -> OrgParser m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m Char -> OrgParser m Char)
-> OrgParser m Char -> OrgParser m Char
forall a b. (a -> b) -> a -> b
$ do
Char
res <- [Char] -> OrgParser m Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
noneOf (Char
cChar -> [Char] -> [Char]
forall a. a -> [a] -> [a]
:[Char]
mathForbiddenBorderChars)
Char -> OrgParser m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
c
ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> () ()
-> OrgParser m Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ OrgParser m Char -> OrgParser m Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead ([Char] -> OrgParser m Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
oneOf [Char]
mathPostChars)
Char -> OrgParser m Char
forall (m :: * -> *) a. Monad m => a -> m a
return Char
res
enclosedInlines :: (PandocMonad m, Show b) => OrgParser m a
-> OrgParser m b
-> OrgParser m (F Inlines)
enclosedInlines :: OrgParser m a -> OrgParser m b -> OrgParser m (F Inlines)
enclosedInlines OrgParser m a
start OrgParser m b
end = OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (F Inlines) -> OrgParser m (F Inlines))
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$
F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF (F Inlines -> F Inlines)
-> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
-> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OrgParser m a
-> OrgParser m b
-> OrgParser m (F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
forall end s (m :: * -> *) st t a.
(Show end, Stream s m Char) =>
ParserT s st m t
-> ParserT s st m end -> ParserT s st m a -> ParserT s st m [a]
enclosed OrgParser m a
start OrgParser m b
end OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inline
enclosedRaw :: (PandocMonad m, Show b) => OrgParser m a
-> OrgParser m b
-> OrgParser m Text
enclosedRaw :: OrgParser m a -> OrgParser m b -> OrgParser m Text
enclosedRaw OrgParser m a
start OrgParser m b
end = OrgParser m Text -> OrgParser m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m Text -> OrgParser m Text)
-> OrgParser m Text -> OrgParser m Text
forall a b. (a -> b) -> a -> b
$
OrgParser m a
start OrgParser m a -> OrgParser m Text -> OrgParser m Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (OrgParser m Text
onSingleLine OrgParser m Text -> OrgParser m Text -> OrgParser m Text
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> OrgParser m Text
spanningTwoLines)
where onSingleLine :: OrgParser m Text
onSingleLine = OrgParser m Text -> OrgParser m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m Text -> OrgParser m Text)
-> OrgParser m Text -> OrgParser m Text
forall a b. (a -> b) -> a -> b
$ ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> OrgParser m b -> OrgParser m Text
forall end s (m :: * -> *) t st.
(Show end, Stream s m t) =>
ParserT s st m Char -> ParserT s st m end -> ParserT s st m Text
many1TillChar ([Char]
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
noneOf [Char]
"\n\r") OrgParser m b
end
spanningTwoLines :: OrgParser m Text
spanningTwoLines = OrgParser m Text -> OrgParser m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m Text -> OrgParser m Text)
-> OrgParser m Text -> OrgParser m Text
forall a b. (a -> b) -> a -> b
$
OrgParser m Text
forall (m :: * -> *). Monad m => OrgParser m Text
anyLine OrgParser m Text -> (Text -> OrgParser m Text) -> OrgParser m Text
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Text
f -> Text -> Text -> Text
forall a. Monoid a => a -> a -> a
mappend (Text
f Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" ") (Text -> Text) -> OrgParser m Text -> OrgParser m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OrgParser m Text
onSingleLine
many1TillNOrLessNewlines :: PandocMonad m => Int
-> OrgParser m Char
-> OrgParser m a
-> OrgParser m Text
many1TillNOrLessNewlines :: Int -> OrgParser m Char -> OrgParser m a -> OrgParser m Text
many1TillNOrLessNewlines Int
n OrgParser m Char
p OrgParser m a
end = OrgParser m Text -> OrgParser m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m Text -> OrgParser m Text)
-> OrgParser m Text -> OrgParser m Text
forall a b. (a -> b) -> a -> b
$
Maybe Int
-> [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall a.
(Eq a, Num a) =>
Maybe a
-> [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
nMoreLines (Int -> Maybe Int
forall a. a -> Maybe a
Just Int
n) [Char]
forall a. Monoid a => a
mempty ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ([Char] -> OrgParser m Text) -> OrgParser m Text
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [Char] -> OrgParser m Text
forall (f :: * -> *). Alternative f => [Char] -> f Text
oneOrMore
where
nMoreLines :: Maybe a
-> [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
nMoreLines Maybe a
Nothing [Char]
cs = [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall (m :: * -> *) a. Monad m => a -> m a
return [Char]
cs
nMoreLines (Just a
0) [Char]
cs = ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char])
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall a b. (a -> b) -> a -> b
$ ([Char]
cs [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++) ([Char] -> [Char])
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
finalLine
nMoreLines Maybe a
k [Char]
cs = ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char])
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall a b. (a -> b) -> a -> b
$ (Maybe a
-> [Char]
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (Maybe a, [Char])
forall p a.
p
-> [Char]
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (Maybe a, [Char])
final Maybe a
k [Char]
cs ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (Maybe a, [Char])
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (Maybe a, [Char])
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (Maybe a, [Char])
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Maybe a
-> [Char]
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (Maybe a, [Char])
forall b (f :: * -> *).
(Num b, Functor f) =>
f b
-> [Char]
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (f b, [Char])
rest Maybe a
k [Char]
cs)
ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (Maybe a, [Char])
-> ((Maybe a, [Char])
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char])
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Maybe a
-> [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char])
-> (Maybe a, [Char])
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Maybe a
-> [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
nMoreLines
final :: p
-> [Char]
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (Maybe a, [Char])
final p
_ [Char]
cs = (\[Char]
x -> (Maybe a
forall a. Maybe a
Nothing, [Char]
cs [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
x)) ([Char] -> (Maybe a, [Char]))
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (Maybe a, [Char])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
finalLine
rest :: f b
-> [Char]
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (f b, [Char])
rest f b
m [Char]
cs = (\[Char]
x -> (b -> b
forall a. Num a => a -> a
minus1 (b -> b) -> f b -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f b
m, [Char]
cs [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
x [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"\n")) ([Char] -> (f b, [Char]))
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (f b, [Char])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m Char
-> OrgParser m Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
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 OrgParser m Char
p OrgParser m Char
forall (m :: * -> *). Monad m => OrgParser m Char
newline)
finalLine :: ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
finalLine = ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char])
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall a b. (a -> b) -> a -> b
$ OrgParser m Char
-> OrgParser m a
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
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 OrgParser m Char
p OrgParser m a
end
minus1 :: a -> a
minus1 a
k = a
k a -> a -> a
forall a. Num a => a -> a -> a
- a
1
oneOrMore :: [Char] -> f Text
oneOrMore [Char]
cs = [Char] -> Text
T.pack [Char]
cs Text -> f () -> f Text
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Bool -> f ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ [Char] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Char]
cs)
emphasisForbiddenBorderChars :: [Char]
emphasisForbiddenBorderChars :: [Char]
emphasisForbiddenBorderChars = [Char]
"\t\n\r "
emphasisAllowedNewlines :: Int
emphasisAllowedNewlines :: Int
emphasisAllowedNewlines = Int
1
mathPostChars :: [Char]
mathPostChars :: [Char]
mathPostChars = [Char]
"\t\n \"'),-.:;?"
mathForbiddenBorderChars :: [Char]
mathForbiddenBorderChars :: [Char]
mathForbiddenBorderChars = [Char]
"\t\n\r ,;.$"
mathAllowedNewlines :: Int
mathAllowedNewlines :: Int
mathAllowedNewlines = Int
2
afterEmphasisPreChar :: PandocMonad m => OrgParser m Bool
afterEmphasisPreChar :: OrgParser m Bool
afterEmphasisPreChar = do
SourcePos
pos <- ParsecT Text OrgParserState (ReaderT OrgParserLocal m) SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Maybe SourcePos
lastPrePos <- OrgParserState -> Maybe SourcePos
orgStateLastPreCharPos (OrgParserState -> Maybe SourcePos)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) OrgParserState
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (Maybe SourcePos)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) OrgParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
Bool -> OrgParser m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> OrgParser m Bool) -> Bool -> OrgParser m Bool
forall a b. (a -> b) -> a -> b
$ Bool -> (SourcePos -> Bool) -> Maybe SourcePos -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
True (SourcePos -> SourcePos -> Bool
forall a. Eq a => a -> a -> Bool
== SourcePos
pos) Maybe SourcePos
lastPrePos
notAfterForbiddenBorderChar :: PandocMonad m => OrgParser m Bool
notAfterForbiddenBorderChar :: OrgParser m Bool
notAfterForbiddenBorderChar = do
SourcePos
pos <- ParsecT Text OrgParserState (ReaderT OrgParserLocal m) SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Maybe SourcePos
lastFBCPos <- OrgParserState -> Maybe SourcePos
orgStateLastForbiddenCharPos (OrgParserState -> Maybe SourcePos)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) OrgParserState
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (Maybe SourcePos)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) OrgParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
Bool -> OrgParser m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> OrgParser m Bool) -> Bool -> OrgParser m Bool
forall a b. (a -> b) -> a -> b
$ Maybe SourcePos
lastFBCPos Maybe SourcePos -> Maybe SourcePos -> Bool
forall a. Eq a => a -> a -> Bool
/= SourcePos -> Maybe SourcePos
forall a. a -> Maybe a
Just SourcePos
pos
subOrSuperExpr :: PandocMonad m => OrgParser m (F Inlines)
subOrSuperExpr :: OrgParser m (F Inlines)
subOrSuperExpr = OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (F Inlines) -> OrgParser m (F Inlines))
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$
OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
simpleSubOrSuperText OrgParser m (F Inlines)
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
([ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [ Char
-> Char
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall s (m :: * -> *) st.
Stream s m Char =>
Char -> Char -> ParserT s st m Char -> ParserT s st m Text
charsInBalanced Char
'{' Char
'}' ([Char]
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
noneOf [Char]
"\n\r")
, (Char, Char) -> Text -> Text
enclosing (Char
'(', Char
')') (Text -> Text)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Char
-> Char
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall s (m :: * -> *) st.
Stream s m Char =>
Char -> Char -> ParserT s st m Char -> ParserT s st m Text
charsInBalanced Char
'(' Char
')' ([Char]
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
noneOf [Char]
"\n\r")
] ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
-> (Text -> OrgParser m (F Inlines)) -> OrgParser m (F Inlines)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= OrgParser m (F Inlines) -> Text -> OrgParser m (F Inlines)
forall (m :: * -> *) a.
Monad m =>
OrgParser m a -> Text -> OrgParser m a
parseFromString ([F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
-> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OrgParser m (F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inline))
where enclosing :: (Char, Char) -> Text -> Text
enclosing (Char
left, Char
right) Text
s = Char -> Text -> Text
T.cons Char
left (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Text -> Char -> Text
T.snoc Text
s Char
right
simpleSubOrSuperText :: PandocMonad m => OrgParser m (F Inlines)
simpleSubOrSuperText :: OrgParser m (F Inlines)
simpleSubOrSuperText = OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (F Inlines) -> OrgParser m (F Inlines))
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
OrgParserState
state <- ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) OrgParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
Bool -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ())
-> (OrgParserState -> Bool)
-> OrgParserState
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExportSettings -> Bool
exportSubSuperscripts (ExportSettings -> Bool)
-> (OrgParserState -> ExportSettings) -> OrgParserState -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OrgParserState -> ExportSettings
orgStateExportSettings (OrgParserState
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ())
-> OrgParserState
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall a b. (a -> b) -> a -> b
$ OrgParserState
state
Inlines -> F Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> F Inlines) -> (Text -> Inlines) -> Text -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines
B.str (Text -> F Inlines)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
-> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
[ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [ Text -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall s (m :: * -> *) u.
Stream s m Char =>
Text -> ParsecT s u m Text
textStr Text
"*"
, Text -> Text -> Text
forall a. Monoid a => a -> a -> a
mappend (Text -> Text -> Text)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (Text -> Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Text
"" (Char -> Text
T.singleton (Char -> Text)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
oneOf [Char]
"+-")
ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (Text -> Text)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
many1Char ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
alphaNum
]
inlineLaTeX :: PandocMonad m => OrgParser m (F Inlines)
inlineLaTeX :: OrgParser m (F Inlines)
inlineLaTeX = OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (F Inlines) -> OrgParser m (F Inlines))
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
Text
cmd <- OrgParser m Text
forall (m :: * -> *). PandocMonad m => OrgParser m Text
inlineLaTeXCommand
TeXExport
texOpt <- (ExportSettings -> TeXExport) -> OrgParser m TeXExport
forall (m :: * -> *) a.
Monad m =>
(ExportSettings -> a) -> OrgParser m a
getExportSetting ExportSettings -> TeXExport
exportWithLatex
Bool
allowEntities <- (ExportSettings -> Bool) -> OrgParser m Bool
forall (m :: * -> *) a.
Monad m =>
(ExportSettings -> a) -> OrgParser m a
getExportSetting ExportSettings -> Bool
exportWithEntities
Maybe Inlines
ils <- Text -> TeXExport -> OrgParser m (Maybe Inlines)
forall (m :: * -> *).
PandocMonad m =>
Text -> TeXExport -> OrgParser m (Maybe Inlines)
parseAsInlineLaTeX Text
cmd TeXExport
texOpt
OrgParser m (F Inlines)
-> (Inlines -> OrgParser m (F Inlines))
-> Maybe Inlines
-> OrgParser m (F Inlines)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe OrgParser m (F Inlines)
forall (m :: * -> *) a. MonadPlus m => m a
mzero Inlines -> OrgParser m (F Inlines)
forall (m :: * -> *) a s. Monad m => a -> m (Future s a)
returnF (Maybe Inlines -> OrgParser m (F Inlines))
-> Maybe Inlines -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$
Bool -> Text -> Maybe Inlines
parseAsMathMLSym Bool
allowEntities Text
cmd Maybe Inlines -> Maybe Inlines -> Maybe Inlines
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus`
Text -> TeXExport -> Maybe Inlines
parseAsMath Text
cmd TeXExport
texOpt Maybe Inlines -> Maybe Inlines -> Maybe Inlines
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus`
Maybe Inlines
ils
where
parseAsInlineLaTeX :: PandocMonad m
=> Text -> TeXExport -> OrgParser m (Maybe Inlines)
parseAsInlineLaTeX :: Text -> TeXExport -> OrgParser m (Maybe Inlines)
parseAsInlineLaTeX Text
cs = \case
TeXExport
TeXExport -> Either ParseError Inlines -> Maybe Inlines
forall a b. Either a b -> Maybe b
maybeRight (Either ParseError Inlines -> Maybe Inlines)
-> ParsecT
Text
OrgParserState
(ReaderT OrgParserLocal m)
(Either ParseError Inlines)
-> OrgParser m (Maybe Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
Text
ParserState
(ParsecT Text OrgParserState (ReaderT OrgParserLocal m))
Inlines
-> ParserState
-> [Char]
-> Text
-> ParsecT
Text
OrgParserState
(ReaderT OrgParserLocal m)
(Either ParseError Inlines)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> u -> [Char] -> s -> m (Either ParseError a)
runParserT ParsecT
Text
ParserState
(ParsecT Text OrgParserState (ReaderT OrgParserLocal m))
Inlines
forall (m :: * -> *).
PandocMonad m =>
ParserT Text ParserState m Inlines
inlineCommand ParserState
state [Char]
"" Text
cs
TeXExport
TeXIgnore -> Maybe Inlines -> OrgParser m (Maybe Inlines)
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> Maybe Inlines
forall a. a -> Maybe a
Just Inlines
forall a. Monoid a => a
mempty)
TeXExport
TeXVerbatim -> Maybe Inlines -> OrgParser m (Maybe Inlines)
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> Maybe Inlines
forall a. a -> Maybe a
Just (Inlines -> Maybe Inlines) -> Inlines -> Maybe Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.str Text
cs)
parseAsMathMLSym :: Bool -> Text -> Maybe Inlines
parseAsMathMLSym :: Bool -> Text -> Maybe Inlines
parseAsMathMLSym Bool
allowEntities Text
cs = do
let clean :: Text -> Text
clean = (Char -> Bool) -> Text -> Text
T.dropWhileEnd (Char -> [Char] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` ([Char]
"{}" :: String)) (Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Text -> Text
T.drop Int
1
case Text -> Inlines
B.str (Text -> Inlines) -> Maybe Text -> Maybe Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> Maybe Text
MathMLEntityMap.getUnicode (Text -> Text
clean Text
cs) of
Just Inlines
_ | Bool -> Bool
not Bool
allowEntities -> Inlines -> Maybe Inlines
forall a. a -> Maybe a
Just (Inlines -> Maybe Inlines) -> Inlines -> Maybe Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.str Text
cs
Maybe Inlines
x -> Maybe Inlines
x
state :: ParserState
state :: ParserState
state = ParserState
forall a. Default a => a
def{ stateOptions :: ReaderOptions
stateOptions = ReaderOptions
forall a. Default a => a
def{ readerExtensions :: Extensions
readerExtensions =
Extension -> Extensions -> Extensions
enableExtension Extension
Ext_raw_tex (ReaderOptions -> Extensions
readerExtensions ReaderOptions
forall a. Default a => a
def) } }
parseAsMath :: Text -> TeXExport -> Maybe Inlines
parseAsMath :: Text -> TeXExport -> Maybe Inlines
parseAsMath Text
cs = \case
TeXExport
TeXExport -> Either Text [Exp] -> Maybe [Exp]
forall a b. Either a b -> Maybe b
maybeRight (Text -> Either Text [Exp]
readTeX Text
cs) Maybe [Exp] -> ([Exp] -> Maybe Inlines) -> Maybe Inlines
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
([Inline] -> Inlines) -> Maybe [Inline] -> Maybe Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Inline] -> Inlines
forall a. [a] -> Many a
B.fromList (Maybe [Inline] -> Maybe Inlines)
-> ([Exp] -> Maybe [Inline]) -> [Exp] -> Maybe Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DisplayType -> [Exp] -> Maybe [Inline]
writePandoc DisplayType
DisplayInline
TeXExport
TeXIgnore -> Inlines -> Maybe Inlines
forall a. a -> Maybe a
Just Inlines
forall a. Monoid a => a
mempty
TeXExport
TeXVerbatim -> Inlines -> Maybe Inlines
forall a. a -> Maybe a
Just (Inlines -> Maybe Inlines) -> Inlines -> Maybe Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.str Text
cs
maybeRight :: Either a b -> Maybe b
maybeRight :: Either a b -> Maybe b
maybeRight = (a -> Maybe b) -> (b -> Maybe b) -> Either a b -> Maybe b
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Maybe b -> a -> Maybe b
forall a b. a -> b -> a
const Maybe b
forall a. Maybe a
Nothing) b -> Maybe b
forall a. a -> Maybe a
Just
inlineLaTeXCommand :: PandocMonad m => OrgParser m Text
inlineLaTeXCommand :: OrgParser m Text
inlineLaTeXCommand = OrgParser m Text -> OrgParser m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m Text -> OrgParser m Text)
-> OrgParser m Text -> OrgParser m Text
forall a b. (a -> b) -> a -> b
$ do
Text
rest <- OrgParser m Text
forall (m :: * -> *) s u. Monad m => ParsecT s u m s
getInput
OrgParserState
st <- ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) OrgParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
Either ParseError Text
parsed <- (ReaderT OrgParserLocal m (Either ParseError Text)
-> ParsecT
Text
OrgParserState
(ReaderT OrgParserLocal m)
(Either ParseError Text)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ReaderT OrgParserLocal m (Either ParseError Text)
-> ParsecT
Text
OrgParserState
(ReaderT OrgParserLocal m)
(Either ParseError Text))
-> (m (Either ParseError Text)
-> ReaderT OrgParserLocal m (Either ParseError Text))
-> m (Either ParseError Text)
-> ParsecT
Text
OrgParserState
(ReaderT OrgParserLocal m)
(Either ParseError Text)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m (Either ParseError Text)
-> ReaderT OrgParserLocal m (Either ParseError Text)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift) (m (Either ParseError Text)
-> ParsecT
Text
OrgParserState
(ReaderT OrgParserLocal m)
(Either ParseError Text))
-> m (Either ParseError Text)
-> ParsecT
Text
OrgParserState
(ReaderT OrgParserLocal m)
(Either ParseError Text)
forall a b. (a -> b) -> a -> b
$ ParsecT Text OrgParserState m Text
-> OrgParserState -> [Char] -> Text -> m (Either ParseError Text)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> u -> [Char] -> s -> m (Either ParseError a)
runParserT ParsecT Text OrgParserState m Text
forall (m :: * -> *) s.
(PandocMonad m, HasMacros s, HasReaderOptions s) =>
ParserT Text s m Text
rawLaTeXInline OrgParserState
st [Char]
"source" Text
rest
case Either ParseError Text
parsed of
Right Text
cs -> do
let cmdNoSpc :: Text
cmdNoSpc = (Char -> Bool) -> Text -> Text
T.dropWhileEnd Char -> Bool
isSpace Text
cs
let len :: Int
len = Text -> Int
T.length Text
cmdNoSpc
Int
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall s (m :: * -> *) t u a.
Stream s m t =>
Int -> ParsecT s u m a -> ParsecT s u m [a]
count Int
len ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
anyChar
Text -> OrgParser m Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
cmdNoSpc
Either ParseError Text
_ -> OrgParser m Text
forall (m :: * -> *) a. MonadPlus m => m a
mzero
exportSnippet :: PandocMonad m => OrgParser m (F Inlines)
exportSnippet :: OrgParser m (F Inlines)
exportSnippet = OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (F Inlines) -> OrgParser m (F Inlines))
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
[Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"@@"
Text
format <- ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall end s (m :: * -> *) t st.
(Show end, Stream s m t) =>
ParserT s st m Char -> ParserT s st m end -> ParserT s st m Text
many1TillChar (ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
alphaNum ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Char -> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'-') (Char -> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
':')
Text
snippet <- ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall s (m :: * -> *) t st a.
Stream s m t =>
ParserT s st m Char -> ParserT s st m a -> ParserT s st m Text
manyTillChar ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
anyChar (ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char])
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall a b. (a -> b) -> a -> b
$ [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"@@")
Inlines -> OrgParser m (F Inlines)
forall (m :: * -> *) a s. Monad m => a -> m (Future s a)
returnF (Inlines -> OrgParser m (F Inlines))
-> Inlines -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines
B.rawInline Text
format Text
snippet
macro :: PandocMonad m => OrgParser m (F Inlines)
macro :: OrgParser m (F Inlines)
macro = OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (F Inlines) -> OrgParser m (F Inlines))
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
Int
recursionDepth <- OrgParserState -> Int
orgStateMacroDepth (OrgParserState -> Int)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) OrgParserState
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) OrgParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
Bool -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ())
-> Bool
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall a b. (a -> b) -> a -> b
$ Int
recursionDepth Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
15
[Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"{{{"
Text
name <- ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
manyChar ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Char
alphaNum
[Text]
args <- ([] [Text]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Text]
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
"}}}")
ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Text]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Text]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Text]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Char -> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'(' ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Text]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Text]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Text
forall st. ParserT Text st (ReaderT OrgParserLocal m) Text
argument ParserT Text OrgParserState (ReaderT OrgParserLocal m) Text
-> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Text]
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` Char -> ParserT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
',' ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Text]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Text]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text OrgParserState (ReaderT OrgParserLocal m) [Char]
forall u. ParsecT Text u (ReaderT OrgParserLocal m) [Char]
eoa
Maybe MacroExpander
expander <- Text -> OrgParserState -> Maybe MacroExpander
lookupMacro Text
name (OrgParserState -> Maybe MacroExpander)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) OrgParserState
-> ParsecT
Text
OrgParserState
(ReaderT OrgParserLocal m)
(Maybe MacroExpander)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) OrgParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
case Maybe MacroExpander
expander of
Maybe MacroExpander
Nothing -> OrgParser m (F Inlines)
forall (m :: * -> *) a. MonadPlus m => m a
mzero
Just MacroExpander
fn -> do
(OrgParserState -> OrgParserState)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((OrgParserState -> OrgParserState)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ())
-> (OrgParserState -> OrgParserState)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall a b. (a -> b) -> a -> b
$ \OrgParserState
s -> OrgParserState
s { orgStateMacroDepth :: Int
orgStateMacroDepth = Int
recursionDepth Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1 }
F Inlines
res <- OrgParser m (F Inlines) -> Text -> OrgParser m (F Inlines)
forall (m :: * -> *) a.
Monad m =>
OrgParser m a -> Text -> OrgParser m a
parseFromString ([F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
-> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OrgParser m (F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inline) (Text -> OrgParser m (F Inlines))
-> Text -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ MacroExpander
fn [Text]
args
(OrgParserState -> OrgParserState)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((OrgParserState -> OrgParserState)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ())
-> (OrgParserState -> OrgParserState)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) ()
forall a b. (a -> b) -> a -> b
$ \OrgParserState
s -> OrgParserState
s { orgStateMacroDepth :: Int
orgStateMacroDepth = Int
recursionDepth }
F Inlines -> OrgParser m (F Inlines)
forall (m :: * -> *) a. Monad m => a -> m a
return F Inlines
res
where
argument :: ParserT Text st (ReaderT OrgParserLocal m) Text
argument = ParserT Text st (ReaderT OrgParserLocal m) Char
-> ParserT Text st (ReaderT OrgParserLocal m) Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParserT s st m Char -> ParserT s st m Text
manyChar (ParserT Text st (ReaderT OrgParserLocal m) Char
-> ParserT Text st (ReaderT OrgParserLocal m) Text)
-> ParserT Text st (ReaderT OrgParserLocal m) Char
-> ParserT Text st (ReaderT OrgParserLocal m) Text
forall a b. (a -> b) -> a -> b
$ ParsecT Text st (ReaderT OrgParserLocal m) [Char]
-> ParsecT Text st (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT Text st (ReaderT OrgParserLocal m) [Char]
forall u. ParsecT Text u (ReaderT OrgParserLocal m) [Char]
eoa ParsecT Text st (ReaderT OrgParserLocal m) ()
-> ParserT Text st (ReaderT OrgParserLocal m) Char
-> ParserT Text st (ReaderT OrgParserLocal m) Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> [Char] -> ParserT Text st (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m Char
noneOf [Char]
","
eoa :: ParsecT Text u (ReaderT OrgParserLocal m) [Char]
eoa = [Char] -> ParsecT Text u (ReaderT OrgParserLocal m) [Char]
forall s (m :: * -> *) u.
Stream s m Char =>
[Char] -> ParsecT s u m [Char]
string [Char]
")}}}"
smart :: PandocMonad m => OrgParser m (F Inlines)
smart :: OrgParser m (F Inlines)
smart = [OrgParser m (F Inlines)] -> OrgParser m (F Inlines)
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
doubleQuoted, OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
singleQuoted, OrgParser m (F Inlines)
forall s.
ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (Future s Inlines)
orgApostrophe, OrgParser m (F Inlines)
orgDash, OrgParser m (F Inlines)
orgEllipses]
where
orgDash :: OrgParser m (F Inlines)
orgDash = do
Bool -> OrgParser m ()
forall (m :: * -> *). PandocMonad m => Bool -> OrgParser m ()
guardOrSmartEnabled (Bool -> OrgParser m ())
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
-> OrgParser m ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (ExportSettings -> Bool)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
forall (m :: * -> *) a.
Monad m =>
(ExportSettings -> a) -> OrgParser m a
getExportSetting ExportSettings -> Bool
exportSpecialStrings
Inlines -> F Inlines
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Inlines -> F Inlines)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Inlines
-> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Inlines
forall st s (m :: * -> *).
(HasReaderOptions st, Stream s m Char) =>
ParserT s st m Inlines
dash OrgParser m (F Inlines)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
updatePositions Char
'-'
orgEllipses :: OrgParser m (F Inlines)
orgEllipses = do
Bool -> OrgParser m ()
forall (m :: * -> *). PandocMonad m => Bool -> OrgParser m ()
guardOrSmartEnabled (Bool -> OrgParser m ())
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
-> OrgParser m ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (ExportSettings -> Bool)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
forall (m :: * -> *) a.
Monad m =>
(ExportSettings -> a) -> OrgParser m a
getExportSetting ExportSettings -> Bool
exportSpecialStrings
Inlines -> F Inlines
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Inlines -> F Inlines)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Inlines
-> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Inlines
forall s (m :: * -> *) st.
Stream s m Char =>
ParserT s st m Inlines
ellipses OrgParser m (F Inlines)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
updatePositions Char
'.'
orgApostrophe :: ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (Future s Inlines)
orgApostrophe = do
Extension -> OrgParser m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParserT s st m ()
guardEnabled Extension
Ext_smart
(Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'\'' ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Char -> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char Char
'\8217') ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> OrgParser m ()
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* OrgParser m ()
forall (m :: * -> *). Monad m => OrgParser m ()
updateLastPreCharPos
ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
-> OrgParser m ()
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* OrgParser m ()
forall (m :: * -> *). Monad m => OrgParser m ()
updateLastForbiddenCharPos
Inlines
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) (Future s Inlines)
forall (m :: * -> *) a s. Monad m => a -> m (Future s a)
returnF (Text -> Inlines
B.str Text
"\x2019")
guardOrSmartEnabled :: PandocMonad m => Bool -> OrgParser m ()
guardOrSmartEnabled :: Bool -> OrgParser m ()
guardOrSmartEnabled Bool
b = do
Bool
smartExtension <- Extension -> Extensions -> Bool
extensionEnabled Extension
Ext_smart (Extensions -> Bool)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) Extensions
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ReaderOptions -> Extensions)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) Extensions
forall st s (m :: * -> *) t b.
(HasReaderOptions st, Stream s m t) =>
(ReaderOptions -> b) -> ParserT s st m b
getOption ReaderOptions -> Extensions
readerExtensions
Bool -> OrgParser m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool
b Bool -> Bool -> Bool
|| Bool
smartExtension)
singleQuoted :: PandocMonad m => OrgParser m (F Inlines)
singleQuoted :: OrgParser m (F Inlines)
singleQuoted = OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (F Inlines) -> OrgParser m (F Inlines))
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
Bool -> OrgParser m ()
forall (m :: * -> *). PandocMonad m => Bool -> OrgParser m ()
guardOrSmartEnabled (Bool -> OrgParser m ())
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
-> OrgParser m ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (ExportSettings -> Bool)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
forall (m :: * -> *) a.
Monad m =>
(ExportSettings -> a) -> OrgParser m a
getExportSetting ExportSettings -> Bool
exportSmartQuotes
OrgParser m ()
forall st (m :: * -> *) s.
(HasLastStrPosition st, HasQuoteContext st m, Stream s m Char) =>
ParserT s st m ()
singleQuoteStart
Char -> OrgParser m Char
forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
updatePositions Char
'\''
QuoteContext -> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall st (m :: * -> *) s a.
HasQuoteContext st m =>
QuoteContext -> ParsecT s st m a -> ParsecT s st m a
withQuoteContext QuoteContext
InSingleQuote (OrgParser m (F Inlines) -> OrgParser m (F Inlines))
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$
(Inlines -> Inlines) -> F Inlines -> F Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Inlines
B.singleQuoted (F Inlines -> F Inlines)
-> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF (F Inlines -> F Inlines)
-> ([F Inlines] -> F Inlines) -> [F Inlines] -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
-> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
OrgParser m (F Inlines)
-> OrgParser m ()
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParserT s st m a -> ParserT s st m end -> ParserT s st m [a]
many1Till OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inline (OrgParser m ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
singleQuoteEnd OrgParser m () -> OrgParser m Char -> OrgParser m ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> OrgParser m Char
forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
updatePositions Char
'\'')
doubleQuoted :: PandocMonad m => OrgParser m (F Inlines)
doubleQuoted :: OrgParser m (F Inlines)
doubleQuoted = OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (F Inlines) -> OrgParser m (F Inlines))
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
Bool -> OrgParser m ()
forall (m :: * -> *). PandocMonad m => Bool -> OrgParser m ()
guardOrSmartEnabled (Bool -> OrgParser m ())
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
-> OrgParser m ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (ExportSettings -> Bool)
-> ParsecT Text OrgParserState (ReaderT OrgParserLocal m) Bool
forall (m :: * -> *) a.
Monad m =>
(ExportSettings -> a) -> OrgParser m a
getExportSetting ExportSettings -> Bool
exportSmartQuotes
OrgParser m ()
forall st (m :: * -> *) s.
(HasQuoteContext st m, Stream s m Char) =>
ParserT s st m ()
doubleQuoteStart
Char -> OrgParser m Char
forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
updatePositions Char
'"'
F Inlines
contents <- [F Inlines] -> F Inlines
forall a. Monoid a => [a] -> a
mconcat ([F Inlines] -> F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
-> OrgParser m (F Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OrgParser m (F Inlines)
-> ParsecT
Text OrgParserState (ReaderT OrgParserLocal m) [F Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (OrgParser m (F Inlines) -> OrgParser m (F Inlines))
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ OrgParser m () -> OrgParser m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy OrgParser m ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
doubleQuoteEnd OrgParser m ()
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> OrgParser m (F Inlines)
forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inline)
let doubleQuotedContent :: OrgParser m (F Inlines)
doubleQuotedContent = QuoteContext -> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall st (m :: * -> *) s a.
HasQuoteContext st m =>
QuoteContext -> ParsecT s st m a -> ParsecT s st m a
withQuoteContext QuoteContext
InDoubleQuote (OrgParser m (F Inlines) -> OrgParser m (F Inlines))
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ do
OrgParser m ()
forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
doubleQuoteEnd
OrgParser m ()
forall (m :: * -> *). Monad m => OrgParser m ()
updateLastForbiddenCharPos
F Inlines -> OrgParser m (F Inlines)
forall (m :: * -> *) a. Monad m => a -> m a
return (F Inlines -> OrgParser m (F Inlines))
-> (F Inlines -> F Inlines) -> F Inlines -> OrgParser m (F Inlines)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Inlines -> Inlines) -> F Inlines -> F Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Inlines
B.doubleQuoted (F Inlines -> F Inlines)
-> (F Inlines -> F Inlines) -> F Inlines -> F Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. F Inlines -> F Inlines
forall s. Future s Inlines -> Future s Inlines
trimInlinesF (F Inlines -> OrgParser m (F Inlines))
-> F Inlines -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ F Inlines
contents
let leftQuoteAndContent :: OrgParser m (F Inlines)
leftQuoteAndContent = F Inlines -> OrgParser m (F Inlines)
forall (m :: * -> *) a. Monad m => a -> m a
return (F Inlines -> OrgParser m (F Inlines))
-> F Inlines -> OrgParser m (F Inlines)
forall a b. (a -> b) -> a -> b
$ Inlines -> F Inlines
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Text -> Inlines
B.str Text
"\8220") F Inlines -> F Inlines -> F Inlines
forall a. Semigroup a => a -> a -> a
<> F Inlines
contents
OrgParser m (F Inlines)
doubleQuotedContent OrgParser m (F Inlines)
-> OrgParser m (F Inlines) -> OrgParser m (F Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> OrgParser m (F Inlines)
leftQuoteAndContent