{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{- |
   Module      : Text.Pandoc.Readers.Org.Inlines
   Copyright   : Copyright (C) 2014-2023 Albert Krewinkel
   License     : GNU GPL, version 2 or above

   Maintainer  : Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>

Parsers for Org-mode inline elements.
-}
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 Text.Pandoc.Sources (ToSources(..))
import qualified Text.TeXMath.Readers.MathML.EntityMap as MathMLEntityMap
import Safe (lastMay)
import Control.Monad (guard, mplus, mzero, unless, when, void)
import Control.Monad.Trans (lift)
import Data.Char (isAlphaNum, isSpace)
import qualified Data.Map as M
import Data.Text (Text)
import qualified Data.Text as T

--
-- Functions acting on the parser state
--
recordAnchorId :: PandocMonad m => Text -> OrgParser m ()
recordAnchorId :: forall (m :: * -> *). PandocMonad m => Text -> OrgParser m ()
recordAnchorId Text
i = forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \OrgParserState
s ->
  OrgParserState
s{ orgStateAnchorIds :: [Text]
orgStateAnchorIds = Text
i forall a. a -> [a] -> [a]
: OrgParserState -> [Text]
orgStateAnchorIds OrgParserState
s }

pushToInlineCharStack :: PandocMonad m => Char -> OrgParser m ()
pushToInlineCharStack :: forall (m :: * -> *). PandocMonad m => Char -> OrgParser m ()
pushToInlineCharStack Char
c = forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \OrgParserState
s ->
  OrgParserState
s{ orgStateEmphasisCharStack :: [Char]
orgStateEmphasisCharStack = Char
cforall a. a -> [a] -> [a]
:OrgParserState -> [Char]
orgStateEmphasisCharStack OrgParserState
s }

popInlineCharStack :: PandocMonad m => OrgParser m ()
popInlineCharStack :: forall (m :: * -> *). PandocMonad m => OrgParser m ()
popInlineCharStack = forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \OrgParserState
s ->
  OrgParserState
s{ orgStateEmphasisCharStack :: [Char]
orgStateEmphasisCharStack = forall a. Int -> [a] -> [a]
drop Int
1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. OrgParserState -> [Char]
orgStateEmphasisCharStack forall a b. (a -> b) -> a -> b
$ OrgParserState
s }

surroundingEmphasisChar :: PandocMonad m => OrgParser m [Char]
surroundingEmphasisChar :: forall (m :: * -> *). PandocMonad m => OrgParser m [Char]
surroundingEmphasisChar =
  forall a. Int -> [a] -> [a]
take Int
1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Int -> [a] -> [a]
drop Int
1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. OrgParserState -> [Char]
orgStateEmphasisCharStack forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState

startEmphasisNewlinesCounting :: PandocMonad m => Int -> OrgParser m ()
startEmphasisNewlinesCounting :: forall (m :: * -> *). PandocMonad m => Int -> OrgParser m ()
startEmphasisNewlinesCounting Int
maxNewlines = forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \OrgParserState
s ->
  OrgParserState
s{ orgStateEmphasisNewlines :: Maybe Int
orgStateEmphasisNewlines = forall a. a -> Maybe a
Just Int
maxNewlines }

decEmphasisNewlinesCount :: PandocMonad m => OrgParser m ()
decEmphasisNewlinesCount :: forall (m :: * -> *). PandocMonad m => OrgParser m ()
decEmphasisNewlinesCount = forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \OrgParserState
s ->
  OrgParserState
s{ orgStateEmphasisNewlines :: Maybe Int
orgStateEmphasisNewlines = (\Int
n -> Int
n forall a. Num a => a -> a -> a
- Int
1) 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 :: forall (m :: * -> *). PandocMonad m => OrgParser m Bool
newlinesCountWithinLimits = do
  OrgParserState
st <- forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ ((forall a. Ord a => a -> a -> Bool
< Int
0) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OrgParserState -> Maybe Int
orgStateEmphasisNewlines OrgParserState
st) forall a. Eq a => a -> a -> Bool
/= forall a. a -> Maybe a
Just Bool
True

resetEmphasisNewlines :: PandocMonad m => OrgParser m ()
resetEmphasisNewlines :: forall (m :: * -> *). PandocMonad m => OrgParser m ()
resetEmphasisNewlines = forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \OrgParserState
s ->
  OrgParserState
s{ orgStateEmphasisNewlines :: Maybe Int
orgStateEmphasisNewlines = forall a. Maybe a
Nothing }

addToNotesTable :: PandocMonad m => OrgNoteRecord -> OrgParser m ()
addToNotesTable :: forall (m :: * -> *).
PandocMonad m =>
OrgNoteRecord -> OrgParser m ()
addToNotesTable OrgNoteRecord
note = do
  OrgNoteTable
oldnotes <- OrgParserState -> OrgNoteTable
orgStateNotes' forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \OrgParserState
s -> OrgParserState
s{ orgStateNotes' :: OrgNoteTable
orgStateNotes' = OrgNoteRecord
noteforall a. a -> [a] -> [a]
:OrgNoteTable
oldnotes }

-- | Parse a single Org-mode inline element
inline :: PandocMonad m => OrgParser m (F Inlines)
inline :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inline =
  forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [ forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
whitespace
         , forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
linebreak
         , forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
cite
         , forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
footnote
         , forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
linkOrImage
         , forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
anchor
         , forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inlineCodeBlock
         , forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
str
         , forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
endline
         , forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
emphasizedText
         , forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
code
         , forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
math
         , forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
displayMath
         , forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
verbatim
         , forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
subscript
         , forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
superscript
         , forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inlineLaTeX
         , forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
exportSnippet
         , forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
macro
         , forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
smart
         , forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
symbol
         ] forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* (forall (f :: * -> *). Alternative f => Bool -> f ()
guard forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (m :: * -> *). PandocMonad m => OrgParser m Bool
newlinesCountWithinLimits)
  forall s u (m :: * -> *) a.
ParsecT s u m a -> [Char] -> ParsecT s u m a
<?> [Char]
"inline"

-- | Read the rest of the input as inlines.
inlines :: PandocMonad m => OrgParser m (F Inlines)
inlines :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inlines = forall s. Future s Inlines -> Future s Inlines
trimInlinesF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inline

-- treat these as potentially non-text when parsing inline:
specialChars :: [Char]
specialChars :: [Char]
specialChars = [Char]
"\"$'()*+-,./:;<=>@[\\]^_{|}~"


whitespace :: PandocMonad m => OrgParser m (F Inlines)
whitespace :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
whitespace = forall (f :: * -> *) a. Applicative f => a -> f a
pure Inlines
B.space forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar
                          forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *). Monad m => OrgParser m ()
updateLastPreCharPos
                          forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *). Monad m => OrgParser m ()
updateLastForbiddenCharPos
             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 :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
linebreak = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Applicative f => a -> f a
pure Inlines
B.linebreak forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"\\\\" forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *). Monad m => OrgParser m Char
newline

str :: PandocMonad m => OrgParser m (F Inlines)
str :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
str = forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines
B.str forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
      ( forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
noneOf forall a b. (a -> b) -> a -> b
$ [Char]
specialChars forall a. [a] -> [a] -> [a]
++ [Char]
"\n\r ") forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall {m :: * -> *}.
PandocMonad m =>
Text
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
updatePositions' )
      forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) a st.
(Stream s m a, HasLastStrPosition st) =>
ParsecT s st m ()
updateLastStrPos
  where
    updatePositions' :: Text
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
updatePositions' Text
str' = Text
str' forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$
      forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall (m :: * -> *) a. MonadPlus m => m a
mzero (forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
updatePositions forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd) (Text -> Maybe (Text, Char)
T.unsnoc Text
str')

-- | An endline character that can be treated as a space, not a structural
-- break.  This should reflect the values of the Emacs variable
-- @org-element-pagaraph-separate@.
endline :: PandocMonad m => OrgParser m (F Inlines)
endline :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
endline = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall (m :: * -> *). Monad m => OrgParser m Char
newline
  forall b s (m :: * -> *) a st.
(Show b, Stream s m a) =>
ParsecT s st m b -> ParsecT s st m ()
notFollowedBy' forall (m :: * -> *). Monad m => OrgParser m ()
endOfBlock
  forall (m :: * -> *). PandocMonad m => OrgParser m ()
decEmphasisNewlinesCount
  forall (f :: * -> *). Alternative f => Bool -> f ()
guard forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (m :: * -> *). PandocMonad m => OrgParser m Bool
newlinesCountWithinLimits
  forall (m :: * -> *). Monad m => OrgParser m ()
updateLastPreCharPos
  Bool
useHardBreaks <- ExportSettings -> Bool
exportPreserveBreaks forall b c a. (b -> c) -> (a -> b) -> a -> c
. OrgParserState -> ExportSettings
orgStateExportSettings forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  forall (m :: * -> *) a s. Monad m => a -> m (Future s a)
returnF (if Bool
useHardBreaks then Inlines
B.linebreak else Inlines
B.softbreak)


--
-- Citations
--

-- We first try to parse official org-cite citations, then fall
-- back to org-ref citations (which are still in wide use).

-- | A citation in org-cite style
orgCite :: PandocMonad m => OrgParser m (F [Citation])
orgCite :: forall (m :: * -> *). PandocMonad m => OrgParser m (F [Citation])
orgCite = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"[cite"
  (CiteStyle
sty, [CiteVariant]
_variants) <- forall (m :: * -> *).
PandocMonad m =>
OrgParser m (CiteStyle, [CiteVariant])
citeStyle
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
':'
  forall (m :: * -> *). PandocMonad m => OrgParser m ()
spnl
  F Inlines
globalPref <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option forall a. Monoid a => a
mempty (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
citePrefix forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
';'))
  F [Citation]
items <- forall (m :: * -> *). PandocMonad m => OrgParser m (F [Citation])
citeItems
  F Inlines
globalSuff <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option forall a. Monoid a => a
mempty (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
';' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
citeSuffix))
  forall (m :: * -> *). PandocMonad m => OrgParser m ()
spnl
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
']'
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ CiteStyle -> F [Citation] -> F [Citation]
adjustCiteStyle CiteStyle
sty forall b c a. (b -> c) -> (a -> b) -> a -> c
.
           F Inlines -> F [Citation] -> F [Citation]
addPrefixToFirstItem F Inlines
globalPref forall b c a. (b -> c) -> (a -> b) -> a -> c
.
           F Inlines -> F [Citation] -> F [Citation]
addSuffixToLastItem F Inlines
globalSuff forall a b. (a -> b) -> a -> b
$ F [Citation]
items

adjustCiteStyle :: CiteStyle -> (F [Citation]) -> (F [Citation])
adjustCiteStyle :: CiteStyle -> F [Citation] -> F [Citation]
adjustCiteStyle CiteStyle
sty F [Citation]
cs = do
  [Citation]
cs' <- F [Citation]
cs
  case [Citation]
cs' of
    [] -> forall (m :: * -> *) a. Monad m => a -> m a
return []
    (Citation
d:[Citation]
ds)  -- TODO needs refinement
      -> case CiteStyle
sty of
         CiteStyle
TextStyle -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Citation
d{ citationMode :: CitationMode
citationMode = CitationMode
AuthorInText
                                , citationSuffix :: [Inline]
citationSuffix = forall a. (a -> Bool) -> [a] -> [a]
dropWhile (forall a. Eq a => a -> a -> Bool
== Inline
Space)
                                    (Citation -> [Inline]
citationSuffix Citation
d)} forall a. a -> [a] -> [a]
: [Citation]
ds
         CiteStyle
NoAuthorStyle -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Citation
d{ citationMode :: CitationMode
citationMode = CitationMode
SuppressAuthor } forall a. a -> [a] -> [a]
: [Citation]
ds
         CiteStyle
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return (Citation
dforall a. a -> [a] -> [a]
:[Citation]
ds)

addPrefixToFirstItem :: (F Inlines) -> (F [Citation]) -> (F [Citation])
addPrefixToFirstItem :: F Inlines -> F [Citation] -> F [Citation]
addPrefixToFirstItem F Inlines
aff F [Citation]
cs = do
  [Citation]
cs' <- F [Citation]
cs
  Inlines
aff' <- F Inlines
aff
  case [Citation]
cs' of
    [] -> forall (m :: * -> *) a. Monad m => a -> m a
return []
    (Citation
d:[Citation]
ds) -> forall (m :: * -> *) a. Monad m => a -> m a
return (Citation
d{ citationPrefix :: [Inline]
citationPrefix =
                          forall a. Many a -> [a]
B.toList Inlines
aff' forall a. Semigroup a => a -> a -> a
<> Citation -> [Inline]
citationPrefix Citation
d }forall a. a -> [a] -> [a]
:[Citation]
ds)

addSuffixToLastItem :: (F Inlines) -> (F [Citation]) -> (F [Citation])
addSuffixToLastItem :: F Inlines -> F [Citation] -> F [Citation]
addSuffixToLastItem F Inlines
aff F [Citation]
cs = do
  [Citation]
cs' <- F [Citation]
cs
  Inlines
aff' <- F Inlines
aff
  case forall a. [a] -> Maybe a
lastMay [Citation]
cs' of
    Maybe Citation
Nothing -> forall (m :: * -> *) a. Monad m => a -> m a
return [Citation]
cs'
    Just Citation
d  ->
      forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. [a] -> [a]
init [Citation]
cs' forall a. [a] -> [a] -> [a]
++ [Citation
d{ citationSuffix :: [Inline]
citationSuffix =
                                Citation -> [Inline]
citationSuffix Citation
d forall a. Semigroup a => a -> a -> a
<> forall a. Many a -> [a]
B.toList Inlines
aff' }])

citeItems :: PandocMonad m => OrgParser m (F [Citation])
citeItems :: forall (m :: * -> *). PandocMonad m => OrgParser m (F [Citation])
citeItems = forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *).
PandocMonad m =>
OrgParser m (Future OrgParserState Citation)
citeItem forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
`sepBy1` (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
';')

citeItem :: PandocMonad m => OrgParser m (F Citation)
citeItem :: forall (m :: * -> *).
PandocMonad m =>
OrgParser m (Future OrgParserState Citation)
citeItem = do
  F Inlines
pref <- forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
citePrefix
  Text
itemKey <- forall (m :: * -> *). PandocMonad m => OrgParser m Text
orgCiteKey
  F Inlines
suff <- forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
citeSuffix
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ do
    Inlines
pre' <- F Inlines
pref
    Inlines
suf' <- F Inlines
suff
    forall (m :: * -> *) a. Monad m => a -> m a
return Citation
      { citationId :: Text
citationId      = Text
itemKey
      , citationPrefix :: [Inline]
citationPrefix  = forall a. Many a -> [a]
B.toList Inlines
pre'
      , citationSuffix :: [Inline]
citationSuffix  = forall a. Many a -> [a]
B.toList Inlines
suf'
      , citationMode :: CitationMode
citationMode    = CitationMode
NormalCitation
      , citationNoteNum :: Int
citationNoteNum = Int
0
      , citationHash :: Int
citationHash    = Int
0
      }

orgCiteKey :: PandocMonad m => OrgParser m Text
orgCiteKey :: forall (m :: * -> *). PandocMonad m => OrgParser m Text
orgCiteKey = do
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'@'
  [Char] -> Text
T.pack forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy Char -> Bool
orgCiteKeyChar)

orgCiteKeyChar :: Char -> Bool
orgCiteKeyChar :: Char -> Bool
orgCiteKeyChar Char
c =
  Char -> Bool
isAlphaNum Char
c Bool -> Bool -> Bool
|| Char
c forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Char
'.',Char
':',Char
'?',Char
'!',Char
'`',Char
'\'',Char
'/',Char
'*',Char
'@',Char
'+',Char
'|',
                            Char
'(',Char
')',Char
'{',Char
'}',Char
'<',Char
'>',Char
'&',Char
'_',Char
'^',Char
'$',Char
'#',
                            Char
'%',Char
'~',Char
'-']

rawAffix :: PandocMonad m => Bool -> OrgParser m Text
rawAffix :: forall (m :: * -> *). PandocMonad m => Bool -> OrgParser m Text
rawAffix Bool
isPrefix = forall a b. (a, b) -> b
snd forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) st a.
Monad m =>
ParsecT Sources st m a -> ParsecT Sources st m (a, Text)
withRaw
  (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many
   (forall {u}. ParsecT Sources u (ReaderT OrgParserLocal m) ()
affixChar
     forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
     forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (f :: * -> *) a. Functor f => f a -> f ()
void (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'[' forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *). PandocMonad m => Bool -> OrgParser m Text
rawAffix Bool
isPrefix forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
']'))))
 where
   affixChar :: ParsecT Sources u (ReaderT OrgParserLocal m) ()
affixChar = forall (f :: * -> *) a. Functor f => f a -> f ()
void forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy forall a b. (a -> b) -> a -> b
$ \Char
c ->
     Bool -> Bool
not (Char
c forall a. Eq a => a -> a -> Bool
== Char
'^' Bool -> Bool -> Bool
|| Char
c forall a. Eq a => a -> a -> Bool
== Char
';' Bool -> Bool -> Bool
|| Char
c forall a. Eq a => a -> a -> Bool
== Char
'[' Bool -> Bool -> Bool
|| Char
c forall a. Eq a => a -> a -> Bool
== Char
']') Bool -> Bool -> Bool
&&
     (Bool -> Bool
not Bool
isPrefix Bool -> Bool -> Bool
|| Char
c forall a. Eq a => a -> a -> Bool
/= Char
'@')

citePrefix :: PandocMonad m => OrgParser m (F Inlines)
citePrefix :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
citePrefix =
  forall (m :: * -> *). PandocMonad m => Bool -> OrgParser m Text
rawAffix Bool
True forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
Monad m =>
OrgParser m a -> Text -> OrgParser m a
parseFromString (forall s. Future s Inlines -> Future s Inlines
trimInlinesF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inline)

citeSuffix :: PandocMonad m => OrgParser m (F Inlines)
citeSuffix :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
citeSuffix =
  forall (m :: * -> *). PandocMonad m => Bool -> OrgParser m Text
rawAffix Bool
False forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
Monad m =>
OrgParser m a -> Text -> OrgParser m a
parseFromString ParsecT
  Sources OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
parseSuffix
 where
   parseSuffix :: ParsecT
  Sources OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
parseSuffix = do
     Bool
hasSpace <- 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 forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
nonspaceChar))
     F Inlines
ils <- forall s. Future s Inlines -> Future s Inlines
trimInlinesF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inline
     forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ if Bool
hasSpace
                 then (Inlines
B.space forall a. Semigroup a => a -> a -> a
<>) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> F Inlines
ils
                 else F Inlines
ils

citeStyle :: PandocMonad m => OrgParser m (CiteStyle, [CiteVariant])
citeStyle :: forall (m :: * -> *).
PandocMonad m =>
OrgParser m (CiteStyle, [CiteVariant])
citeStyle = forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option (CiteStyle
DefStyle, []) forall a b. (a -> b) -> a -> b
$ do
  CiteStyle
sty <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option CiteStyle
DefStyle forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'/' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => OrgParser m CiteStyle
orgCiteStyle
  [CiteVariant]
variants <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'/' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => OrgParser m [CiteVariant]
orgCiteVariants
  forall (m :: * -> *) a. Monad m => a -> m a
return (CiteStyle
sty, [CiteVariant]
variants)

orgCiteStyle :: PandocMonad m => OrgParser m CiteStyle
orgCiteStyle :: forall (m :: * -> *). PandocMonad m => OrgParser m CiteStyle
orgCiteStyle = forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try
  [ CiteStyle
NoAuthorStyle forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"noauthor"
  , CiteStyle
NoAuthorStyle forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"na"
  , CiteStyle
LocatorsStyle forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"locators"
  , CiteStyle
LocatorsStyle forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'l'
  , CiteStyle
NociteStyle forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"nocite"
  , CiteStyle
NociteStyle forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'n'
  , CiteStyle
TextStyle forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"text"
  , CiteStyle
TextStyle forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
't'
  ]

orgCiteVariants :: PandocMonad m => OrgParser m [CiteVariant]
orgCiteVariants :: forall (m :: * -> *). PandocMonad m => OrgParser m [CiteVariant]
orgCiteVariants =
  (forall {u}.
ParsecT Sources u (ReaderT OrgParserLocal m) CiteVariant
fullnameVariant forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
`sepBy1` (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'-')) forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 forall {u}.
ParsecT Sources u (ReaderT OrgParserLocal m) CiteVariant
onecharVariant)
 where
  fullnameVariant :: ParsecT Sources u (ReaderT OrgParserLocal m) CiteVariant
fullnameVariant = forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try
     [ CiteVariant
Bare forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"bare"
     , CiteVariant
Caps forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"caps"
     , CiteVariant
Full forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"full"
     ]
  onecharVariant :: ParsecT Sources u (ReaderT OrgParserLocal m) CiteVariant
onecharVariant = forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
     [ CiteVariant
Bare forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'b'
     , CiteVariant
Caps forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'c'
     , CiteVariant
Full forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'f'
     ]

data CiteStyle =
    NoAuthorStyle
  | LocatorsStyle
  | NociteStyle
  | TextStyle
  | DefStyle
  deriving Int -> CiteStyle -> ShowS
[CiteStyle] -> ShowS
CiteStyle -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [CiteStyle] -> ShowS
$cshowList :: [CiteStyle] -> ShowS
show :: CiteStyle -> [Char]
$cshow :: CiteStyle -> [Char]
showsPrec :: Int -> CiteStyle -> ShowS
$cshowsPrec :: Int -> CiteStyle -> ShowS
Show

data CiteVariant =
    Caps
  | Bare
  | Full
  deriving Int -> CiteVariant -> ShowS
[CiteVariant] -> ShowS
CiteVariant -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [CiteVariant] -> ShowS
$cshowList :: [CiteVariant] -> ShowS
show :: CiteVariant -> [Char]
$cshow :: CiteVariant -> [Char]
showsPrec :: Int -> CiteVariant -> ShowS
$cshowsPrec :: Int -> CiteVariant -> ShowS
Show


spnl :: PandocMonad m => OrgParser m ()
spnl :: forall (m :: * -> *). PandocMonad m => OrgParser m ()
spnl =
  forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (forall (m :: * -> *). Monad m => OrgParser m Char
newline forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
blankline forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces)

cite :: PandocMonad m => OrgParser m (F Inlines)
cite :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
cite = do
  forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_citations
  (F [Citation]
cs, Text
raw) <- forall (m :: * -> *) st a.
Monad m =>
ParsecT Sources st m a -> ParsecT Sources st m (a, Text)
withRaw forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
               [ forall (m :: * -> *). PandocMonad m => OrgParser m (F [Citation])
orgCite
               , forall (m :: * -> *). PandocMonad m => OrgParser m (F [Citation])
orgRefCite
               ]
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a b c. (a -> b -> c) -> b -> a -> c
flip [Citation] -> Inlines -> Inlines
B.cite (Text -> Inlines
B.text Text
raw) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> F [Citation]
cs

-- org-ref

orgRefCite :: PandocMonad m => OrgParser m (F [Citation])
orgRefCite :: forall (m :: * -> *). PandocMonad m => OrgParser m (F [Citation])
orgRefCite = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
  [ forall (m :: * -> *). PandocMonad m => OrgParser m (F [Citation])
normalOrgRefCite
  , forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a. a -> [a] -> [a]
:[]) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *).
PandocMonad m =>
OrgParser m (Future OrgParserState Citation)
linkLikeOrgRefCite
  ]

normalOrgRefCite :: PandocMonad m => OrgParser m (F [Citation])
normalOrgRefCite :: forall (m :: * -> *). PandocMonad m => OrgParser m (F [Citation])
normalOrgRefCite = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  CitationMode
mode <- forall (m :: * -> *). PandocMonad m => OrgParser m CitationMode
orgRefCiteMode
  Future OrgParserState Citation
firstCitation <- forall (m :: * -> *).
PandocMonad m =>
CitationMode -> OrgParser m (Future OrgParserState Citation)
orgRefCiteList CitationMode
mode
  [Future OrgParserState Citation]
moreCitations <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
',' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *).
PandocMonad m =>
CitationMode -> OrgParser m (Future OrgParserState Citation)
orgRefCiteList CitationMode
mode)
  forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence forall a b. (a -> b) -> a -> b
$ Future OrgParserState Citation
firstCitation forall a. a -> [a] -> [a]
: [Future OrgParserState Citation]
moreCitations
 where
  -- A list of org-ref style citation keys, parsed as citation of the given
  -- citation mode.
  orgRefCiteList :: PandocMonad m => CitationMode -> OrgParser m (F Citation)
  orgRefCiteList :: forall (m :: * -> *).
PandocMonad m =>
CitationMode -> OrgParser m (Future OrgParserState Citation)
orgRefCiteList CitationMode
citeMode = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
    Text
key <- forall (m :: * -> *). PandocMonad m => OrgParser m Text
orgRefCiteKey
    forall (m :: * -> *) a s. Monad m => a -> m (Future s a)
returnF Citation
     { citationId :: Text
citationId      = Text
key
     , citationPrefix :: [Inline]
citationPrefix  = forall a. Monoid a => a
mempty
     , citationSuffix :: [Inline]
citationSuffix  = forall a. Monoid a => a
mempty
     , citationMode :: CitationMode
citationMode    = CitationMode
citeMode
     , citationNoteNum :: Int
citationNoteNum = Int
0
     , citationHash :: Int
citationHash    = Int
0
     }

-- | Read a link-like org-ref style citation.  The citation includes pre and
-- post text.  However, multiple citations are not possible due to limitations
-- in the syntax.
linkLikeOrgRefCite :: PandocMonad m => OrgParser m (F Citation)
linkLikeOrgRefCite :: forall (m :: * -> *).
PandocMonad m =>
OrgParser m (Future OrgParserState Citation)
linkLikeOrgRefCite = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  [Char]
_    <- forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"[["
  CitationMode
mode <- forall (m :: * -> *). PandocMonad m => OrgParser m CitationMode
orgRefCiteMode
  Text
key  <- forall (m :: * -> *). PandocMonad m => OrgParser m Text
orgRefCiteKey
  [Char]
_    <- forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"]["
  F Inlines
pre  <- forall s. Future s Inlines -> Future s Inlines
trimInlinesF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
manyTill forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inline (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"::")
  Bool
spc  <- 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 forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar)
  F Inlines
suf  <- forall s. Future s Inlines -> Future s Inlines
trimInlinesF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
manyTill forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inline (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"]]")
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ do
    Inlines
pre' <- F Inlines
pre
    Inlines
suf' <- F Inlines
suf
    forall (m :: * -> *) a. Monad m => a -> m a
return Citation
      { citationId :: Text
citationId      = Text
key
      , citationPrefix :: [Inline]
citationPrefix  = forall a. Many a -> [a]
B.toList Inlines
pre'
      , citationSuffix :: [Inline]
citationSuffix  = forall a. Many a -> [a]
B.toList (if Bool
spc then Inlines
B.space 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
      }

-- | Read a citation key.  The characters allowed in citation keys are taken
-- from the `org-ref-cite-re` variable in `org-ref.el`.
orgRefCiteKey :: PandocMonad m => OrgParser m Text
orgRefCiteKey :: forall (m :: * -> *). PandocMonad m => OrgParser m Text
orgRefCiteKey =
  let citeKeySpecialChars :: [Char]
citeKeySpecialChars = [Char]
"-_:\\./" :: String
      isCiteKeySpecialChar :: Char -> Bool
isCiteKeySpecialChar Char
c = Char
c 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 Sources u (ReaderT OrgParserLocal m) Char
endOfCitation = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
        forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy Char -> Bool
isCiteKeySpecialChar
        forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy forall a b. (a -> b) -> a -> b
$ Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Bool
isCiteKeyChar
  in forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
        forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'&') -- this is used in org-ref v3
        forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy Char -> Bool
isCiteKeyChar forall end s (m :: * -> *) t st.
(Show end, Stream s m t) =>
ParsecT s st m Char -> ParsecT s st m end -> ParsecT s st m Text
`many1TillChar` forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead forall {u}. ParsecT Sources u (ReaderT OrgParserLocal m) Char
endOfCitation

-- | Supported citation types.  Only a small subset of org-ref types is
-- supported for now.  TODO: rewrite this, use LaTeX reader as template.
orgRefCiteMode :: PandocMonad m => OrgParser m CitationMode
orgRefCiteMode :: forall (m :: * -> *). PandocMonad m => OrgParser m CitationMode
orgRefCiteMode =
  forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (\([Char]
s, CitationMode
mode) -> CitationMode
mode forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
s forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s 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)
    ]

footnote :: PandocMonad m => OrgParser m (F Inlines)
footnote :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
footnote = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  F Inlines
note <- forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inlineNote forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
referencedNote
  Bool
withNote <- forall (m :: * -> *) a.
Monad m =>
(ExportSettings -> a) -> OrgParser m a
getExportSetting ExportSettings -> Bool
exportWithFootnotes
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ if Bool
withNote then F Inlines
note else forall a. Monoid a => a
mempty

inlineNote :: PandocMonad m => OrgParser m (F Inlines)
inlineNote :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inlineNote = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"[fn:"
  Text
ref <- forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
manyChar forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
':'
  Future OrgParserState Blocks
note <- forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Blocks
B.para forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s. Future s Inlines -> Future s Inlines
trimInlinesF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParsecT s st m a -> ParsecT s st m end -> ParsecT s st m [a]
many1Till forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inline (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
']')
  forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Text -> Bool
T.null Text
ref) forall a b. (a -> b) -> a -> b
$
       forall (m :: * -> *).
PandocMonad m =>
OrgNoteRecord -> OrgParser m ()
addToNotesTable (Text
"fn:" forall a. Semigroup a => a -> a -> a
<> Text
ref, Future OrgParserState Blocks
note)
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Blocks -> Inlines
B.note forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Future OrgParserState Blocks
note

referencedNote :: PandocMonad m => OrgParser m (F Inlines)
referencedNote :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
referencedNote = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  Text
ref <- forall (m :: * -> *). Monad m => OrgParser m Text
noteMarker
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ do
    OrgNoteTable
notes <- forall s a. (s -> a) -> Future s a
asksF OrgParserState -> OrgNoteTable
orgStateNotes'
    case forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
ref OrgNoteTable
notes of
      Maybe (Future OrgParserState Blocks)
Nothing   -> forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines
B.str forall a b. (a -> b) -> a -> b
$ Text
"[" forall a. Semigroup a => a -> a -> a
<> Text
ref forall a. Semigroup a => a -> a -> a
<> Text
"]"
      Just Future OrgParserState Blocks
contents  -> do
        OrgParserState
st <- forall s. Future s s
askF
        let contents' :: Blocks
contents' = forall s a. Future s a -> s -> a
runF Future OrgParserState Blocks
contents OrgParserState
st{ orgStateNotes' :: OrgNoteTable
orgStateNotes' = [] }
        forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Blocks -> Inlines
B.note Blocks
contents'

linkOrImage :: PandocMonad m => OrgParser m (F Inlines)
linkOrImage :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
linkOrImage = forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
explicitOrImageLink
              forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
selflinkOrImage
              forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
angleLink
              forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
plainLink
              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 :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
explicitOrImageLink = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'['
  F Text
srcF   <- forall (m :: * -> *). Text -> OrgParser m (F Text)
applyCustomLinkFormat forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (m :: * -> *). PandocMonad m => OrgParser m Text
possiblyEmptyLinkTarget
  Text
descr  <- forall (m :: * -> *) b a.
(PandocMonad m, Show b) =>
OrgParser m a -> OrgParser m b -> OrgParser m Text
enclosedRaw (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'[') (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
']')
  F Inlines
titleF <- forall (m :: * -> *) a.
Monad m =>
OrgParser m a -> Text -> OrgParser m a
parseFromString (forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inline) Text
descr
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
']'
  forall (m :: * -> *) a. Monad m => a -> m a
return 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 ->
        forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Inlines -> Inlines
B.link Text
src Text
"" forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines -> Inlines
B.image Text
imgSrc forall a. Monoid a => a
mempty 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 :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
selflinkOrImage = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  Text
target <- forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'[' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => OrgParser m Text
linkTarget forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s 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
_) -> forall (m :: * -> *) a s. Monad m => a -> m (Future s a)
returnF 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)
_             -> forall (m :: * -> *) a. Monad m => a -> m a
return 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 forall (m :: * -> *) a s. Monad m => a -> m (Future s a)
returnF forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines -> Inlines
B.image Text
nonDocTgt Text
"" Inlines
""
                      else forall (m :: * -> *) a s. Monad m => a -> m (Future s a)
returnF 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 :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
plainLink = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  (Text
orig, Text
src) <- forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (Text, Text)
uri
  forall (m :: * -> *) a s. Monad m => a -> m (Future s a)
returnF 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 :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
angleLink = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'<'
  F Inlines
link <- forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
plainLink
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'>'
  forall (m :: * -> *) a. Monad m => a -> m a
return F Inlines
link

linkTarget :: PandocMonad m => OrgParser m Text
linkTarget :: forall (m :: * -> *). PandocMonad m => OrgParser m Text
linkTarget = [Char] -> Text
T.pack forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
PandocMonad m =>
Char -> Char -> OrgParser m a -> OrgParser m [a]
enclosedByPair1 Char
'[' Char
']' (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
noneOf [Char]
"\n\r[]")

possiblyEmptyLinkTarget :: PandocMonad m => OrgParser m Text
possiblyEmptyLinkTarget :: forall (m :: * -> *). PandocMonad m => OrgParser m Text
possiblyEmptyLinkTarget = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall (m :: * -> *). PandocMonad m => OrgParser m Text
linkTarget forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Text
"" forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"[]")

applyCustomLinkFormat :: Text -> OrgParser m (F Text)
applyCustomLinkFormat :: forall (m :: * -> *). Text -> OrgParser m (F Text)
applyCustomLinkFormat Text
link = do
  let (Text
linkType, Text
rest) = (Char -> Bool) -> Text -> (Text, Text)
T.break (forall a. Eq a => a -> a -> Bool
== Char
':') Text
link
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ do
    Maybe (Text -> Text)
formatter <- forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Text
linkType forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s a. (s -> a) -> Future s a
asksF OrgParserState -> OrgLinkFormatters
orgStateLinkFormatters
    forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
link (forall a b. (a -> b) -> a -> b
$ Int -> Text -> Text
T.drop Int
1 Text
rest) Maybe (Text -> Text)
formatter

-- | Take a link and return a function which produces new inlines when given
-- description inlines.
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       -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Inlines -> Inlines
B.link forall a. Monoid a => a
mempty Text
""       -- wiki link (empty by convention)
    Just (Char
'#', Text
_) -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Inlines -> Inlines
B.link Text
linkStr Text
""      -- document-local fraction
    Maybe (Char, Text)
_             -> case Text -> Maybe Text
cleanLinkText Text
linkStr of
      Just Text
extTgt -> forall (m :: * -> *) a. Monad m => a -> m a
return 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  -- other internal link

internalLink :: Text -> Inlines -> F Inlines
internalLink :: Text -> Inlines -> F Inlines
internalLink Text
link Inlines
title = do
  [Text]
ids <- forall s a. (s -> a) -> Future s a
asksF OrgParserState -> [Text]
orgStateAnchorIds
  if Text
link forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Text]
ids
    then forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines -> Inlines
B.link (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 forall (m :: * -> *) a. Monad m => a -> m a
return 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)

-- | Parse an anchor like @<<anchor-id>>@ and return an empty span with
-- @anchor-id@ set as id.  Legal anchors in org-mode are defined through
-- @org-target-regexp@, which is fairly liberal.  Since no link is created if
-- @anchor-id@ contains spaces, we are more restrictive in what is accepted as
-- an anchor.
anchor :: PandocMonad m => OrgParser m (F Inlines)
anchor :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
anchor =  forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  Text
anchorId <- forall {u}. ParsecT Sources u (ReaderT OrgParserLocal m) Text
parseAnchor
  forall (m :: * -> *). PandocMonad m => Text -> OrgParser m ()
recordAnchorId Text
anchorId
  forall (m :: * -> *) a s. Monad m => a -> m (Future s a)
returnF forall a b. (a -> b) -> a -> b
$ (Text, [Text], [(Text, Text)]) -> Inlines -> Inlines
B.spanWith (Text -> Text
solidify Text
anchorId, [], []) forall a. Monoid a => a
mempty
 where
       parseAnchor :: ParsecT Sources u (ReaderT OrgParserLocal m) Text
parseAnchor = forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"<<"
                     forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
noneOf [Char]
"\t\n\r<>\"' ")
                     forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
">>"
                     forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces

-- | Replace every char but [a-zA-Z0-9_.-:] with a hyphen '-'.  This mirrors
-- the org function @org-export-solidify-link-text@.
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 forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` ([Char]
"_.-:" :: String) = Char
c
           | Bool
otherwise       = Char
'-'

-- | Parses an inline code block and marks it as an babel block.
inlineCodeBlock :: PandocMonad m => OrgParser m (F Inlines)
inlineCodeBlock :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inlineCodeBlock = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"src_"
  Text
lang <- forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char forall (m :: * -> *). Monad m => OrgParser m Char
orgArgWordChar
  [(Text, Text)]
opts <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a.
PandocMonad m =>
Char -> Char -> OrgParser m a -> OrgParser m [a]
enclosedByPair Char
'[' Char
']' forall (m :: * -> *). PandocMonad m => OrgParser m (Text, Text)
inlineBlockOption
  Text
inlineCode <- [Char] -> Text
T.pack forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
PandocMonad m =>
Char -> Char -> OrgParser m a -> OrgParser m [a]
enclosedByPair1 Char
'{' Char
'}' (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s 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 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
  forall (m :: * -> *) a s. Monad m => a -> m (Future s a)
returnF forall a b. (a -> b) -> a -> b
$ if [(Text, Text)] -> Bool
exportsCode [(Text, Text)]
opts then Inlines
codeInlineBlck else forall a. Monoid a => a
mempty
 where
   inlineBlockOption :: PandocMonad m => OrgParser m (Text, Text)
   inlineBlockOption :: forall (m :: * -> *). PandocMonad m => OrgParser m (Text, Text)
inlineBlockOption = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
     Text
argKey <- forall (m :: * -> *). Monad m => OrgParser m Text
orgArgKey
     Text
paramValue <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Text
"yes" forall (m :: * -> *). PandocMonad m => OrgParser m Text
orgInlineParamValue
     forall (m :: * -> *) a. Monad m => a -> m a
return (Text
argKey, Text
paramValue)

   orgInlineParamValue :: PandocMonad m => OrgParser m Text
   orgInlineParamValue :: forall (m :: * -> *). PandocMonad m => OrgParser m Text
orgInlineParamValue = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$
     forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces
       forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
':')
       forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
noneOf [Char]
"\t\n\r ]")
       forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces


emphasizedText :: PandocMonad m => OrgParser m (F Inlines)
emphasizedText :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
emphasizedText = do
  OrgParserState
state <- forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  forall (f :: * -> *). Alternative f => Bool -> f ()
guard forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExportSettings -> Bool
exportEmphasizedText forall b c a. (b -> c) -> (a -> b) -> a -> c
. OrgParserState -> ExportSettings
orgStateExportSettings forall a b. (a -> b) -> a -> b
$ OrgParserState
state
  forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
    [ forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
emph
    , forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
strong
    , forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
strikeout
    , forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
underline
    ]

enclosedByPair :: PandocMonad m
               => Char          -- ^ opening char
               -> Char          -- ^ closing char
               -> OrgParser m a   -- ^ parser
               -> OrgParser m [a]
enclosedByPair :: forall (m :: * -> *) a.
PandocMonad m =>
Char -> Char -> OrgParser m a -> OrgParser m [a]
enclosedByPair Char
s Char
e OrgParser m a
p = forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
s forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
manyTill OrgParser m a
p (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
e)

enclosedByPair1 :: PandocMonad m
               => Char          -- ^ opening char
               -> Char          -- ^ closing char
               -> OrgParser m a   -- ^ parser
               -> OrgParser m [a]
enclosedByPair1 :: forall (m :: * -> *) a.
PandocMonad m =>
Char -> Char -> OrgParser m a -> OrgParser m [a]
enclosedByPair1 Char
s Char
e OrgParser m a
p = forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
s forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParsecT s st m a -> ParsecT s st m end -> ParsecT s st m [a]
many1Till OrgParser m a
p (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
e)

emph      :: PandocMonad m => OrgParser m (F Inlines)
emph :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
emph      = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Inlines
B.emph         forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *).
PandocMonad m =>
Char -> OrgParser m (F Inlines)
emphasisBetween Char
'/'

strong    :: PandocMonad m => OrgParser m (F Inlines)
strong :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
strong    = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Inlines
B.strong       forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *).
PandocMonad m =>
Char -> OrgParser m (F Inlines)
emphasisBetween Char
'*'

strikeout :: PandocMonad m => OrgParser m (F Inlines)
strikeout :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
strikeout = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Inlines
B.strikeout    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *).
PandocMonad m =>
Char -> OrgParser m (F Inlines)
emphasisBetween Char
'+'

underline :: PandocMonad m => OrgParser m (F Inlines)
underline :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
underline = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Inlines
B.underline    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *).
PandocMonad m =>
Char -> OrgParser m (F Inlines)
emphasisBetween Char
'_'

verbatim  :: PandocMonad m => OrgParser m (F Inlines)
verbatim :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
verbatim  = forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text, [Text], [(Text, Text)]) -> Text -> Inlines
B.codeWith (Text
"", [Text
"verbatim"], []) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Text
verbatimBetween Char
'='

code      :: PandocMonad m => OrgParser m (F Inlines)
code :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
code      = forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines
B.code     forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Text
verbatimBetween Char
'~'

subscript   :: PandocMonad m => OrgParser m (F Inlines)
subscript :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
subscript   = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Inlines
B.subscript   forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'_' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
subOrSuperExpr)

superscript :: PandocMonad m => OrgParser m (F Inlines)
superscript :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
superscript = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Inlines
B.superscript forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'^' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
subOrSuperExpr)

math      :: PandocMonad m => OrgParser m (F Inlines)
math :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
math      = forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines
B.math      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [ forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Text
math1CharBetween Char
'$'
                                            , forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Text
mathTextBetween Char
'$'
                                            , forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> OrgParser m Text
rawMathBetween Text
"\\(" Text
"\\)"
                                            ]

displayMath :: PandocMonad m => OrgParser m (F Inlines)
displayMath :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
displayMath = forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines
B.displayMath forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [ forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> OrgParser m Text
rawMathBetween Text
"\\[" Text
"\\]"
                                                , forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> OrgParser m Text
rawMathBetween Text
"$$"  Text
"$$"
                                                ]

updatePositions :: PandocMonad m
                => Char
                -> OrgParser m Char
updatePositions :: forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
updatePositions Char
c = do
  OrgParserState
st <- forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  let emphasisPreChars :: [Char]
emphasisPreChars = OrgParserState -> [Char]
orgStateEmphasisPreChars OrgParserState
st
  forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Char
c forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Char]
emphasisPreChars) forall (m :: * -> *). Monad m => OrgParser m ()
updateLastPreCharPos
  forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Char
c forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Char]
emphasisForbiddenBorderChars) forall (m :: * -> *). Monad m => OrgParser m ()
updateLastForbiddenCharPos
  forall (m :: * -> *) a. Monad m => a -> m a
return Char
c

symbol :: PandocMonad m => OrgParser m (F Inlines)
symbol :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
symbol = forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines
B.str forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Text
T.singleton forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
oneOf [Char]
specialChars forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
updatePositions)

emphasisBetween :: PandocMonad m
                => Char
                -> OrgParser m (F Inlines)
emphasisBetween :: forall (m :: * -> *).
PandocMonad m =>
Char -> OrgParser m (F Inlines)
emphasisBetween Char
c = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall (m :: * -> *). PandocMonad m => Int -> OrgParser m ()
startEmphasisNewlinesCounting Int
emphasisAllowedNewlines
  F Inlines
res <- forall (m :: * -> *) b a.
(PandocMonad m, Show b) =>
OrgParser m a -> OrgParser m b -> OrgParser m (F Inlines)
enclosedInlines (forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
emphasisStart Char
c) (forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
emphasisEnd Char
c)
  Bool
isTopLevelEmphasis <- forall (t :: * -> *) a. Foldable t => t a -> Bool
null forall b c a. (b -> c) -> (a -> b) -> a -> c
. OrgParserState -> [Char]
orgStateEmphasisCharStack forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
isTopLevelEmphasis
       forall (m :: * -> *). PandocMonad m => OrgParser m ()
resetEmphasisNewlines
  forall (m :: * -> *) a. Monad m => a -> m a
return F Inlines
res

verbatimBetween :: PandocMonad m
                => Char
                -> OrgParser m Text
verbatimBetween :: forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Text
verbatimBetween Char
c = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$
  forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
emphasisStart Char
c forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
  forall (m :: * -> *) a.
PandocMonad m =>
Int -> OrgParser m Char -> OrgParser m a -> OrgParser m Text
many1TillNOrLessNewlines Int
1 ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
verbatimChar (forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
emphasisEnd Char
c)
 where
   verbatimChar :: ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
verbatimChar = forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
noneOf [Char]
"\n\r" forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
updatePositions

-- | Parses a raw string delimited by @c@ using Org's math rules
mathTextBetween :: PandocMonad m
                  => Char
                  -> OrgParser m Text
mathTextBetween :: forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Text
mathTextBetween Char
c = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
mathStart Char
c
  Text
body <- forall (m :: * -> *) a.
PandocMonad m =>
Int -> OrgParser m Char -> OrgParser m a -> OrgParser m Text
many1TillNOrLessNewlines Int
mathAllowedNewlines
                                   (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
noneOf (Char
cforall a. a -> [a] -> [a]
:[Char]
"\n\r"))
                                   (forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
mathEnd Char
c)
  Char
final <- forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
mathEnd Char
c
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text -> Char -> Text
T.snoc Text
body Char
final

-- | Parse a single character between @c@ using math rules
math1CharBetween :: PandocMonad m
                 => Char
                -> OrgParser m Text
math1CharBetween :: forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Text
math1CharBetween Char
c = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
c
  Char
res <- forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
noneOf forall a b. (a -> b) -> a -> b
$ Char
cforall a. a -> [a] -> [a]
:[Char]
mathForbiddenBorderChars
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
c
  forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> () forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
oneOf [Char]
mathPostChars)
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Char -> Text
T.singleton Char
res

rawMathBetween :: PandocMonad m
               => Text
               -> Text
               -> OrgParser m Text
rawMathBetween :: forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> OrgParser m Text
rawMathBetween Text
s Text
e = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
textStr Text
s forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) t st a.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m a -> ParsecT s st m Text
manyTillChar forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
textStr Text
e)

-- | Parses the start (opening character) of emphasis
emphasisStart :: PandocMonad m => Char -> OrgParser m Char
emphasisStart :: forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
emphasisStart Char
c = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall (f :: * -> *). Alternative f => Bool -> f ()
guard forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (m :: * -> *). PandocMonad m => OrgParser m Bool
afterEmphasisPreChar
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
c
  forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
noneOf [Char]
emphasisForbiddenBorderChars)
  forall (m :: * -> *). PandocMonad m => Char -> OrgParser m ()
pushToInlineCharStack Char
c
  -- nested inlines are allowed, so mark this position as one which might be
  -- followed by another inline.
  forall (m :: * -> *). Monad m => OrgParser m ()
updateLastPreCharPos
  forall (m :: * -> *) a. Monad m => a -> m a
return Char
c

-- | Parses the closing character of emphasis
emphasisEnd :: PandocMonad m => Char -> OrgParser m Char
emphasisEnd :: forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
emphasisEnd Char
c = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall (f :: * -> *). Alternative f => Bool -> f ()
guard forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (m :: * -> *). PandocMonad m => OrgParser m Bool
notAfterForbiddenBorderChar
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
c
  forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> () forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
acceptablePostChars
  forall s (m :: * -> *) a st.
(Stream s m a, HasLastStrPosition st) =>
ParsecT s st m ()
updateLastStrPos
  forall (m :: * -> *). PandocMonad m => OrgParser m ()
popInlineCharStack
  forall (m :: * -> *) a. Monad m => a -> m a
return Char
c
 where
  acceptablePostChars :: ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
acceptablePostChars = do
    [Char]
emphasisPostChars <- OrgParserState -> [Char]
orgStateEmphasisPostChars forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
    forall (m :: * -> *). PandocMonad m => OrgParser m [Char]
surroundingEmphasisChar forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \[Char]
x -> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
oneOf ([Char]
x forall a. [a] -> [a] -> [a]
++ [Char]
emphasisPostChars)

mathStart :: PandocMonad m => Char -> OrgParser m Char
mathStart :: forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
mathStart Char
c = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
c forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall b s (m :: * -> *) a st.
(Show b, Stream s m a) =>
ParsecT s st m b -> ParsecT s st m ()
notFollowedBy' (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
oneOf (Char
cforall a. a -> [a] -> [a]
:[Char]
mathForbiddenBorderChars))

mathEnd :: PandocMonad m => Char -> OrgParser m Char
mathEnd :: forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
mathEnd Char
c = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  Char
res <- forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
noneOf (Char
cforall a. a -> [a] -> [a]
:[Char]
mathForbiddenBorderChars)
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
c
  forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> () forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
oneOf [Char]
mathPostChars)
  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 :: forall (m :: * -> *) b a.
(PandocMonad m, Show b) =>
OrgParser m a -> OrgParser m b -> OrgParser m (F Inlines)
enclosedInlines OrgParser m a
start OrgParser m b
end = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$
  forall s. Future s Inlines -> Future s Inlines
trimInlinesF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall end s (m :: * -> *) st t a.
(Show end, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m t
-> ParsecT s st m end -> ParsecT s st m a -> ParsecT s st m [a]
enclosed OrgParser m a
start OrgParser m b
end forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inline

enclosedRaw :: (PandocMonad m, Show b) => OrgParser m a
            -> OrgParser m b
            -> OrgParser m Text
enclosedRaw :: forall (m :: * -> *) b a.
(PandocMonad m, Show b) =>
OrgParser m a -> OrgParser m b -> OrgParser m Text
enclosedRaw OrgParser m a
start OrgParser m b
end = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$
  OrgParser m a
start forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
onSingleLine forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
spanningTwoLines)
 where onSingleLine :: ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
onSingleLine = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall end s (m :: * -> *) t st.
(Show end, Stream s m t) =>
ParsecT s st m Char -> ParsecT s st m end -> ParsecT s st m Text
many1TillChar (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
noneOf [Char]
"\n\r") OrgParser m b
end
       spanningTwoLines :: ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
spanningTwoLines = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$
         forall (m :: * -> *). Monad m => OrgParser m Text
anyLine forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Text
f -> forall a. Monoid a => a -> a -> a
mappend (Text
f forall a. Semigroup a => a -> a -> a
<> Text
" ") forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
onSingleLine

-- | Like many1Till, but parses at most @n+1@ lines.  @p@ must not consume
--   newlines.
many1TillNOrLessNewlines :: PandocMonad m => Int
                         -> OrgParser m Char
                         -> OrgParser m a
                         -> OrgParser m Text
many1TillNOrLessNewlines :: forall (m :: * -> *) a.
PandocMonad m =>
Int -> OrgParser m Char -> OrgParser m a -> OrgParser m Text
many1TillNOrLessNewlines Int
n OrgParser m Char
p OrgParser m a
end = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$
  forall {a}.
(Eq a, Num a) =>
Maybe a
-> [Char]
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Char]
nMoreLines (forall a. a -> Maybe a
Just Int
n) forall a. Monoid a => a
mempty forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall {f :: * -> *}. Alternative f => [Char] -> f Text
oneOrMore
 where
   nMoreLines :: Maybe a
-> [Char]
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Char]
nMoreLines Maybe a
Nothing  [Char]
cs = forall (m :: * -> *) a. Monad m => a -> m a
return [Char]
cs
   nMoreLines (Just a
0) [Char]
cs = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ ([Char]
cs forall a. [a] -> [a] -> [a]
++) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Char]
finalLine
   nMoreLines Maybe a
k        [Char]
cs = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ (forall {p} {a}.
p
-> [Char]
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) (Maybe a, [Char])
final Maybe a
k [Char]
cs forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall {b} {f :: * -> *}.
(Num b, Functor f) =>
f b
-> [Char]
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) (f b, [Char])
rest Maybe a
k [Char]
cs)
                                  forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Maybe a
-> [Char]
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Char]
nMoreLines
   final :: p
-> [Char]
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) (Maybe a, [Char])
final p
_ [Char]
cs = (\[Char]
x -> (forall a. Maybe a
Nothing,      [Char]
cs forall a. [a] -> [a] -> [a]
++ [Char]
x)) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Char]
finalLine
   rest :: f b
-> [Char]
-> ParsecT
     Sources OrgParserState (ReaderT OrgParserLocal m) (f b, [Char])
rest  f b
m [Char]
cs = (\[Char]
x -> (forall {a}. Num a => a -> a
minus1 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f b
m, [Char]
cs forall a. [a] -> [a] -> [a]
++ [Char]
x forall a. [a] -> [a] -> [a]
++ [Char]
"\n")) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
manyTill OrgParser m Char
p forall (m :: * -> *). Monad m => OrgParser m Char
newline)
   finalLine :: ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) [Char]
finalLine = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
manyTill OrgParser m Char
p OrgParser m a
end
   minus1 :: a -> a
minus1 a
k = a
k forall a. Num a => a -> a -> a
- a
1
   oneOrMore :: [Char] -> f Text
oneOrMore [Char]
cs = [Char] -> Text
T.pack [Char]
cs forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Bool
not forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Char]
cs)

-- Org allows customization of the way it reads emphasis.  We use the defaults
-- here (see, e.g., the Emacs Lisp variable `org-emphasis-regexp-components`
-- for details).

-- | Chars not allowed at the (inner) border of emphasis
emphasisForbiddenBorderChars :: [Char]
emphasisForbiddenBorderChars :: [Char]
emphasisForbiddenBorderChars = [Char]
"\t\n\r \x200B"

-- | The maximum number of newlines within
emphasisAllowedNewlines :: Int
emphasisAllowedNewlines :: Int
emphasisAllowedNewlines = Int
1

-- LaTeX-style math: see `org-latex-regexps` for details

-- | Chars allowed after an inline ($...$) math statement
mathPostChars :: [Char]
mathPostChars :: [Char]
mathPostChars = [Char]
"\t\n \"'),-.:;?"

-- | Chars not allowed at the (inner) border of math
mathForbiddenBorderChars :: [Char]
mathForbiddenBorderChars :: [Char]
mathForbiddenBorderChars = [Char]
"\t\n\r ,;.$"

-- | Maximum number of newlines in an inline math statement
mathAllowedNewlines :: Int
mathAllowedNewlines :: Int
mathAllowedNewlines = Int
2

-- | Whether we are right behind a char allowed before emphasis
afterEmphasisPreChar :: PandocMonad m => OrgParser m Bool
afterEmphasisPreChar :: forall (m :: * -> *). PandocMonad m => OrgParser m Bool
afterEmphasisPreChar = do
  SourcePos
pos <- forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
  Maybe SourcePos
lastPrePos <- OrgParserState -> Maybe SourcePos
orgStateLastPreCharPos forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
True (forall a. Eq a => a -> a -> Bool
== SourcePos
pos) Maybe SourcePos
lastPrePos

-- | Whether the parser is right after a forbidden border char
notAfterForbiddenBorderChar :: PandocMonad m => OrgParser m Bool
notAfterForbiddenBorderChar :: forall (m :: * -> *). PandocMonad m => OrgParser m Bool
notAfterForbiddenBorderChar = do
  SourcePos
pos <- forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
  Maybe SourcePos
lastFBCPos <- OrgParserState -> Maybe SourcePos
orgStateLastForbiddenCharPos forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Maybe SourcePos
lastFBCPos forall a. Eq a => a -> a -> Bool
/= forall a. a -> Maybe a
Just SourcePos
pos

-- | Read a sub- or superscript expression
subOrSuperExpr :: PandocMonad m => OrgParser m (F Inlines)
subOrSuperExpr :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
subOrSuperExpr = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$
  forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
simpleSubOrSuperText forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
  (forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [ forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
Char -> Char -> ParsecT s st m Text -> ParsecT s st m Text
charsInBalanced Char
'{' Char
'}' (Char -> Text
T.singleton forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
noneOf [Char]
"\n\r")
          , (Char, Char) -> Text -> Text
enclosing (Char
'(', Char
')') forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
Char -> Char -> ParsecT s st m Text -> ParsecT s st m Text
charsInBalanced Char
'(' Char
')' (Char -> Text
T.singleton forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
noneOf [Char]
"\n\r")
          ] forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
Monad m =>
OrgParser m a -> Text -> OrgParser m a
parseFromString (forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many 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 forall a b. (a -> b) -> a -> b
$ Text -> Char -> Text
T.snoc Text
s Char
right

simpleSubOrSuperText :: PandocMonad m => OrgParser m (F Inlines)
simpleSubOrSuperText :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
simpleSubOrSuperText = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  OrgParserState
state <- forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  forall (f :: * -> *). Alternative f => Bool -> f ()
guard forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExportSettings -> Bool
exportSubSuperscripts forall b c a. (b -> c) -> (a -> b) -> a -> c
. OrgParserState -> ExportSettings
orgStateExportSettings forall a b. (a -> b) -> a -> b
$ OrgParserState
state
  forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines
B.str forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
    forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [ forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
textStr Text
"*"
           , forall a. Monoid a => a -> a -> a
mappend forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Text
"" (Char -> Text
T.singleton forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
oneOf [Char]
"+-")
                     forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum
           ]

inlineLaTeX :: PandocMonad m => OrgParser m (F Inlines)
inlineLaTeX :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inlineLaTeX = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  Text
cmd <- forall (m :: * -> *). PandocMonad m => OrgParser m Text
inlineLaTeXCommand
  TeXExport
texOpt <- forall (m :: * -> *) a.
Monad m =>
(ExportSettings -> a) -> OrgParser m a
getExportSetting ExportSettings -> TeXExport
exportWithLatex
  Bool
allowEntities <- forall (m :: * -> *) a.
Monad m =>
(ExportSettings -> a) -> OrgParser m a
getExportSetting ExportSettings -> Bool
exportWithEntities
  Maybe Inlines
ils <- forall (m :: * -> *).
PandocMonad m =>
Text -> TeXExport -> OrgParser m (Maybe Inlines)
parseAsInlineLaTeX Text
cmd TeXExport
texOpt
  forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall (m :: * -> *) a. MonadPlus m => m a
mzero forall (m :: * -> *) a s. Monad m => a -> m (Future s a)
returnF forall a b. (a -> b) -> a -> b
$
     Bool -> Text -> Maybe Inlines
parseAsMathMLSym Bool
allowEntities Text
cmd forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus`
     Text -> TeXExport -> Maybe Inlines
parseAsMath Text
cmd TeXExport
texOpt 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 :: forall (m :: * -> *).
PandocMonad m =>
Text -> TeXExport -> OrgParser m (Maybe Inlines)
parseAsInlineLaTeX Text
cs = \case
     TeXExport
TeXExport -> forall a b. Either a b -> Maybe b
maybeRight forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> u -> [Char] -> s -> m (Either ParseError a)
runParserT forall (m :: * -> *).
PandocMonad m =>
ParsecT Sources ParserState m Inlines
inlineCommand ParserState
state [Char]
"" (forall a. ToSources a => a -> Sources
toSources Text
cs)
     TeXExport
TeXIgnore -> forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. a -> Maybe a
Just forall a. Monoid a => a
mempty)
     TeXExport
TeXVerbatim -> forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. a -> Maybe a
Just 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
     -- drop initial backslash and any trailing "{}"
     let clean :: Text -> Text
clean = (Char -> Bool) -> Text -> Text
T.dropWhileEnd (forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` ([Char]
"{}" :: String)) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Text -> Text
T.drop Int
1
     -- If entities are disabled, then return the string as text, but
     -- only if this *is* a MathML entity.
     case Text -> Inlines
B.str 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 -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.str Text
cs
       Maybe Inlines
x -> Maybe Inlines
x

   state :: ParserState
   state :: ParserState
state = forall a. Default a => a
def{ stateOptions :: ReaderOptions
stateOptions = forall a. Default a => a
def{ readerExtensions :: Extensions
readerExtensions =
                    Extension -> Extensions -> Extensions
enableExtension Extension
Ext_raw_tex (ReaderOptions -> Extensions
readerExtensions forall a. Default a => a
def) } }

   parseAsMath :: Text -> TeXExport -> Maybe Inlines
   parseAsMath :: Text -> TeXExport -> Maybe Inlines
parseAsMath Text
cs = \case
     TeXExport
TeXExport -> forall a b. Either a b -> Maybe b
maybeRight (Text -> Either Text [Exp]
readTeX Text
cs) forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
                  forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. [a] -> Many a
B.fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
. DisplayType -> [Exp] -> Maybe [Inline]
writePandoc DisplayType
DisplayInline
     TeXExport
TeXIgnore -> forall a. a -> Maybe a
Just forall a. Monoid a => a
mempty
     TeXExport
TeXVerbatim -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.str Text
cs

maybeRight :: Either a b -> Maybe b
maybeRight :: forall a b. Either a b -> Maybe b
maybeRight = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall a b. a -> b -> a
const forall a. Maybe a
Nothing) forall a. a -> Maybe a
Just

inlineLaTeXCommand :: PandocMonad m => OrgParser m Text
inlineLaTeXCommand :: forall (m :: * -> *). PandocMonad m => OrgParser m Text
inlineLaTeXCommand = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  Sources
rest <- forall (m :: * -> *) s u. Monad m => ParsecT s u m s
getInput
  OrgParserState
st <- forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  Either ParseError Text
parsed <- (forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift) forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> u -> [Char] -> s -> m (Either ParseError a)
runParserT forall (m :: * -> *) s.
(PandocMonad m, HasMacros s, HasReaderOptions s) =>
ParsecT Sources s m Text
rawLaTeXInline OrgParserState
st [Char]
"source" Sources
rest
  case Either ParseError Text
parsed of
    Right Text
cs -> do
      -- drop any trailing whitespace, those are not part of the command as
      -- far as org mode is concerned.
      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
      forall s (m :: * -> *) t u a.
Stream s m t =>
Int -> ParsecT s u m a -> ParsecT s u m [a]
count Int
len forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar
      forall (m :: * -> *) a. Monad m => a -> m a
return Text
cmdNoSpc
    Either ParseError Text
_ -> forall (m :: * -> *) a. MonadPlus m => m a
mzero

exportSnippet :: PandocMonad m => OrgParser m (F Inlines)
exportSnippet :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
exportSnippet = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"@@"
  Text
format <- forall end s (m :: * -> *) t st.
(Show end, Stream s m t) =>
ParsecT s st m Char -> ParsecT s st m end -> ParsecT s st m Text
many1TillChar (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'-') (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
':')
  Text
snippet <- forall s (m :: * -> *) t st a.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m a -> ParsecT s st m Text
manyTillChar forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"@@")
  forall (m :: * -> *) a s. Monad m => a -> m (Future s a)
returnF forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines
B.rawInline Text
format Text
snippet

macro :: PandocMonad m => OrgParser m (F Inlines)
macro :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
macro = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  Int
recursionDepth <- OrgParserState -> Int
orgStateMacroDepth forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  forall (f :: * -> *). Alternative f => Bool -> f ()
guard forall a b. (a -> b) -> a -> b
$ Int
recursionDepth forall a. Ord a => a -> a -> Bool
< Int
15
  forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"{{{"
  Text
name <- forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
manyChar forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum
  [Text]
args <- ([] forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
"}}}")
          forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'(' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall {st}. ParsecT Sources st (ReaderT OrgParserLocal m) Text
argument forall s (m :: * -> *) t u a sep.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m sep -> ParsecT s u m [a]
`sepBy` forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
',' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall {u}. ParsecT Sources u (ReaderT OrgParserLocal m) [Char]
eoa
  Maybe MacroExpander
expander <- Text -> OrgParserState -> Maybe MacroExpander
lookupMacro Text
name forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  case Maybe MacroExpander
expander of
    Maybe MacroExpander
Nothing -> forall (m :: * -> *) a. MonadPlus m => m a
mzero
    Just MacroExpander
fn -> do
      forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \OrgParserState
s -> OrgParserState
s { orgStateMacroDepth :: Int
orgStateMacroDepth = Int
recursionDepth forall a. Num a => a -> a -> a
+ Int
1 }
      F Inlines
res <- forall (m :: * -> *) a.
Monad m =>
OrgParser m a -> Text -> OrgParser m a
parseFromString (forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inline) forall a b. (a -> b) -> a -> b
$ MacroExpander
fn [Text]
args
      forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \OrgParserState
s -> OrgParserState
s { orgStateMacroDepth :: Int
orgStateMacroDepth = Int
recursionDepth }
      forall (m :: * -> *) a. Monad m => a -> m a
return F Inlines
res
 where
  argument :: ParsecT Sources st (ReaderT OrgParserLocal m) Text
argument = forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
manyChar forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy forall {u}. ParsecT Sources u (ReaderT OrgParserLocal m) [Char]
eoa forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (forall {u}. ParsecT Sources u (ReaderT OrgParserLocal m) Char
escapedComma forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
noneOf [Char]
",")
  escapedComma :: ParsecT Sources u (ReaderT OrgParserLocal m) Char
escapedComma = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'\\' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
oneOf [Char]
",\\"
  eoa :: ParsecT Sources u (ReaderT OrgParserLocal m) [Char]
eoa = forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m [Char]
string [Char]
")}}}"

smart :: PandocMonad m => OrgParser m (F Inlines)
smart :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
smart = forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
doubleQuoted, forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
singleQuoted, forall {s}.
ParsecT
  Sources
  OrgParserState
  (ReaderT OrgParserLocal m)
  (Future s Inlines)
orgApostrophe, ParsecT
  Sources OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
orgDash, ParsecT
  Sources OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
orgEllipses]
  where
    orgDash :: ParsecT
  Sources OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
orgDash = do
      forall (m :: * -> *). PandocMonad m => Bool -> OrgParser m ()
guardOrSmartEnabled forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (m :: * -> *) a.
Monad m =>
(ExportSettings -> a) -> OrgParser m a
getExportSetting ExportSettings -> Bool
exportSpecialStrings
      forall (f :: * -> *) a. Applicative f => a -> f a
pure forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall st s (m :: * -> *).
(HasReaderOptions st, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Inlines
dash forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
updatePositions Char
'-'
    orgEllipses :: ParsecT
  Sources OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
orgEllipses = do
      forall (m :: * -> *). PandocMonad m => Bool -> OrgParser m ()
guardOrSmartEnabled forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (m :: * -> *) a.
Monad m =>
(ExportSettings -> a) -> OrgParser m a
getExportSetting ExportSettings -> Bool
exportSpecialStrings
      forall (f :: * -> *) a. Applicative f => a -> f a
pure forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Inlines
ellipses forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
updatePositions Char
'.'
    orgApostrophe :: ParsecT
  Sources
  OrgParserState
  (ReaderT OrgParserLocal m)
  (Future s Inlines)
orgApostrophe = do
      forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParsecT s st m ()
guardEnabled Extension
Ext_smart
      (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'\'' forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'\8217') forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *). Monad m => OrgParser m ()
updateLastPreCharPos
                                   forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *). Monad m => OrgParser m ()
updateLastForbiddenCharPos
      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 :: forall (m :: * -> *). PandocMonad m => Bool -> OrgParser m ()
guardOrSmartEnabled Bool
b = do
  Bool
smartExtension <- Extension -> Extensions -> Bool
extensionEnabled Extension
Ext_smart forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall st s (m :: * -> *) t b.
(HasReaderOptions st, Stream s m t) =>
(ReaderOptions -> b) -> ParsecT s st m b
getOption ReaderOptions -> Extensions
readerExtensions
  forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool
b Bool -> Bool -> Bool
|| Bool
smartExtension)

singleQuoted :: PandocMonad m => OrgParser m (F Inlines)
singleQuoted :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
singleQuoted = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall (m :: * -> *). PandocMonad m => Bool -> OrgParser m ()
guardOrSmartEnabled forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (m :: * -> *) a.
Monad m =>
(ExportSettings -> a) -> OrgParser m a
getExportSetting ExportSettings -> Bool
exportSmartQuotes
  forall st (m :: * -> *) s.
(HasLastStrPosition st, HasQuoteContext st m, Stream s m Char,
 UpdateSourcePos s Char) =>
ParsecT s st m ()
singleQuoteStart
  forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
updatePositions Char
'\''
  forall st (m :: * -> *) s a.
HasQuoteContext st m =>
QuoteContext -> ParsecT s st m a -> ParsecT s st m a
withQuoteContext QuoteContext
InSingleQuote forall a b. (a -> b) -> a -> b
$
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Inlines
B.singleQuoted forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s. Future s Inlines -> Future s Inlines
trimInlinesF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
      forall end s (m :: * -> *) t st a.
(Show end, Stream s m t) =>
ParsecT s st m a -> ParsecT s st m end -> ParsecT s st m [a]
many1Till forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inline (forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
singleQuoteEnd forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
updatePositions Char
'\'')

-- doubleQuoted will handle regular double-quoted sections, as well
-- as dialogues with an open double-quote without a close double-quote
-- in the same paragraph.
doubleQuoted :: PandocMonad m => OrgParser m (F Inlines)
doubleQuoted :: forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
doubleQuoted = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
  forall (m :: * -> *). PandocMonad m => Bool -> OrgParser m ()
guardOrSmartEnabled forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (m :: * -> *) a.
Monad m =>
(ExportSettings -> a) -> OrgParser m a
getExportSetting ExportSettings -> Bool
exportSmartQuotes
  forall st (m :: * -> *) s.
(HasLastStrPosition st, HasQuoteContext st m, Stream s m Char,
 UpdateSourcePos s Char) =>
ParsecT s st m ()
doubleQuoteStart
  forall (m :: * -> *). PandocMonad m => Char -> OrgParser m Char
updatePositions Char
'"'
  F Inlines
contents <- forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
doubleQuoteEnd forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *). PandocMonad m => OrgParser m (F Inlines)
inline)
  let doubleQuotedContent :: ParsecT
  Sources OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
doubleQuotedContent = forall st (m :: * -> *) s a.
HasQuoteContext st m =>
QuoteContext -> ParsecT s st m a -> ParsecT s st m a
withQuoteContext QuoteContext
InDoubleQuote forall a b. (a -> b) -> a -> b
$ do
        forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
doubleQuoteEnd
        forall (m :: * -> *). Monad m => OrgParser m ()
updateLastForbiddenCharPos
        forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Inlines
B.doubleQuoted forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s. Future s Inlines -> Future s Inlines
trimInlinesF forall a b. (a -> b) -> a -> b
$ F Inlines
contents
  let leftQuoteAndContent :: ParsecT
  Sources OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
leftQuoteAndContent = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Applicative f => a -> f a
pure (Text -> Inlines
B.str Text
"\8220") forall a. Semigroup a => a -> a -> a
<> F Inlines
contents
  ParsecT
  Sources OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
doubleQuotedContent forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT
  Sources OrgParserState (ReaderT OrgParserLocal m) (F Inlines)
leftQuoteAndContent