{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE ViewPatterns #-}
module Text.Pandoc.Readers.Mdoc (readMdoc) where
import Data.Char (isAsciiLower, toUpper)
import Data.Default (Default)
import Data.Either (fromRight)
import Data.Functor (($>))
import Data.Maybe (catMaybes)
import Control.Monad (mplus, guard, void, when, unless)
import Control.Monad.Except (throwError)
#if MIN_VERSION_base(4,19,0)
import Data.List (intersperse, unsnoc)
#else
import Data.List (intersperse)
#endif
import qualified Data.Map.Strict as M
import qualified Data.Text as T
import Text.Pandoc.Definition (Pandoc(Pandoc), Meta)
import Text.Pandoc.Builder (Blocks, Inlines)
import qualified Text.Pandoc.Builder as B
import Text.Pandoc.Class.PandocMonad (PandocMonad(..))
import Text.Pandoc.Options
import Text.Pandoc.Parsing hiding (uncons)
import Text.Pandoc.Logging
import Text.Pandoc.Readers.Mdoc.Lex
import Text.Pandoc.Readers.Mdoc.Standards
import Text.Parsec (modifyState)
import qualified Text.Pandoc.Parsing as P
import qualified Data.Foldable as Foldable
import Text.Pandoc.Shared (stringify)
#if !MIN_VERSION_base(4,19,0)
unsnoc :: [a] -> Maybe ([a], a)
unsnoc = foldr (\x -> Just . maybe ([], x) (\(~(a, b)) -> (x : a, b))) Nothing
#endif
data MdocSection
= ShName
| ShSynopsis
| ShAuthors
| ShSeeAlso
| ShOther
deriving (Int -> MdocSection -> ShowS
[MdocSection] -> ShowS
MdocSection -> String
(Int -> MdocSection -> ShowS)
-> (MdocSection -> String)
-> ([MdocSection] -> ShowS)
-> Show MdocSection
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MdocSection -> ShowS
showsPrec :: Int -> MdocSection -> ShowS
$cshow :: MdocSection -> String
show :: MdocSection -> String
$cshowList :: [MdocSection] -> ShowS
showList :: [MdocSection] -> ShowS
Show, MdocSection -> MdocSection -> Bool
(MdocSection -> MdocSection -> Bool)
-> (MdocSection -> MdocSection -> Bool) -> Eq MdocSection
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MdocSection -> MdocSection -> Bool
== :: MdocSection -> MdocSection -> Bool
$c/= :: MdocSection -> MdocSection -> Bool
/= :: MdocSection -> MdocSection -> Bool
Eq)
data ReferenceField =
Author
| ArticleTitle
| BookTitle
| Publisher
| Journal
| TechReportTitle
| IssueNumber
|
| Url
| Pages
| Institution
| PubLocation
| PubDate
| Optional
deriving (Int -> ReferenceField -> ShowS
[ReferenceField] -> ShowS
ReferenceField -> String
(Int -> ReferenceField -> ShowS)
-> (ReferenceField -> String)
-> ([ReferenceField] -> ShowS)
-> Show ReferenceField
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ReferenceField -> ShowS
showsPrec :: Int -> ReferenceField -> ShowS
$cshow :: ReferenceField -> String
show :: ReferenceField -> String
$cshowList :: [ReferenceField] -> ShowS
showList :: [ReferenceField] -> ShowS
Show, ReferenceField -> ReferenceField -> Bool
(ReferenceField -> ReferenceField -> Bool)
-> (ReferenceField -> ReferenceField -> Bool) -> Eq ReferenceField
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ReferenceField -> ReferenceField -> Bool
== :: ReferenceField -> ReferenceField -> Bool
$c/= :: ReferenceField -> ReferenceField -> Bool
/= :: ReferenceField -> ReferenceField -> Bool
Eq, Eq ReferenceField
Eq ReferenceField =>
(ReferenceField -> ReferenceField -> Ordering)
-> (ReferenceField -> ReferenceField -> Bool)
-> (ReferenceField -> ReferenceField -> Bool)
-> (ReferenceField -> ReferenceField -> Bool)
-> (ReferenceField -> ReferenceField -> Bool)
-> (ReferenceField -> ReferenceField -> ReferenceField)
-> (ReferenceField -> ReferenceField -> ReferenceField)
-> Ord ReferenceField
ReferenceField -> ReferenceField -> Bool
ReferenceField -> ReferenceField -> Ordering
ReferenceField -> ReferenceField -> ReferenceField
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ReferenceField -> ReferenceField -> Ordering
compare :: ReferenceField -> ReferenceField -> Ordering
$c< :: ReferenceField -> ReferenceField -> Bool
< :: ReferenceField -> ReferenceField -> Bool
$c<= :: ReferenceField -> ReferenceField -> Bool
<= :: ReferenceField -> ReferenceField -> Bool
$c> :: ReferenceField -> ReferenceField -> Bool
> :: ReferenceField -> ReferenceField -> Bool
$c>= :: ReferenceField -> ReferenceField -> Bool
>= :: ReferenceField -> ReferenceField -> Bool
$cmax :: ReferenceField -> ReferenceField -> ReferenceField
max :: ReferenceField -> ReferenceField -> ReferenceField
$cmin :: ReferenceField -> ReferenceField -> ReferenceField
min :: ReferenceField -> ReferenceField -> ReferenceField
Ord, Int -> ReferenceField
ReferenceField -> Int
ReferenceField -> [ReferenceField]
ReferenceField -> ReferenceField
ReferenceField -> ReferenceField -> [ReferenceField]
ReferenceField
-> ReferenceField -> ReferenceField -> [ReferenceField]
(ReferenceField -> ReferenceField)
-> (ReferenceField -> ReferenceField)
-> (Int -> ReferenceField)
-> (ReferenceField -> Int)
-> (ReferenceField -> [ReferenceField])
-> (ReferenceField -> ReferenceField -> [ReferenceField])
-> (ReferenceField -> ReferenceField -> [ReferenceField])
-> (ReferenceField
-> ReferenceField -> ReferenceField -> [ReferenceField])
-> Enum ReferenceField
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: ReferenceField -> ReferenceField
succ :: ReferenceField -> ReferenceField
$cpred :: ReferenceField -> ReferenceField
pred :: ReferenceField -> ReferenceField
$ctoEnum :: Int -> ReferenceField
toEnum :: Int -> ReferenceField
$cfromEnum :: ReferenceField -> Int
fromEnum :: ReferenceField -> Int
$cenumFrom :: ReferenceField -> [ReferenceField]
enumFrom :: ReferenceField -> [ReferenceField]
$cenumFromThen :: ReferenceField -> ReferenceField -> [ReferenceField]
enumFromThen :: ReferenceField -> ReferenceField -> [ReferenceField]
$cenumFromTo :: ReferenceField -> ReferenceField -> [ReferenceField]
enumFromTo :: ReferenceField -> ReferenceField -> [ReferenceField]
$cenumFromThenTo :: ReferenceField
-> ReferenceField -> ReferenceField -> [ReferenceField]
enumFromThenTo :: ReferenceField
-> ReferenceField -> ReferenceField -> [ReferenceField]
Enum)
type MdocReference = M.Map ReferenceField [T.Text]
data MdocState = MdocState
{ MdocState -> ReaderOptions
readerOptions :: ReaderOptions
, MdocState -> Meta
metadata :: Meta
, MdocState -> Bool
tableCellsPlain :: Bool
, MdocState -> Bool
spacingMode :: Bool
, MdocState -> Bool
authorNameSplit :: Bool
, MdocState -> Bool
inLineEnclosure :: Bool
, MdocState -> Maybe Text
progName :: Maybe T.Text
, MdocState -> MdocSection
currentSection :: MdocSection
, MdocState -> MdocReference
currentReference :: MdocReference
, MdocState -> [LogMessage]
logMessages :: [LogMessage]
}
deriving (Int -> MdocState -> ShowS
[MdocState] -> ShowS
MdocState -> String
(Int -> MdocState -> ShowS)
-> (MdocState -> String)
-> ([MdocState] -> ShowS)
-> Show MdocState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MdocState -> ShowS
showsPrec :: Int -> MdocState -> ShowS
$cshow :: MdocState -> String
show :: MdocState -> String
$cshowList :: [MdocState] -> ShowS
showList :: [MdocState] -> ShowS
Show)
instance Default MdocState where
def :: MdocState
def =
MdocState
{ readerOptions :: ReaderOptions
readerOptions = ReaderOptions
forall a. Default a => a
def
, metadata :: Meta
metadata = Meta
B.nullMeta
, tableCellsPlain :: Bool
tableCellsPlain = Bool
True
, spacingMode :: Bool
spacingMode = Bool
True
, authorNameSplit :: Bool
authorNameSplit = Bool
False
, inLineEnclosure :: Bool
inLineEnclosure = Bool
False
, currentSection :: MdocSection
currentSection = MdocSection
ShOther
, currentReference :: MdocReference
currentReference = MdocReference
forall k a. Map k a
M.empty
, progName :: Maybe Text
progName = Maybe Text
forall a. Maybe a
Nothing
, logMessages :: [LogMessage]
logMessages = []
}
instance HasLogMessages MdocState where
addLogMessage :: LogMessage -> MdocState -> MdocState
addLogMessage LogMessage
msg MdocState
st = MdocState
st{ logMessages = msg : logMessages st }
getLogMessages :: MdocState -> [LogMessage]
getLogMessages MdocState
st = [LogMessage] -> [LogMessage]
forall a. [a] -> [a]
reverse ([LogMessage] -> [LogMessage]) -> [LogMessage] -> [LogMessage]
forall a b. (a -> b) -> a -> b
$ MdocState -> [LogMessage]
logMessages MdocState
st
type MdocParser m = P.ParsecT [MdocToken] MdocState m
readMdoc :: (PandocMonad m, ToSources a)
=> ReaderOptions
-> a
-> m Pandoc
readMdoc :: forall (m :: * -> *) a.
(PandocMonad m, ToSources a) =>
ReaderOptions -> a -> m Pandoc
readMdoc ReaderOptions
opts a
s = do
let Sources [(SourcePos, Text)]
inps = a -> Sources
forall a. ToSources a => a -> Sources
toSources a
s
tokenz <- [MdocTokens] -> MdocTokens
forall a. Monoid a => [a] -> a
mconcat ([MdocTokens] -> MdocTokens) -> m [MdocTokens] -> m MdocTokens
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((SourcePos, Text) -> m MdocTokens)
-> [(SourcePos, Text)] -> m [MdocTokens]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM ((SourcePos -> Text -> m MdocTokens)
-> (SourcePos, Text) -> m MdocTokens
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry SourcePos -> Text -> m MdocTokens
forall (m :: * -> *).
PandocMonad m =>
SourcePos -> Text -> m MdocTokens
lexMdoc) [(SourcePos, Text)]
inps
let state = MdocState
forall a. Default a => a
def {readerOptions = opts} :: MdocState
eitherdoc <- readWithMTokens parseMdoc state
(Foldable.toList . unMdocTokens $ tokenz)
either (throwError . fromParsecError (Sources inps)) return eitherdoc
readWithMTokens :: PandocMonad m
=> ParsecT [MdocToken] MdocState m a
-> MdocState
-> [MdocToken]
-> m (Either ParseError a)
readWithMTokens :: forall (m :: * -> *) a.
PandocMonad m =>
ParsecT [MdocToken] MdocState m a
-> MdocState -> [MdocToken] -> m (Either ParseError a)
readWithMTokens ParsecT [MdocToken] MdocState m a
parser MdocState
state [MdocToken]
input =
ParsecT [MdocToken] MdocState m a
-> MdocState -> String -> [MdocToken] -> m (Either ParseError a)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> u -> String -> s -> m (Either ParseError a)
runParserT ParsecT [MdocToken] MdocState m a
parser MdocState
state String
"source" [MdocToken]
input
parseMdoc :: PandocMonad m => MdocParser m Pandoc
parseMdoc :: forall (m :: * -> *). PandocMonad m => MdocParser m Pandoc
parseMdoc = do
ParsecT [MdocToken] MdocState m ()
-> ParsecT [MdocToken] MdocState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional ParsecT [MdocToken] MdocState m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
parsePrologue
bs <- ParsecT [MdocToken] MdocState m Blocks
-> ParsecT [MdocToken] MdocState m [Blocks]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT [MdocToken] MdocState m Blocks
forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseBlock ParsecT [MdocToken] MdocState m [Blocks]
-> ParsecT [MdocToken] MdocState m ()
-> ParsecT [MdocToken] MdocState m [Blocks]
forall a b.
ParsecT [MdocToken] MdocState m a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT [MdocToken] MdocState m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
meta <- metadata <$> getState
let (Pandoc _ blocks) = B.doc $ mconcat bs
reportLogMessages
return $ Pandoc meta blocks
msatisfy :: Monad m
=> (MdocToken -> Bool) -> P.ParsecT [MdocToken] st m MdocToken
msatisfy :: forall (m :: * -> *) st.
Monad m =>
(MdocToken -> Bool) -> ParsecT [MdocToken] st m MdocToken
msatisfy MdocToken -> Bool
predic = (MdocToken -> String)
-> (SourcePos -> MdocToken -> [MdocToken] -> SourcePos)
-> (MdocToken -> Maybe MdocToken)
-> ParsecT [MdocToken] st m MdocToken
forall s (m :: * -> *) t a u.
Stream s m t =>
(t -> String)
-> (SourcePos -> t -> s -> SourcePos)
-> (t -> Maybe a)
-> ParsecT s u m a
P.tokenPrim MdocToken -> String
forall a. Show a => a -> String
show SourcePos -> MdocToken -> [MdocToken] -> SourcePos
nextPos MdocToken -> Maybe MdocToken
testTok
where
testTok :: MdocToken -> Maybe MdocToken
testTok MdocToken
t = if MdocToken -> Bool
predic MdocToken
t then MdocToken -> Maybe MdocToken
forall a. a -> Maybe a
Just MdocToken
t else Maybe MdocToken
forall a. Maybe a
Nothing
nextPos :: SourcePos -> MdocToken -> [MdocToken] -> SourcePos
nextPos SourcePos
_ MdocToken
_ (Macro Text
_ SourcePos
pos':[MdocToken]
_) = SourcePos
pos'
nextPos SourcePos
_ MdocToken
_ (Lit Text
_ SourcePos
pos':[MdocToken]
_) = SourcePos
pos'
nextPos SourcePos
_ MdocToken
_ (Str Text
_ SourcePos
pos':[MdocToken]
_) = SourcePos
pos'
nextPos SourcePos
_ MdocToken
_ (Delim DelimSide
_ Text
_ SourcePos
pos':[MdocToken]
_) = SourcePos
pos'
nextPos SourcePos
_ MdocToken
_ (Blank SourcePos
pos':[MdocToken]
_) = SourcePos
pos'
nextPos SourcePos
a MdocToken
_ (Eol{}:MdocToken
x:[MdocToken]
xs) = SourcePos -> MdocToken -> [MdocToken] -> SourcePos
nextPos SourcePos
a MdocToken
x [MdocToken]
xs
nextPos SourcePos
pos MdocToken
_ [MdocToken
Eol] = SourcePos
pos
nextPos SourcePos
pos MdocToken
_ [] = SourcePos
pos
macro :: PandocMonad m => T.Text -> MdocParser m MdocToken
macro :: forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
name = (MdocToken -> Bool) -> ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *) st.
Monad m =>
(MdocToken -> Bool) -> ParsecT [MdocToken] st m MdocToken
msatisfy MdocToken -> Bool
t where
t :: MdocToken -> Bool
t (Macro Text
n SourcePos
_) = Text
n Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
name
t MdocToken
_ = Bool
False
anyMacro :: PandocMonad m => MdocParser m MdocToken
anyMacro :: forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
anyMacro = (MdocToken -> Bool) -> ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *) st.
Monad m =>
(MdocToken -> Bool) -> ParsecT [MdocToken] st m MdocToken
msatisfy MdocToken -> Bool
t where
t :: MdocToken -> Bool
t (Macro Text
_ SourcePos
_) = Bool
True
t MdocToken
_ = Bool
False
emptyMacro :: PandocMonad m => T.Text -> MdocParser m MdocToken
emptyMacro :: forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
emptyMacro Text
n = Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
n MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m () -> MdocParser m MdocToken
forall a b.
ParsecT [MdocToken] MdocState m a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT [MdocToken] MdocState m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
eol
delim :: PandocMonad m => DelimSide -> MdocParser m MdocToken
delim :: forall (m :: * -> *).
PandocMonad m =>
DelimSide -> MdocParser m MdocToken
delim DelimSide
side = (MdocToken -> Bool) -> ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *) st.
Monad m =>
(MdocToken -> Bool) -> ParsecT [MdocToken] st m MdocToken
msatisfy MdocToken -> Bool
t where
t :: MdocToken -> Bool
t (Delim DelimSide
s Text
_ SourcePos
_) = DelimSide
side DelimSide -> DelimSide -> Bool
forall a. Eq a => a -> a -> Bool
== DelimSide
s
t MdocToken
_ = Bool
False
str :: PandocMonad m => MdocParser m MdocToken
str :: forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
str = (MdocToken -> Bool) -> ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *) st.
Monad m =>
(MdocToken -> Bool) -> ParsecT [MdocToken] st m MdocToken
msatisfy MdocToken -> Bool
t where
t :: MdocToken -> Bool
t Str{} = Bool
True
t MdocToken
_ = Bool
False
lit :: PandocMonad m => MdocParser m MdocToken
lit :: forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
lit = (MdocToken -> Bool) -> ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *) st.
Monad m =>
(MdocToken -> Bool) -> ParsecT [MdocToken] st m MdocToken
msatisfy MdocToken -> Bool
t where
t :: MdocToken -> Bool
t Lit{} = Bool
True
t MdocToken
_ = Bool
False
arg :: PandocMonad m => MdocParser m MdocToken
arg :: forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
arg = (MdocToken -> Bool) -> ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *) st.
Monad m =>
(MdocToken -> Bool) -> ParsecT [MdocToken] st m MdocToken
msatisfy MdocToken -> Bool
t where
t :: MdocToken -> Bool
t Lit{} = Bool
True
t Macro{} = Bool
True
t MdocToken
_ = Bool
False
literal :: PandocMonad m => T.Text -> MdocParser m MdocToken
literal :: forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
n = (MdocToken -> Bool) -> ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *) st.
Monad m =>
(MdocToken -> Bool) -> ParsecT [MdocToken] st m MdocToken
msatisfy MdocToken -> Bool
t where
t :: MdocToken -> Bool
t (Lit Text
n' SourcePos
_) = Text
n Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
n'
t MdocToken
_ = Bool
False
blank :: PandocMonad m => MdocParser m MdocToken
blank :: forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
blank = (MdocToken -> Bool) -> ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *) st.
Monad m =>
(MdocToken -> Bool) -> ParsecT [MdocToken] st m MdocToken
msatisfy MdocToken -> Bool
t where
t :: MdocToken -> Bool
t Blank{} = Bool
True
t MdocToken
_ = Bool
False
eol :: PandocMonad m => MdocParser m ()
eol :: forall (m :: * -> *). PandocMonad m => MdocParser m ()
eol = ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m ())
-> ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m ()
forall a b. (a -> b) -> a -> b
$ (MdocToken -> Bool) -> ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *) st.
Monad m =>
(MdocToken -> Bool) -> ParsecT [MdocToken] st m MdocToken
msatisfy MdocToken -> Bool
t where
t :: MdocToken -> Bool
t Eol{} = Bool
True
t MdocToken
_ = Bool
False
newControlContext :: MdocToken -> Bool
newControlContext :: MdocToken -> Bool
newControlContext Eol{} = Bool
True
newControlContext Macro{} = Bool
True
newControlContext Str{} = Bool
True
newControlContext Blank{} = Bool
True
newControlContext Lit{} = Bool
False
newControlContext Delim{} = Bool
False
inlineContextEnd :: PandocMonad m => MdocParser m ()
inlineContextEnd :: forall (m :: * -> *). PandocMonad m => MdocParser m ()
inlineContextEnd = ParsecT [MdocToken] MdocState m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof ParsecT [MdocToken] MdocState m ()
-> ParsecT [MdocToken] MdocState m ()
-> ParsecT [MdocToken] MdocState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m ())
-> (ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m MdocToken)
-> ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m MdocToken
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m ())
-> ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m ()
forall a b. (a -> b) -> a -> b
$ (MdocToken -> Bool) -> ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *) st.
Monad m =>
(MdocToken -> Bool) -> ParsecT [MdocToken] st m MdocToken
msatisfy MdocToken -> Bool
newControlContext)
sectionEnd :: PandocMonad m => MdocParser m ()
sectionEnd :: forall (m :: * -> *). PandocMonad m => MdocParser m ()
sectionEnd = ParsecT [MdocToken] MdocState m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof ParsecT [MdocToken] MdocState m ()
-> ParsecT [MdocToken] MdocState m ()
-> ParsecT [MdocToken] MdocState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m ())
-> (ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m MdocToken)
-> ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m MdocToken
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m ())
-> ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m ()
forall a b. (a -> b) -> a -> b
$ Text -> ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Sh")
argsToInlines :: PandocMonad m => MdocParser m Inlines
argsToInlines :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
argsToInlines = do
ls <- ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m ()
-> ParsecT [MdocToken] MdocState m [MdocToken]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
arg ParsecT [MdocToken] MdocState m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
eol
let strs = (MdocToken -> Many Inline) -> [MdocToken] -> [Many Inline]
forall a b. (a -> b) -> [a] -> [b]
map (Text -> Many Inline
B.str (Text -> Many Inline)
-> (MdocToken -> Text) -> MdocToken -> Many Inline
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MdocToken -> Text
toString) [MdocToken]
ls
spacify strs
parsePrologue :: PandocMonad m => MdocParser m ()
parsePrologue :: forall (m :: * -> *). PandocMonad m => MdocParser m ()
parsePrologue = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Dd"
date <- MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
argsToInlines
macro "Dt"
(Lit title _) <- lit
(Lit section _) <- lit
arch <- optionMaybe (toString <$> lit)
eol
emptyMacro "Os"
let adjust = Text -> Many Inline -> Meta -> Meta
forall a b. (HasMeta a, ToMetaValue b) => Text -> b -> a -> a
forall b. ToMetaValue b => Text -> b -> Meta -> Meta
B.setMeta Text
"title" (Text -> Many Inline
B.str Text
title)
(Meta -> Meta) -> (Meta -> Meta) -> Meta -> Meta
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Many Inline -> Meta -> Meta
forall a b. (HasMeta a, ToMetaValue b) => Text -> b -> a -> a
forall b. ToMetaValue b => Text -> b -> Meta -> Meta
B.setMeta Text
"date" Many Inline
date
(Meta -> Meta) -> (Meta -> Meta) -> Meta -> Meta
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Many Inline -> Meta -> Meta
forall a b. (HasMeta a, ToMetaValue b) => Text -> b -> a -> a
forall b. ToMetaValue b => Text -> b -> Meta -> Meta
B.setMeta Text
"section" (Text -> Many Inline
B.str Text
section)
(Meta -> Meta) -> (Meta -> Meta) -> Meta -> Meta
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Meta -> Meta)
-> (Text -> Meta -> Meta) -> Maybe Text -> Meta -> Meta
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Meta -> Meta
forall a. a -> a
id (Text -> Many Inline -> Meta -> Meta
forall a b. (HasMeta a, ToMetaValue b) => Text -> b -> a -> a
forall b. ToMetaValue b => Text -> b -> Meta -> Meta
B.setMeta Text
"architecture" (Many Inline -> Meta -> Meta)
-> (Text -> Many Inline) -> Text -> Meta -> Meta
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Many Inline
B.str) Maybe Text
arch
modifyState $ \MdocState
s -> MdocState
s{metadata = adjust $ metadata s}
shToSectionMode :: T.Text -> MdocSection
shToSectionMode :: Text -> MdocSection
shToSectionMode Text
"NAME" = MdocSection
ShName
shToSectionMode Text
"SYNOPSIS" = MdocSection
ShSynopsis
shToSectionMode Text
"AUTHORS" = MdocSection
ShAuthors
shToSectionMode Text
"SEE ALSO" = MdocSection
ShSeeAlso
shToSectionMode Text
_ = MdocSection
ShOther
parseHeader :: PandocMonad m => MdocParser m Blocks
= do
(Macro m _) <- ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m MdocToken
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m MdocToken)
-> ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m MdocToken
forall a b. (a -> b) -> a -> b
$ Text -> ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Sh" ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m MdocToken
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Text -> ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Ss"
txt <- lineEnclosure m id
let lvl = if Text
m Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"Sh" then Int
1 else Int
2
when (lvl == 1) $ modifyState $ \MdocState
s -> MdocState
s{currentSection = (shToSectionMode . stringify) txt}
return $ B.header lvl txt
parseNameSection :: PandocMonad m => MdocParser m Blocks
parseNameSection :: forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseNameSection = do
sec <- MdocState -> MdocSection
currentSection (MdocState -> MdocSection)
-> ParsecT [MdocToken] MdocState m MdocState
-> ParsecT [MdocToken] MdocState m MdocSection
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m MdocState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
guard $ sec == ShName
nms <- mconcat . intersperse B.space <$> many nameNm
macro "Nd"
desc <- argsToInlines
return $ B.para $ nms <> B.space <> "—" <> B.space <> desc
where
nameNm :: ParsecT [MdocToken] MdocState m (Many Inline)
nameNm = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Nm"
nms <- ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m [Many Inline]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT [MdocToken] MdocState m (Many Inline)
aNm
eol
return $ mconcat $ intersperse B.space nms
comma :: ParsecT [MdocToken] st m MdocToken
comma = (MdocToken -> Bool) -> ParsecT [MdocToken] st m MdocToken
forall (m :: * -> *) st.
Monad m =>
(MdocToken -> Bool) -> ParsecT [MdocToken] st m MdocToken
msatisfy ((MdocToken -> Bool) -> ParsecT [MdocToken] st m MdocToken)
-> (MdocToken -> Bool) -> ParsecT [MdocToken] st m MdocToken
forall a b. (a -> b) -> a -> b
$ \case
(Delim DelimSide
_ Text
"," SourcePos
_) -> Bool
True
MdocToken
_ -> Bool
False
aNm :: ParsecT [MdocToken] MdocState m (Many Inline)
aNm = do
nm <- MdocToken -> Text
toString (MdocToken -> Text)
-> MdocParser m MdocToken -> ParsecT [MdocToken] MdocState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MdocParser m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
lit
c <- option mempty (toString <$> comma)
modifyState $ \MdocState
s -> MdocState
s{progName = mplus (progName s) (Just nm)}
return $ B.code nm <> B.str c
parseSynopsisSection :: PandocMonad m => MdocParser m Blocks
parseSynopsisSection :: forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseSynopsisSection = do
sec <- MdocState -> MdocSection
currentSection (MdocState -> MdocSection)
-> ParsecT [MdocToken] MdocState m MdocState
-> ParsecT [MdocToken] MdocState m MdocSection
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m MdocState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
guard $ sec == ShSynopsis
parseSynopsis sectionEnd
parseMiniSynopsis :: PandocMonad m => MdocParser m Blocks
parseMiniSynopsis :: forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseMiniSynopsis = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"nr"
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
"nS"
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
"1"
MdocParser m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
eol
MdocParser m () -> MdocParser m Blocks
forall (m :: * -> *).
PandocMonad m =>
MdocParser m () -> MdocParser m Blocks
parseSynopsis (MdocParser m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
sectionEnd MdocParser m () -> MdocParser m () -> MdocParser m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MdocParser m ()
end)
where
end :: MdocParser m ()
end = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"nr"
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
"nS"
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
"0"
MdocParser m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
eol
() -> MdocParser m ()
forall a. a -> ParsecT [MdocToken] MdocState m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
parseSynopsis :: PandocMonad m => MdocParser m () -> MdocParser m Blocks
parseSynopsis :: forall (m :: * -> *).
PandocMonad m =>
MdocParser m () -> MdocParser m Blocks
parseSynopsis MdocParser m ()
end = do
bs <- ParsecT [MdocToken] MdocState m Blocks
-> MdocParser m () -> ParsecT [MdocToken] MdocState m [Blocks]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT [MdocToken] MdocState m Blocks
synopsisBlock MdocParser m ()
end
return $ mconcat bs
where
synopsisGroup :: ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m Blocks
synopsisGroup ParsecT [MdocToken] MdocState m (Many Inline)
p = [Many Inline] -> Blocks
B.lineBlock ([Many Inline] -> Blocks)
-> ParsecT [MdocToken] MdocState m [Many Inline]
-> ParsecT [MdocToken] MdocState m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m [Many Inline]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT [MdocToken] MdocState m (Many Inline)
p ParsecT [MdocToken] MdocState m Blocks
-> ParsecT [MdocToken] MdocState m ()
-> ParsecT [MdocToken] MdocState m Blocks
forall a b.
ParsecT [MdocToken] MdocState m a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (Text -> ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
emptyMacro Text
"Pp")
synopsisBlock :: ParsecT [MdocToken] MdocState m Blocks
synopsisBlock = ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m Blocks
forall {m :: * -> *}.
PandocMonad m =>
ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m Blocks
synopsisGroup ParsecT [MdocToken] MdocState m (Many Inline)
parseInvocation
ParsecT [MdocToken] MdocState m Blocks
-> ParsecT [MdocToken] MdocState m Blocks
-> ParsecT [MdocToken] MdocState m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m Blocks
forall {m :: * -> *}.
PandocMonad m =>
ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m Blocks
synopsisGroup (ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseCd ParsecT [MdocToken] MdocState m (Many Inline)
-> MdocParser m () -> ParsecT [MdocToken] MdocState m (Many Inline)
forall a b.
ParsecT [MdocToken] MdocState m a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* MdocParser m () -> MdocParser m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional MdocParser m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
eol)
ParsecT [MdocToken] MdocState m Blocks
-> ParsecT [MdocToken] MdocState m Blocks
-> ParsecT [MdocToken] MdocState m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m Blocks
forall {m :: * -> *}.
PandocMonad m =>
ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m Blocks
synopsisGroup (ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseIn ParsecT [MdocToken] MdocState m (Many Inline)
-> MdocParser m () -> ParsecT [MdocToken] MdocState m (Many Inline)
forall a b.
ParsecT [MdocToken] MdocState m a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* MdocParser m () -> MdocParser m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional MdocParser m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
eol)
ParsecT [MdocToken] MdocState m Blocks
-> ParsecT [MdocToken] MdocState m Blocks
-> ParsecT [MdocToken] MdocState m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m Blocks
forall {m :: * -> *}.
PandocMonad m =>
ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m Blocks
synopsisGroup (ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseFd ParsecT [MdocToken] MdocState m (Many Inline)
-> MdocParser m () -> ParsecT [MdocToken] MdocState m (Many Inline)
forall a b.
ParsecT [MdocToken] MdocState m a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* MdocParser m () -> MdocParser m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional MdocParser m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
eol)
ParsecT [MdocToken] MdocState m Blocks
-> ParsecT [MdocToken] MdocState m Blocks
-> ParsecT [MdocToken] MdocState m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m Blocks
forall {m :: * -> *}.
PandocMonad m =>
ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m Blocks
synopsisGroup (ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseVt ParsecT [MdocToken] MdocState m (Many Inline)
-> MdocParser m () -> ParsecT [MdocToken] MdocState m (Many Inline)
forall a b.
ParsecT [MdocToken] MdocState m a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* MdocParser m () -> MdocParser m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional MdocParser m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
eol)
ParsecT [MdocToken] MdocState m Blocks
-> ParsecT [MdocToken] MdocState m Blocks
-> ParsecT [MdocToken] MdocState m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT [MdocToken] MdocState m Blocks
-> ParsecT [MdocToken] MdocState m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT [MdocToken] MdocState m Blocks
parseSignature
ParsecT [MdocToken] MdocState m Blocks
-> ParsecT [MdocToken] MdocState m Blocks
-> ParsecT [MdocToken] MdocState m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT [MdocToken] MdocState m Blocks
parseWeirdSignature
ParsecT [MdocToken] MdocState m Blocks
-> ParsecT [MdocToken] MdocState m Blocks
-> ParsecT [MdocToken] MdocState m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT [MdocToken] MdocState m Blocks
forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseRegularBlock
parseInvocation :: ParsecT [MdocToken] MdocState m (Many Inline)
parseInvocation = do
nm <- ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseNm
optional eol
rest <- many synopsisInline
spacify (nm:rest)
parseSignature :: ParsecT [MdocToken] MdocState m Blocks
parseSignature = do
ft <- ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseFt ParsecT [MdocToken] MdocState m (Many Inline)
-> MdocParser m () -> ParsecT [MdocToken] MdocState m (Many Inline)
forall a b.
ParsecT [MdocToken] MdocState m a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* MdocParser m () -> MdocParser m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional MdocParser m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
eol
sig <- (parseFn <|> parseFo) <* optional eol
return $ B.lineBlock [ft, sig <> ";"]
parseWeirdSignature :: ParsecT [MdocToken] MdocState m Blocks
parseWeirdSignature = do
ft <- ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseFt ParsecT [MdocToken] MdocState m (Many Inline)
-> MdocParser m () -> ParsecT [MdocToken] MdocState m (Many Inline)
forall a b.
ParsecT [MdocToken] MdocState m a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* MdocParser m () -> MdocParser m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional MdocParser m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
eol
rest <- many synopsisInline
line <- spacify (ft:rest)
return $ B.lineBlock [line]
synopsisInline :: ParsecT [MdocToken] MdocState m (Many Inline)
synopsisInline = ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseSmToggle ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseStrs ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (ParsecT [MdocToken] MdocState m [Many Inline]
controlLine ParsecT [MdocToken] MdocState m [Many Inline]
-> ([Many Inline] -> ParsecT [MdocToken] MdocState m (Many Inline))
-> ParsecT [MdocToken] MdocState m (Many Inline)
forall a b.
ParsecT [MdocToken] MdocState m a
-> (a -> ParsecT [MdocToken] MdocState m b)
-> ParsecT [MdocToken] MdocState m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [Many Inline] -> ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
[Many Inline] -> MdocParser m (Many Inline)
spacify) ParsecT [MdocToken] MdocState m (Many Inline)
-> String -> ParsecT [MdocToken] MdocState m (Many Inline)
forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"synopsis inlines"
safeEol :: MdocParser m ()
safeEol = do
amNested <- MdocState -> Bool
inLineEnclosure (MdocState -> Bool)
-> ParsecT [MdocToken] MdocState m MdocState
-> ParsecT [MdocToken] MdocState m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m MdocState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
unless amNested $ optional eol
controlLine :: ParsecT [MdocToken] MdocState m [Many Inline]
controlLine = ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m [Many Inline]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 (([ParsecT [MdocToken] MdocState m (Many Inline)]
-> ParsecT [MdocToken] MdocState m (Many Inline)
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [ParsecT [MdocToken] MdocState m (Many Inline)]
forall (m :: * -> *). PandocMonad m => [MdocParser m (Many Inline)]
otherInlineMacros ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
litsAndDelimsToInlines) ParsecT [MdocToken] MdocState m (Many Inline)
-> MdocParser m () -> ParsecT [MdocToken] MdocState m (Many Inline)
forall a b.
ParsecT [MdocToken] MdocState m a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* MdocParser m ()
safeEol)
parseSeeAlsoSection :: PandocMonad m => MdocParser m Blocks
parseSeeAlsoSection :: forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseSeeAlsoSection = do
sec <- MdocState -> MdocSection
currentSection (MdocState -> MdocSection)
-> ParsecT [MdocToken] MdocState m MdocState
-> ParsecT [MdocToken] MdocState m MdocSection
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m MdocState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
guard $ sec == ShSeeAlso
blocks <- many1Till parseSeeAlsoBlock sectionEnd
return $ mconcat blocks
where
parseSeeAlsoBlock :: ParsecT [MdocToken] MdocState m Blocks
parseSeeAlsoBlock = ParsecT [MdocToken] MdocState m Blocks
forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseRegularBlock ParsecT [MdocToken] MdocState m Blocks
-> ParsecT [MdocToken] MdocState m Blocks
-> ParsecT [MdocToken] MdocState m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Many Inline -> Blocks
B.para (Many Inline -> Blocks)
-> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseRs)
parseStr :: PandocMonad m => MdocParser m Inlines
parseStr :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseStr = do
(Str txt _) <- MdocParser m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
str
return $ B.text txt
parseStrs :: PandocMonad m => MdocParser m Inlines
parseStrs :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseStrs = do
txt <- ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m [Many Inline]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseStr
return $ mconcat $ intersperse B.space txt
parseDelim :: PandocMonad m => DelimSide -> MdocParser m Inlines
parseDelim :: forall (m :: * -> *).
PandocMonad m =>
DelimSide -> MdocParser m (Many Inline)
parseDelim DelimSide
pos = do
(Delim _ txt _) <- DelimSide -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
DelimSide -> MdocParser m MdocToken
delim DelimSide
pos
return $ B.str txt
litsToText :: PandocMonad m => MdocParser m [T.Text]
litsToText :: forall (m :: * -> *). PandocMonad m => MdocParser m [Text]
litsToText = do
ls <- ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m [MdocToken]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
lit
return $ map toString ls
litsToInlines :: PandocMonad m => MdocParser m Inlines
litsToInlines :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
litsToInlines = do
ls <- ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m [MdocToken]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
lit
let strs = (MdocToken -> Many Inline) -> [MdocToken] -> [Many Inline]
forall a b. (a -> b) -> [a] -> [b]
map (Text -> Many Inline
B.str (Text -> Many Inline)
-> (MdocToken -> Text) -> MdocToken -> Many Inline
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MdocToken -> Text
toString) [MdocToken]
ls
spacify strs
litsAndDelimsToInlines :: PandocMonad m => MdocParser m Inlines
litsAndDelimsToInlines :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
litsAndDelimsToInlines = do
(o, ls, c) <- MdocParser m [MdocToken]
-> MdocParser m (Many Inline, [MdocToken], Many Inline)
forall (m :: * -> *) x.
PandocMonad m =>
MdocParser m x -> MdocParser m (Many Inline, x, Many Inline)
delimitedArgs (MdocParser m [MdocToken]
-> MdocParser m (Many Inline, [MdocToken], Many Inline))
-> MdocParser m [MdocToken]
-> MdocParser m (Many Inline, [MdocToken], Many Inline)
forall a b. (a -> b) -> a -> b
$ ParsecT [MdocToken] MdocState m MdocToken
-> MdocParser m [MdocToken]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
lit
guard $ not (null o && null ls && null c)
strs <- spacify $ map (B.str . toString) ls
return $ o <> strs <> c
openingDelimiters :: PandocMonad m => MdocParser m Inlines
openingDelimiters :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
openingDelimiters = do
openDelim <- [Many Inline] -> Many Inline
forall a. Monoid a => [a] -> a
mconcat ([Many Inline] -> Many Inline)
-> ParsecT [MdocToken] MdocState m [Many Inline]
-> ParsecT [MdocToken] MdocState m (Many Inline)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m [Many Inline]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (DelimSide -> ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
DelimSide -> MdocParser m (Many Inline)
parseDelim DelimSide
Open)
omids <- pipes
addSpace <- spacingMode <$> getState
let omid | Many Inline -> Bool
forall a. Many a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Many Inline
omids = Many Inline
forall a. Monoid a => a
mempty
| Bool
addSpace = Many Inline
omids Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
B.space
| Bool
otherwise = Many Inline
omids
return $ openDelim <> omid
pipes :: PandocMonad m => MdocParser m Inlines
pipes :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
pipes = ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m [Many Inline]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (DelimSide -> ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
DelimSide -> MdocParser m (Many Inline)
parseDelim DelimSide
Middle) ParsecT [MdocToken] MdocState m [Many Inline]
-> ([Many Inline] -> ParsecT [MdocToken] MdocState m (Many Inline))
-> ParsecT [MdocToken] MdocState m (Many Inline)
forall a b.
ParsecT [MdocToken] MdocState m a
-> (a -> ParsecT [MdocToken] MdocState m b)
-> ParsecT [MdocToken] MdocState m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [Many Inline] -> ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
[Many Inline] -> MdocParser m (Many Inline)
spacify
closingDelimiters :: PandocMonad m => MdocParser m Inlines
closingDelimiters :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
closingDelimiters = do
cmids <- MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
pipes
addSpace <- spacingMode <$> getState
let cmid | Many Inline -> Bool
forall a. Many a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Many Inline
cmids = Many Inline
forall a. Monoid a => a
mempty
| Bool
addSpace = Many Inline
B.space Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
cmids
| Bool
otherwise = Many Inline
cmids
closeDelim <- mconcat <$> many (parseDelim Close)
return $ cmid <> closeDelim
delimitedArgs :: PandocMonad m => MdocParser m x -> MdocParser m (Inlines, x, Inlines)
delimitedArgs :: forall (m :: * -> *) x.
PandocMonad m =>
MdocParser m x -> MdocParser m (Many Inline, x, Many Inline)
delimitedArgs MdocParser m x
p = do
openDelim <- MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
openingDelimiters
inlines <- p
closeDelim <- closingDelimiters
return (openDelim, inlines, closeDelim)
simpleInline :: PandocMonad m => T.Text -> (Inlines -> Inlines) -> MdocParser m Inlines
simpleInline :: forall (m :: * -> *).
PandocMonad m =>
Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
simpleInline Text
nm Many Inline -> Many Inline
xform = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
nm
segs <- ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m ()
-> ParsecT [MdocToken] MdocState m [Many Inline]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT [MdocToken] MdocState m (Many Inline)
segment ParsecT [MdocToken] MdocState m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
inlineContextEnd
spacify segs
where
segment :: ParsecT [MdocToken] MdocState m (Many Inline)
segment = do
(openDelim, inlines, closeDelim) <- ParsecT [MdocToken] MdocState m (Many Inline)
-> MdocParser m (Many Inline, Many Inline, Many Inline)
forall (m :: * -> *) x.
PandocMonad m =>
MdocParser m x -> MdocParser m (Many Inline, x, Many Inline)
delimitedArgs (ParsecT [MdocToken] MdocState m (Many Inline)
-> MdocParser m (Many Inline, Many Inline, Many Inline))
-> ParsecT [MdocToken] MdocState m (Many Inline)
-> MdocParser m (Many Inline, Many Inline, Many Inline)
forall a b. (a -> b) -> a -> b
$ Many Inline
-> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Many Inline
forall a. Monoid a => a
mempty ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
litsToInlines
return $ openDelim <> xform inlines <> closeDelim
codeLikeInline' :: PandocMonad m => T.Text -> T.Text -> MdocParser m Inlines
codeLikeInline' :: forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> MdocParser m (Many Inline)
codeLikeInline' Text
nm Text
cl = Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
simpleInline Text
nm ((Many Inline -> Many Inline) -> Many Inline -> Many Inline
eliminateEmpty (Attr -> Text -> Many Inline
B.codeWith (Text -> Attr
cls Text
cl) (Text -> Many Inline)
-> (Many Inline -> Text) -> Many Inline -> Many Inline
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Many Inline -> Text
forall a. Walkable Inline a => a -> Text
stringify))
codeLikeInline :: PandocMonad m => T.Text -> MdocParser m Inlines
codeLikeInline :: forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m (Many Inline)
codeLikeInline Text
nm = Text -> Text -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> MdocParser m (Many Inline)
codeLikeInline' Text
nm Text
nm
spanLikeInline :: PandocMonad m => T.Text -> MdocParser m Inlines
spanLikeInline :: forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m (Many Inline)
spanLikeInline Text
nm = Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
simpleInline Text
nm ((Many Inline -> Many Inline) -> Many Inline -> Many Inline
eliminateEmpty (Attr -> Many Inline -> Many Inline
B.spanWith (Text -> Attr
cls Text
nm)))
lineEnclosure :: PandocMonad m => T.Text -> (Inlines -> Inlines) -> MdocParser m Inlines
lineEnclosure :: forall (m :: * -> *).
PandocMonad m =>
Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
lineEnclosure Text
nm Many Inline -> Many Inline
xform = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
nm
amNested <- MdocState -> Bool
inLineEnclosure (MdocState -> Bool)
-> ParsecT [MdocToken] MdocState m MdocState
-> ParsecT [MdocToken] MdocState m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m MdocState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
modifyState $ \MdocState
s -> MdocState
s{inLineEnclosure = True}
first <- openingDelimiters
further <-
(manyTill
(parseInlineMacro
<|> (try (litsAndDelimsToInlines <* notFollowedBy eol))
<|> litsToInlines
<|> openingDelimiters)
lineEnclosureContextEnd)
further' <- spacify further
finally <- if amNested then mempty else closingDelimiters <* optional eol
modifyState $ \MdocState
s -> MdocState
s{inLineEnclosure = amNested}
return $ first <> xform further' <> finally
where
lineEnclosureContextEnd :: ParsecT [MdocToken] MdocState m ()
lineEnclosureContextEnd =
ParsecT [MdocToken] MdocState m ()
-> ParsecT [MdocToken] MdocState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT [MdocToken] MdocState m ()
-> ParsecT [MdocToken] MdocState m ())
-> ParsecT [MdocToken] MdocState m ()
-> ParsecT [MdocToken] MdocState m ()
forall a b. (a -> b) -> a -> b
$
MdocParser m MdocToken -> ParsecT [MdocToken] MdocState m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (MdocParser m MdocToken -> MdocParser m MdocToken
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Ta"))
ParsecT [MdocToken] MdocState m ()
-> ParsecT [MdocToken] MdocState m ()
-> ParsecT [MdocToken] MdocState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT [MdocToken] MdocState m ()
-> ParsecT [MdocToken] MdocState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m [MdocToken]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Ns" MdocParser m MdocToken
-> MdocParser m MdocToken -> MdocParser m MdocToken
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DelimSide -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
DelimSide -> MdocParser m MdocToken
delim DelimSide
Close) ParsecT [MdocToken] MdocState m [MdocToken]
-> ParsecT [MdocToken] MdocState m ()
-> ParsecT [MdocToken] MdocState m ()
forall a b.
ParsecT [MdocToken] MdocState m a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT [MdocToken] MdocState m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
eol)
noSpace :: Inlines
noSpace :: Many Inline
noSpace = Text -> Text -> Many Inline
B.rawInline Text
"mdoc" Text
"Ns"
apMacro :: Inlines
apMacro :: Many Inline
apMacro = Text -> Text -> Many Inline
B.rawInline Text
"mdoc" Text
"Ap"
smOff :: Inlines
smOff :: Many Inline
smOff = Text -> Text -> Many Inline
B.rawInline Text
"mdoc" Text
"Sm off"
smOn :: Inlines
smOn :: Many Inline
smOn = Text -> Text -> Many Inline
B.rawInline Text
"mdoc" Text
"Sm on"
data SpacifyState = SpacifyState
{ SpacifyState -> [Many Inline]
accum :: [Inlines],
SpacifyState -> Many Inline
prev :: Inlines,
SpacifyState -> Bool
ns :: Bool,
SpacifyState -> Bool
sm :: Bool
}
instance Default SpacifyState where
def :: SpacifyState
def = [Many Inline] -> Many Inline -> Bool -> Bool -> SpacifyState
SpacifyState [] Many Inline
forall a. Monoid a => a
mempty Bool
False Bool
True
foldNoSpaces :: [Inlines] -> [Inlines]
foldNoSpaces :: [Many Inline] -> [Many Inline]
foldNoSpaces [Many Inline]
xs = (SpacifyState -> [Many Inline]
finalize (SpacifyState -> [Many Inline])
-> ([Many Inline] -> SpacifyState)
-> [Many Inline]
-> [Many Inline]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SpacifyState -> Many Inline -> SpacifyState)
-> SpacifyState -> [Many Inline] -> SpacifyState
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl SpacifyState -> Many Inline -> SpacifyState
go SpacifyState
forall a. Default a => a
def) [Many Inline]
xs
where
go :: SpacifyState -> Inlines -> SpacifyState
go :: SpacifyState -> Many Inline -> SpacifyState
go SpacifyState
s Many Inline
x
| SpacifyState -> Bool
ns SpacifyState
s Bool -> Bool -> Bool
&& Many Inline
x Many Inline -> Many Inline -> Bool
forall a. Eq a => a -> a -> Bool
== Many Inline
noSpace = SpacifyState
s
| Many Inline
x Many Inline -> Many Inline -> Bool
forall a. Eq a => a -> a -> Bool
== Many Inline
apMacro = SpacifyState
s{prev = prev s <> "'", ns = True}
| Many Inline
x Many Inline -> Many Inline -> Bool
forall a. Eq a => a -> a -> Bool
== Many Inline
noSpace = SpacifyState
s{ns = True}
| Many Inline
x Many Inline -> Many Inline -> Bool
forall a. Eq a => a -> a -> Bool
== Many Inline
smOn = SpacifyState
s{sm = True}
| SpacifyState -> Bool
sm SpacifyState
s Bool -> Bool -> Bool
&& Many Inline
x Many Inline -> Many Inline -> Bool
forall a. Eq a => a -> a -> Bool
== Many Inline
smOff = SpacifyState
s{accum = accum s <> [prev s], prev = mempty, sm = False}
| SpacifyState -> Bool
ns SpacifyState
s = SpacifyState
s{prev = prev s <> x, ns = False}
| Bool -> Bool
not (SpacifyState -> Bool
sm SpacifyState
s) = SpacifyState
s{prev = prev s <> x}
| Many Inline -> Bool
forall a. Many a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (SpacifyState -> Many Inline
prev SpacifyState
s) = SpacifyState
s{prev = x}
| Bool
otherwise = SpacifyState
s{accum = accum s <> [prev s], prev = x}
finalize :: SpacifyState -> [Many Inline]
finalize SpacifyState
s
| Many Inline -> Bool
forall a. Many a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (SpacifyState -> Many Inline
prev SpacifyState
s) = SpacifyState -> [Many Inline]
accum SpacifyState
s
| Bool
otherwise = SpacifyState -> [Many Inline]
accum SpacifyState
s [Many Inline] -> [Many Inline] -> [Many Inline]
forall a. Semigroup a => a -> a -> a
<> [SpacifyState -> Many Inline
prev SpacifyState
s]
spacify :: PandocMonad m => [Inlines] -> MdocParser m Inlines
spacify :: forall (m :: * -> *).
PandocMonad m =>
[Many Inline] -> MdocParser m (Many Inline)
spacify [Many Inline]
x = do
mode <- MdocState -> Bool
spacingMode (MdocState -> Bool)
-> ParsecT [MdocToken] MdocState m MdocState
-> ParsecT [MdocToken] MdocState m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m MdocState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
return (go mode x)
where
go :: Bool -> [Many Inline] -> Many Inline
go Bool
True = [Many Inline] -> Many Inline
forall a. Monoid a => [a] -> a
mconcat ([Many Inline] -> Many Inline)
-> ([Many Inline] -> [Many Inline]) -> [Many Inline] -> Many Inline
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Many Inline -> [Many Inline] -> [Many Inline]
forall a. a -> [a] -> [a]
intersperse Many Inline
B.space ([Many Inline] -> [Many Inline])
-> ([Many Inline] -> [Many Inline])
-> [Many Inline]
-> [Many Inline]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Many Inline] -> [Many Inline]
foldNoSpaces
go Bool
False = [Many Inline] -> Many Inline
forall a. Monoid a => [a] -> a
mconcat ([Many Inline] -> Many Inline)
-> ([Many Inline] -> [Many Inline]) -> [Many Inline] -> Many Inline
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Many Inline] -> [Many Inline]
foldNoSpaces
multilineEnclosure :: PandocMonad m => T.Text -> T.Text -> (Inlines -> Inlines) -> MdocParser m Inlines
multilineEnclosure :: forall (m :: * -> *).
PandocMonad m =>
Text
-> Text
-> (Many Inline -> Many Inline)
-> MdocParser m (Many Inline)
multilineEnclosure Text
op Text
cl Many Inline -> Many Inline
xform = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
op
amNested <- MdocState -> Bool
inLineEnclosure (MdocState -> Bool)
-> ParsecT [MdocToken] MdocState m MdocState
-> ParsecT [MdocToken] MdocState m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m MdocState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
modifyState $ \MdocState
s -> MdocState
s{inLineEnclosure = False}
openDelim <- mconcat <$> many (parseDelim Open)
optional eol
contents <- parseInlines
(macro cl <?> show cl)
closeDelim <-
if amNested
then mempty
else mconcat <$> many (parseDelim Close) <* optional eol
modifyState $ \MdocState
s -> MdocState
s{inLineEnclosure = amNested}
return $ openDelim <> xform contents <> closeDelim
parseEo :: PandocMonad m => MdocParser m Inlines
parseEo :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseEo = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Eo"
odel <- ParsecT [MdocToken] MdocState m (Many Inline)
del
optional eol
inner <- parseInlines
macro "Ec"
cdel <- del
optional eol
return $ odel <> inner <> cdel
where
del :: ParsecT [MdocToken] MdocState m (Many Inline)
del = Text -> Many Inline
B.str (Text -> Many Inline)
-> (MdocToken -> Text) -> MdocToken -> Many Inline
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MdocToken -> Text
toString (MdocToken -> Many Inline)
-> MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m (Many Inline)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (MdocParser m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
arg MdocParser m MdocToken
-> MdocParser m MdocToken -> MdocParser m MdocToken
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DelimSide -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
DelimSide -> MdocParser m MdocToken
delim DelimSide
Open MdocParser m MdocToken
-> MdocParser m MdocToken -> MdocParser m MdocToken
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DelimSide -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
DelimSide -> MdocParser m MdocToken
delim DelimSide
Middle MdocParser m MdocToken
-> MdocParser m MdocToken -> MdocParser m MdocToken
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DelimSide -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
DelimSide -> MdocParser m MdocToken
delim DelimSide
Close)
eliminateEmpty :: (Inlines -> Inlines) -> Inlines -> Inlines
eliminateEmpty :: (Many Inline -> Many Inline) -> Many Inline -> Many Inline
eliminateEmpty Many Inline -> Many Inline
x Many Inline
y = if Many Inline -> Bool
forall a. Many a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Many Inline
y then Many Inline
forall a. Monoid a => a
mempty else Many Inline -> Many Inline
x Many Inline
y
cls :: T.Text -> B.Attr
cls :: Text -> Attr
cls Text
x = (Text
forall a. Monoid a => a
mempty, [Text
x], [(Text, Text)]
forall a. Monoid a => a
mempty)
parseSy :: PandocMonad m => MdocParser m Inlines
parseSy :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseSy = Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
simpleInline Text
"Sy" ((Many Inline -> Many Inline) -> Many Inline -> Many Inline
eliminateEmpty Many Inline -> Many Inline
B.strong)
parseEm :: PandocMonad m => MdocParser m Inlines
parseEm :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseEm = Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
simpleInline Text
"Em" ((Many Inline -> Many Inline) -> Many Inline -> Many Inline
eliminateEmpty Many Inline -> Many Inline
B.emph)
parseNo :: PandocMonad m => MdocParser m Inlines
parseNo :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseNo = Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
simpleInline Text
"No" ((Many Inline -> Many Inline) -> Many Inline -> Many Inline
eliminateEmpty Many Inline -> Many Inline
forall a. a -> a
id)
parseTn :: PandocMonad m => MdocParser m Inlines
parseTn :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseTn = Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
simpleInline Text
"Tn" ((Many Inline -> Many Inline) -> Many Inline -> Many Inline
eliminateEmpty Many Inline -> Many Inline
forall a. a -> a
id)
parseLi :: PandocMonad m => MdocParser m Inlines
parseLi :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseLi = Text -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m (Many Inline)
codeLikeInline Text
"Li"
parseEv :: PandocMonad m => MdocParser m Inlines
parseEv :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseEv = Text -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m (Many Inline)
codeLikeInline Text
"Ev"
parseDv :: PandocMonad m => MdocParser m Inlines
parseDv :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseDv = Text -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m (Many Inline)
codeLikeInline Text
"Dv"
parseAd :: PandocMonad m => MdocParser m Inlines
parseAd :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseAd = Text -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m (Many Inline)
spanLikeInline Text
"Ad"
parseVa :: PandocMonad m => MdocParser m Inlines
parseVa :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseVa = Text -> Text -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> MdocParser m (Many Inline)
codeLikeInline' Text
"Va" Text
"variable"
parseVt :: PandocMonad m => MdocParser m Inlines
parseVt :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseVt = Text -> Text -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> MdocParser m (Many Inline)
codeLikeInline' Text
"Vt" Text
"variable"
parseAn :: PandocMonad m => MdocParser m Inlines
parseAn :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseAn = ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT [MdocToken] MdocState m (Many Inline)
anSplit ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT [MdocToken] MdocState m (Many Inline)
anRegular
where
anSplit :: ParsecT [MdocToken] MdocState m (Many Inline)
anSplit = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"An"
mode <- Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
"-split" MdocParser m MdocToken
-> Bool -> ParsecT [MdocToken] MdocState m Bool
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Bool
True ParsecT [MdocToken] MdocState m Bool
-> ParsecT [MdocToken] MdocState m Bool
-> ParsecT [MdocToken] MdocState m Bool
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
"-nosplit" MdocParser m MdocToken
-> Bool -> ParsecT [MdocToken] MdocState m Bool
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Bool
False
modifyState $ \MdocState
s -> MdocState
s{authorNameSplit = mode}
return mempty
anRegular :: ParsecT [MdocToken] MdocState m (Many Inline)
anRegular = do
an <- Text -> ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m (Many Inline)
spanLikeInline Text
"An"
spl <- authorNameSplit <$> getState
return $ (if spl then B.linebreak else mempty) <> an
parseMs :: PandocMonad m => MdocParser m Inlines
parseMs :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseMs = Text -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m (Many Inline)
spanLikeInline Text
"Ms"
parseSx :: PandocMonad m => MdocParser m Inlines
parseSx :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseSx = Text -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m (Many Inline)
spanLikeInline Text
"Sx"
parseMt :: PandocMonad m => MdocParser m Inlines
parseMt :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseMt = Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
simpleInline Text
"Mt" Many Inline -> Many Inline
mailto
where mailto :: Many Inline -> Many Inline
mailto Many Inline
x | Many Inline -> Bool
forall a. Many a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Many Inline
x = Text -> Text -> Many Inline -> Many Inline
B.link (Text
"mailto:~") Text
"" Many Inline
"~"
| Bool
otherwise = Text -> Text -> Many Inline -> Many Inline
B.link (Text
"mailto:" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Many Inline -> Text
forall a. Walkable Inline a => a -> Text
stringify Many Inline
x) Text
"" Many Inline
x
parsePa :: PandocMonad m => MdocParser m Inlines
parsePa :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parsePa = Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
simpleInline Text
"Pa" Many Inline -> Many Inline
p
where p :: Many Inline -> Many Inline
p Many Inline
x | Many Inline -> Bool
forall a. Many a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Many Inline
x = Attr -> Many Inline -> Many Inline
B.spanWith (Text -> Attr
cls Text
"Pa") Many Inline
"~"
| Bool
otherwise = Attr -> Many Inline -> Many Inline
B.spanWith (Text -> Attr
cls Text
"Pa") Many Inline
x
parseFl :: PandocMonad m => MdocParser m Inlines
parseFl :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseFl = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Fl"
start <- Many Inline
-> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Many Inline
forall a. Monoid a => a
mempty (ParsecT [MdocToken] MdocState m (Many Inline)
emptyWithDelim ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT [MdocToken] MdocState m (Many Inline)
flfl ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT [MdocToken] MdocState m (Many Inline)
emptyWithMacro ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT [MdocToken] MdocState m (Many Inline)
emptyEmpty)
segs <- manyTill segment inlineContextEnd
spacify ([start] <> segs)
where
emptyWithDelim :: ParsecT [MdocToken] MdocState m (Many Inline)
emptyWithDelim = do
ParsecT [MdocToken] MdocState m [MdocToken]
-> ParsecT [MdocToken] MdocState m [MdocToken]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParsecT [MdocToken] MdocState m [MdocToken]
-> ParsecT [MdocToken] MdocState m [MdocToken])
-> ParsecT [MdocToken] MdocState m [MdocToken]
-> ParsecT [MdocToken] MdocState m [MdocToken]
forall a b. (a -> b) -> a -> b
$ MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m [MdocToken]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 (DelimSide -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
DelimSide -> MdocParser m MdocToken
delim DelimSide
Middle MdocParser m MdocToken
-> MdocParser m MdocToken -> MdocParser m MdocToken
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DelimSide -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
DelimSide -> MdocParser m MdocToken
delim DelimSide
Close)
ds <- ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
closingDelimiters
return $ fl "-" <> ds
flfl :: ParsecT [MdocToken] MdocState m (Many Inline)
flfl = do
MdocParser m MdocToken -> MdocParser m MdocToken
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Fl")
x:xs <- Many Inline -> [Inline]
forall a. Many a -> [a]
B.toList (Many Inline -> [Inline])
-> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m [Inline]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseFl
let xx = Attr -> Text -> Many Inline
B.codeWith (Text -> Attr
cls Text
"Fl") (Text -> Many Inline) -> Text -> Many Inline
forall a b. (a -> b) -> a -> b
$ Text
"-" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Inline -> Text
forall a. Walkable Inline a => a -> Text
stringify Inline
x
return $ xx <> B.fromList xs
emptyWithMacro :: ParsecT [MdocToken] MdocState m (Many Inline)
emptyWithMacro = do
MdocParser m MdocToken -> MdocParser m MdocToken
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead MdocParser m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
anyMacro
rest <- ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseInline
return $ fl "-" <> rest
emptyEmpty :: ParsecT [MdocToken] MdocState m (Many Inline)
emptyEmpty = ParsecT [MdocToken] MdocState m ()
-> ParsecT [MdocToken] MdocState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead ParsecT [MdocToken] MdocState m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
eol ParsecT [MdocToken] MdocState m ()
-> Many Inline -> ParsecT [MdocToken] MdocState m (Many Inline)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Text -> Many Inline
fl Text
"-"
segment :: ParsecT [MdocToken] MdocState m (Many Inline)
segment = do
(openDelim, inlines, closeDelim) <- MdocParser m [Text]
-> MdocParser m (Many Inline, [Text], Many Inline)
forall (m :: * -> *) x.
PandocMonad m =>
MdocParser m x -> MdocParser m (Many Inline, x, Many Inline)
delimitedArgs (MdocParser m [Text]
-> MdocParser m (Many Inline, [Text], Many Inline))
-> MdocParser m [Text]
-> MdocParser m (Many Inline, [Text], Many Inline)
forall a b. (a -> b) -> a -> b
$ [Text] -> MdocParser m [Text] -> MdocParser m [Text]
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [Text]
forall a. Monoid a => a
mempty MdocParser m [Text]
forall (m :: * -> *). PandocMonad m => MdocParser m [Text]
litsToText
inner <- (spacify . (map fl) . flags) inlines
return $ openDelim <> inner <> closeDelim
fl :: Text -> Many Inline
fl = Attr -> Text -> Many Inline
B.codeWith (Text -> Attr
cls Text
"Fl")
flags :: [a] -> [a]
flags [] = [a
"-"]
flags [a]
xs = (a -> a) -> [a] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map (a
"-" a -> a -> a
forall a. Semigroup a => a -> a -> a
<>) [a]
xs
parseAr :: PandocMonad m => MdocParser m Inlines
parseAr :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseAr = Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
simpleInline Text
"Ar" Many Inline -> Many Inline
forall {t :: * -> *} {a}.
(Foldable t, Walkable Inline (t a)) =>
t a -> Many Inline
ar
where ar :: t a -> Many Inline
ar t a
x | t a -> Bool
forall a. t a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null t a
x = Attr -> Text -> Many Inline
B.codeWith (Text -> Attr
cls Text
"variable") Text
"file ..."
| Bool
otherwise = Attr -> Text -> Many Inline
B.codeWith (Text -> Attr
cls Text
"variable") (Text -> Many Inline) -> Text -> Many Inline
forall a b. (a -> b) -> a -> b
$ t a -> Text
forall a. Walkable Inline a => a -> Text
stringify t a
x
parseCm :: PandocMonad m => MdocParser m Inlines
parseCm :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseCm = Text -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m (Many Inline)
codeLikeInline Text
"Cm"
parseIc :: PandocMonad m => MdocParser m Inlines
parseIc :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseIc = Text -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m (Many Inline)
codeLikeInline Text
"Ic"
parseEr :: PandocMonad m => MdocParser m Inlines
parseEr :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseEr = Text -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m (Many Inline)
codeLikeInline Text
"Er"
parseCd :: PandocMonad m => MdocParser m Inlines
parseCd :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseCd = Text -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m (Many Inline)
codeLikeInline Text
"Cd"
parseQl :: PandocMonad m => MdocParser m Inlines
parseQl :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseQl = Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
lineEnclosure Text
"Ql" ((Many Inline -> Many Inline) -> MdocParser m (Many Inline))
-> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall a b. (a -> b) -> a -> b
$ Attr -> Text -> Many Inline
B.codeWith (Text -> Attr
cls Text
"Ql") (Text -> Many Inline)
-> (Many Inline -> Text) -> Many Inline -> Many Inline
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Many Inline -> Text
forall a. Walkable Inline a => a -> Text
stringify
parseDq :: PandocMonad m => MdocParser m Inlines
parseDq :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseDq = Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
lineEnclosure Text
"Dq" Many Inline -> Many Inline
B.doubleQuoted
parseDo :: PandocMonad m => MdocParser m Inlines
parseDo :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseDo = Text
-> Text
-> (Many Inline -> Many Inline)
-> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text
-> Text
-> (Many Inline -> Many Inline)
-> MdocParser m (Many Inline)
multilineEnclosure Text
"Do" Text
"Dc" Many Inline -> Many Inline
B.doubleQuoted
parseSq :: PandocMonad m => MdocParser m Inlines
parseSq :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseSq = Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
lineEnclosure Text
"Sq" Many Inline -> Many Inline
B.singleQuoted
parseSo :: PandocMonad m => MdocParser m Inlines
parseSo :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseSo = Text
-> Text
-> (Many Inline -> Many Inline)
-> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text
-> Text
-> (Many Inline -> Many Inline)
-> MdocParser m (Many Inline)
multilineEnclosure Text
"So" Text
"Sc" Many Inline -> Many Inline
B.singleQuoted
parseQq :: PandocMonad m => MdocParser m Inlines
parseQq :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseQq = Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
lineEnclosure Text
"Qq" ((Many Inline -> Many Inline) -> MdocParser m (Many Inline))
-> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall a b. (a -> b) -> a -> b
$ \Many Inline
x -> Many Inline
"\"" Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
x Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
"\""
parseQo :: PandocMonad m => MdocParser m Inlines
parseQo :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseQo = Text
-> Text
-> (Many Inline -> Many Inline)
-> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text
-> Text
-> (Many Inline -> Many Inline)
-> MdocParser m (Many Inline)
multilineEnclosure Text
"Qo" Text
"Qc" ((Many Inline -> Many Inline) -> MdocParser m (Many Inline))
-> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall a b. (a -> b) -> a -> b
$ \Many Inline
x -> Many Inline
"\"" Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
x Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
"\""
parsePq :: PandocMonad m => MdocParser m Inlines
parsePq :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parsePq = Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
lineEnclosure Text
"Pq" ((Many Inline -> Many Inline) -> MdocParser m (Many Inline))
-> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall a b. (a -> b) -> a -> b
$ \Many Inline
x -> Many Inline
"(" Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
x Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
")"
parsePo :: PandocMonad m => MdocParser m Inlines
parsePo :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parsePo = Text
-> Text
-> (Many Inline -> Many Inline)
-> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text
-> Text
-> (Many Inline -> Many Inline)
-> MdocParser m (Many Inline)
multilineEnclosure Text
"Po" Text
"Pc" ((Many Inline -> Many Inline) -> MdocParser m (Many Inline))
-> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall a b. (a -> b) -> a -> b
$ \Many Inline
x -> Many Inline
"(" Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
x Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
")"
parseBq :: PandocMonad m => MdocParser m Inlines
parseBq :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseBq = Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
lineEnclosure Text
"Bq" ((Many Inline -> Many Inline) -> MdocParser m (Many Inline))
-> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall a b. (a -> b) -> a -> b
$ \Many Inline
x -> Many Inline
"[" Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
x Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
"]"
parseBo :: PandocMonad m => MdocParser m Inlines
parseBo :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseBo = Text
-> Text
-> (Many Inline -> Many Inline)
-> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text
-> Text
-> (Many Inline -> Many Inline)
-> MdocParser m (Many Inline)
multilineEnclosure Text
"Bo" Text
"Bc" ((Many Inline -> Many Inline) -> MdocParser m (Many Inline))
-> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall a b. (a -> b) -> a -> b
$ \Many Inline
x -> Many Inline
"[" Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
x Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
"]"
parseOp :: PandocMonad m => MdocParser m Inlines
parseOp :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseOp = Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
lineEnclosure Text
"Op" ((Many Inline -> Many Inline) -> MdocParser m (Many Inline))
-> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall a b. (a -> b) -> a -> b
$ \Many Inline
x -> Many Inline
"[" Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
x Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
"]"
parseOo :: PandocMonad m => MdocParser m Inlines
parseOo :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseOo = Text
-> Text
-> (Many Inline -> Many Inline)
-> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text
-> Text
-> (Many Inline -> Many Inline)
-> MdocParser m (Many Inline)
multilineEnclosure Text
"Oo" Text
"Oc" ((Many Inline -> Many Inline) -> MdocParser m (Many Inline))
-> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall a b. (a -> b) -> a -> b
$ \Many Inline
x -> Many Inline
"[" Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
x Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
"]"
parseBrq :: PandocMonad m => MdocParser m Inlines
parseBrq :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseBrq = Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
lineEnclosure Text
"Brq" ((Many Inline -> Many Inline) -> MdocParser m (Many Inline))
-> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall a b. (a -> b) -> a -> b
$ \Many Inline
x -> Many Inline
"{" Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
x Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
"}"
parseBro :: PandocMonad m => MdocParser m Inlines
parseBro :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseBro = Text
-> Text
-> (Many Inline -> Many Inline)
-> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text
-> Text
-> (Many Inline -> Many Inline)
-> MdocParser m (Many Inline)
multilineEnclosure Text
"Bro" Text
"Brc" ((Many Inline -> Many Inline) -> MdocParser m (Many Inline))
-> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall a b. (a -> b) -> a -> b
$ \Many Inline
x -> Many Inline
"{" Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
x Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
"}"
parseAq :: PandocMonad m => MdocParser m Inlines
parseAq :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseAq = Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
lineEnclosure Text
"Aq" ((Many Inline -> Many Inline) -> MdocParser m (Many Inline))
-> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall a b. (a -> b) -> a -> b
$ \Many Inline
x -> Many Inline
"⟨" Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
x Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
"⟩"
parseAo :: PandocMonad m => MdocParser m Inlines
parseAo :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseAo = Text
-> Text
-> (Many Inline -> Many Inline)
-> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text
-> Text
-> (Many Inline -> Many Inline)
-> MdocParser m (Many Inline)
multilineEnclosure Text
"Ao" Text
"Ac" ((Many Inline -> Many Inline) -> MdocParser m (Many Inline))
-> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall a b. (a -> b) -> a -> b
$ \Many Inline
x -> Many Inline
"⟨" Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
x Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
"⟩"
parseDl :: PandocMonad m => MdocParser m Blocks
parseDl :: forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseDl = do
inner <- Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
lineEnclosure Text
"Dl" Many Inline -> Many Inline
forall a. a -> a
id
return $ B.codeBlock (stringify inner)
parseD1 :: PandocMonad m => MdocParser m Blocks
parseD1 :: forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseD1 = do
inner <- Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> (Many Inline -> Many Inline) -> MdocParser m (Many Inline)
lineEnclosure Text
"D1" Many Inline -> Many Inline
forall a. a -> a
id
return $ B.divWith (cls "display") $ B.plain inner
parseNm :: PandocMonad m => MdocParser m Inlines
parseNm :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseNm = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Nm"
mnm <- (MdocState -> Maybe Text
progName (MdocState -> Maybe Text)
-> ParsecT [MdocToken] MdocState m MdocState
-> ParsecT [MdocToken] MdocState m (Maybe Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m MdocState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState)
(op, rg, cl) <- delimitedArgs $ option mempty litsToInlines
return $ case (mnm, rg) of
(Just Text
nm, Many Inline
x) | Many Inline -> Bool
forall a. Many a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Many Inline
x ->
Many Inline
op Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Text -> Many Inline
ok Text
nm Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
cl
(Maybe Text
_, Many Inline
x) ->
Many Inline
op Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> (Text -> Many Inline
ok (Text -> Many Inline)
-> (Many Inline -> Text) -> Many Inline -> Many Inline
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Many Inline -> Text
forall a. Walkable Inline a => a -> Text
stringify) Many Inline
x Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
cl
where
ok :: Text -> Many Inline
ok = Attr -> Text -> Many Inline
B.codeWith (Text -> Attr
cls Text
"Nm")
parseXr :: PandocMonad m => MdocParser m Inlines
parseXr :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseXr = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Xr"
(open, (name, section), close) <- MdocParser m (Text, Text)
-> MdocParser m (Many Inline, (Text, Text), Many Inline)
forall (m :: * -> *) x.
PandocMonad m =>
MdocParser m x -> MdocParser m (Many Inline, x, Many Inline)
delimitedArgs MdocParser m (Text, Text)
f
let ref = Text
name Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"(" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
section Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
")"
return $ open <> B.spanWith (cls "Xr") (B.str ref) <> close
where
f :: MdocParser m (Text, Text)
f = do
n <- MdocParser m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
lit MdocParser m MdocToken -> String -> MdocParser m MdocToken
forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"Xr manual name"
s <- lit <?> "Xr manual section"
return (toString n, toString s)
parseIn :: PandocMonad m => MdocParser m Inlines
parseIn :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseIn = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"In"
openClose <- MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
closingDelimiters
openOpen <- openingDelimiters
header <- toString <$> lit
close <- closingDelimiters
return $ open openClose openOpen <> B.codeWith (cls "In") ("<" <> header <> ">") <> close
where
open :: Many Inline -> Many Inline -> Many Inline
open Many Inline
a Many Inline
b
| Many Inline -> Bool
forall a. Many a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Many Inline
a = Many Inline
b
| Many Inline -> Bool
forall a. Many a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Many Inline
b = Many Inline
a
| Bool
otherwise = Many Inline
a Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
B.space Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
b
parseFd :: PandocMonad m => MdocParser m Inlines
parseFd :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseFd = Text -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m (Many Inline)
codeLikeInline Text
"Fd"
parseFt :: PandocMonad m => MdocParser m Inlines
parseFt :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseFt = Text -> Text -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> MdocParser m (Many Inline)
codeLikeInline' Text
"Ft" Text
"variable"
formatFunction :: T.Text -> [Inlines] -> Inlines
formatFunction :: Text -> [Many Inline] -> Many Inline
formatFunction Text
nm [Many Inline]
args = Attr -> Text -> Many Inline
B.codeWith (Text -> Attr
cls Text
"Fn") Text
nm Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
"(" Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
args' Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
")"
where
args' :: Many Inline
args' = [Many Inline] -> Many Inline
forall a. Monoid a => [a] -> a
mconcat ([Many Inline] -> Many Inline) -> [Many Inline] -> Many Inline
forall a b. (a -> b) -> a -> b
$ Many Inline -> [Many Inline] -> [Many Inline]
forall a. a -> [a] -> [a]
intersperse (Many Inline
", ") [Many Inline]
args
parseFn :: PandocMonad m => MdocParser m Inlines
parseFn :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseFn = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Fn"
(op, (nm, args), cl) <- MdocParser m (Text, [Text])
-> MdocParser m (Many Inline, (Text, [Text]), Many Inline)
forall (m :: * -> *) x.
PandocMonad m =>
MdocParser m x -> MdocParser m (Many Inline, x, Many Inline)
delimitedArgs MdocParser m (Text, [Text])
f
return $ op <> formatFunction nm (fmap (B.codeWith (cls "variable")) args) <> cl
where
f :: MdocParser m (Text, [Text])
f = do
nm <- MdocToken -> Text
toString (MdocToken -> Text)
-> MdocParser m MdocToken -> ParsecT [MdocToken] MdocState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MdocParser m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
lit
args <- option [] litsToText
return (nm, args)
parseFa :: PandocMonad m => MdocParser m Inlines
parseFa :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseFa = Text -> Text -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> MdocParser m (Many Inline)
codeLikeInline' Text
"Fa" Text
"variable"
parseFo :: PandocMonad m => MdocParser m Inlines
parseFo :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseFo = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Fo"
nm <- MdocToken -> Text
toString (MdocToken -> Text)
-> MdocParser m MdocToken -> ParsecT [MdocToken] MdocState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MdocParser m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
lit
eol
args <- many (parseFa <* eol)
macro "Fc"
return $ formatFunction nm args
parseLk :: PandocMonad m => MdocParser m Inlines
parseLk :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseLk = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Lk"
openClose <- MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
closingDelimiters
openOpen <- openingDelimiters
url <- toString <$> lit
inner <- many segment >>= spacify
close <- closingDelimiters
let label | Many Inline -> Bool
forall a. Many a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Many Inline
inner = Text -> Many Inline
B.str Text
url
| Bool
otherwise = Many Inline
inner
return $ open openClose openOpen <> B.link url "" label <> close
where
open :: Many Inline -> Many Inline -> Many Inline
open Many Inline
a Many Inline
b
| Many Inline -> Bool
forall a. Many a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Many Inline
a = Many Inline
b
| Many Inline -> Bool
forall a. Many a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Many Inline
b = Many Inline
a
| Bool
otherwise = Many Inline
a Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
B.space Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
b
end :: ParsecT [MdocToken] st m MdocToken
end = (MdocToken -> Bool) -> ParsecT [MdocToken] st m MdocToken
forall (m :: * -> *) st.
Monad m =>
(MdocToken -> Bool) -> ParsecT [MdocToken] st m MdocToken
msatisfy MdocToken -> Bool
newControlContext
segment :: MdocParser m (Many Inline)
segment = do
a <- MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
openingDelimiters
m <- option mempty litsToInlines
z <-
try (closingDelimiters <* notFollowedBy end)
<|> option mempty pipes
guard $ not $ all null [a, m, z]
return $ a <> m <> z
parsebr :: PandocMonad m => MdocParser m Inlines
parsebr :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parsebr = Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
emptyMacro Text
"br" MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
forall a b.
ParsecT [MdocToken] MdocState m a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Many Inline -> ParsecT [MdocToken] MdocState m (Many Inline)
forall a. a -> ParsecT [MdocToken] MdocState m a
forall (m :: * -> *) a. Monad m => a -> m a
return Many Inline
B.linebreak
parseNs :: PandocMonad m => MdocParser m Inlines
parseNs :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseNs = Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Ns" MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
forall a b.
ParsecT [MdocToken] MdocState m a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Many Inline -> ParsecT [MdocToken] MdocState m (Many Inline)
forall a. a -> ParsecT [MdocToken] MdocState m a
forall (m :: * -> *) a. Monad m => a -> m a
return Many Inline
noSpace
parsePf :: PandocMonad m => MdocParser m Inlines
parsePf :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parsePf = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Pf"
t <- MdocToken -> Text
toString (MdocToken -> Text)
-> MdocParser m MdocToken -> ParsecT [MdocToken] MdocState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MdocParser m MdocToken
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m t
anyToken
rest <- getInput
pos <- getPosition
setInput $ (Macro "Ns" pos):rest
return $ B.str t
parseAp :: PandocMonad m => MdocParser m Inlines
parseAp :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseAp = Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Ap" MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
forall a b.
ParsecT [MdocToken] MdocState m a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Many Inline -> ParsecT [MdocToken] MdocState m (Many Inline)
forall a. a -> ParsecT [MdocToken] MdocState m a
forall (m :: * -> *) a. Monad m => a -> m a
return Many Inline
apMacro
parseEx :: PandocMonad m => MdocParser m Inlines
parseEx :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseEx = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Ex"
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
"-std"
args <- (MdocToken -> Text) -> [MdocToken] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap MdocToken -> Text
toString ([MdocToken] -> [Text])
-> ParsecT [MdocToken] MdocState m [MdocToken]
-> ParsecT [MdocToken] MdocState m [Text]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m [MdocToken]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many MdocParser m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
lit
pn <- progName <$> getState
eol
return $ "The"
<> B.space
<> utils pn args
<> B.space
<> "0 on success, and >0 if an error occurs."
where
nm :: Text -> Many Inline
nm = Attr -> Text -> Many Inline
B.codeWith (Text -> Attr
cls Text
"Nm")
sing :: Many Inline
sing = Many Inline
"utility exits"
plur :: Many Inline
plur = Many Inline
"utilities exit"
utils :: Maybe Text -> [Text] -> Many Inline
utils (Just Text
x) [] = Text -> Many Inline
nm Text
x Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
B.space Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
sing
utils Maybe Text
_ [Text
x] = Text -> Many Inline
nm Text
x Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
B.space Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
sing
utils Maybe Text
_ [Text
x,Text
y] = Text -> Many Inline
nm Text
x Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
B.space Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
"and" Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
B.space Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Text -> Many Inline
nm Text
y Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
B.space Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
plur
utils Maybe Text
pn [Text]
xs =
case (Maybe Text
pn, [Text] -> Maybe ([Text], Text)
forall a. [a] -> Maybe ([a], a)
unsnoc [Text]
xs) of
(Maybe Text
Nothing, Maybe ([Text], Text)
Nothing) -> Many Inline
sing
(Maybe Text
_, Just ([Text]
hd, Text
end)) -> [Many Inline] -> Many Inline
forall a. Monoid a => [a] -> a
mconcat ((Many Inline -> [Many Inline] -> [Many Inline]
forall a. a -> [a] -> [a]
intersperse (Many Inline
", ") ([Many Inline] -> [Many Inline])
-> ([Text] -> [Many Inline]) -> [Text] -> [Many Inline]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> Many Inline) -> [Text] -> [Many Inline]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> Many Inline
nm) [Text]
hd) Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
", and " Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Text -> Many Inline
nm Text
end Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
B.space Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
plur
(Just Text
p, Maybe ([Text], Text)
Nothing) -> Text -> Many Inline
nm Text
p Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
B.space Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
sing
parseRv :: (PandocMonad m) => MdocParser m Inlines
parseRv :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseRv = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Rv"
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
"-std"
args <- (MdocToken -> Text) -> [MdocToken] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap MdocToken -> Text
toString ([MdocToken] -> [Text])
-> ParsecT [MdocToken] MdocState m [MdocToken]
-> ParsecT [MdocToken] MdocState m [Text]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m [MdocToken]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many MdocParser m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
lit
pn <- progName <$> getState
eol
return $ go pn args
where
nm :: Text -> Many Inline
nm Text
a = Attr -> Text -> Many Inline
B.codeWith (Text -> Attr
cls Text
"Fn") Text
a Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
"()"
nothing :: Many Inline
nothing = Many Inline
"Upon successful completion, the value 0 is returned;"
sing :: Many Inline
sing = Many Inline
"function returns"
plur :: Many Inline
plur = Many Inline
"functions return"
success :: Many Inline
success = Many Inline
"the value 0 if successful;"
errno :: Many Inline
errno =
Many Inline
"otherwise the value -1 is returned and the global variable"
Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Attr -> Text -> Many Inline
B.codeWith (Text -> Attr
cls Text
"variable") Text
"errno"
Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
"is set to indicate the error."
message :: Many Inline -> Many Inline
message Many Inline
conj =
Many Inline
"The"
Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
B.space
Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
conj
Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
B.space
Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
success
Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
B.space
Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
errno
go :: Maybe Text -> [Text] -> Many Inline
go (Just Text
x) [] = Many Inline -> Many Inline
message (Text -> Many Inline
nm Text
x Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
B.space Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
sing)
go Maybe Text
_ [Text
x] = Many Inline -> Many Inline
message (Text -> Many Inline
nm Text
x Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
B.space Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
sing)
go Maybe Text
_ [Text
x, Text
y] = Many Inline -> Many Inline
message (Text -> Many Inline
nm Text
x Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
B.space Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
"and" Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
B.space Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Text -> Many Inline
nm Text
y Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
B.space Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
plur)
go Maybe Text
pn [Text]
xs =
case (Maybe Text
pn, [Text] -> Maybe ([Text], Text)
forall a. [a] -> Maybe ([a], a)
unsnoc [Text]
xs) of
(Maybe Text
Nothing, Maybe ([Text], Text)
Nothing) -> Many Inline
nothing Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
B.space Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
errno
(Maybe Text
_, Just ([Text]
hd, Text
end)) -> Many Inline -> Many Inline
message ([Many Inline] -> Many Inline
forall a. Monoid a => [a] -> a
mconcat ((Many Inline -> [Many Inline] -> [Many Inline]
forall a. a -> [a] -> [a]
intersperse (Many Inline
", ") ([Many Inline] -> [Many Inline])
-> ([Text] -> [Many Inline]) -> [Text] -> [Many Inline]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> Many Inline) -> [Text] -> [Many Inline]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> Many Inline
nm) [Text]
hd) Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
", and " Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Text -> Many Inline
nm Text
end Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
B.space Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
plur)
(Just Text
p, Maybe ([Text], Text)
Nothing) -> Many Inline -> Many Inline
message (Text -> Many Inline
nm Text
p Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
B.space Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Many Inline
sing)
parseSt :: PandocMonad m => MdocParser m Inlines
parseSt :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseSt = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"St"
(Lit std pos) <- MdocParser m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
lit
case standard std of
Maybe Text
Nothing -> do
LogMessage -> ParsecT [MdocToken] MdocState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasLogMessages st) =>
LogMessage -> ParsecT s st m ()
logMessage (LogMessage -> ParsecT [MdocToken] MdocState m ())
-> LogMessage -> ParsecT [MdocToken] MdocState m ()
forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
SkippedContent (Text
"unrecognized argument to St: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
std) SourcePos
pos
Many Inline -> ParsecT [MdocToken] MdocState m (Many Inline)
forall a. a -> ParsecT [MdocToken] MdocState m a
forall (m :: * -> *) a. Monad m => a -> m a
return Many Inline
forall a. Monoid a => a
mempty
Just Text
t -> Many Inline -> ParsecT [MdocToken] MdocState m (Many Inline)
forall a. a -> ParsecT [MdocToken] MdocState m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Many Inline -> ParsecT [MdocToken] MdocState m (Many Inline))
-> Many Inline -> ParsecT [MdocToken] MdocState m (Many Inline)
forall a b. (a -> b) -> a -> b
$ Text -> Many Inline
B.text Text
t
parseLb :: PandocMonad m => MdocParser m Inlines
parseLb :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseLb = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Lb"
library <- MdocToken -> Text
toString (MdocToken -> Text)
-> MdocParser m MdocToken -> ParsecT [MdocToken] MdocState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MdocParser m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
lit
return $ "library" <> B.space <> B.doubleQuoted (B.str library)
unixVersion :: PandocMonad m => T.Text -> T.Text -> MdocParser m Inlines
unixVersion :: forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> MdocParser m (Many Inline)
unixVersion Text
m Text
s = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
m
(o, v, c) <- MdocParser m Text -> MdocParser m (Many Inline, Text, Many Inline)
forall (m :: * -> *) x.
PandocMonad m =>
MdocParser m x -> MdocParser m (Many Inline, x, Many Inline)
delimitedArgs (Text -> MdocParser m Text -> MdocParser m Text
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Text
forall a. Monoid a => a
mempty (MdocToken -> Text
toString (MdocToken -> Text) -> MdocParser m MdocToken -> MdocParser m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MdocParser m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
lit))
return $ o <> B.str s <> f v <> c
where
f :: Text -> Many Inline
f Text
v | Text -> Bool
T.null Text
v = Many Inline
forall a. Monoid a => a
mempty
| Bool
otherwise = Many Inline
B.space Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Text -> Many Inline
B.str Text
v
parseAt :: PandocMonad m => MdocParser m Inlines
parseAt :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseAt = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"At"
(o, v, c) <- MdocParser m (Maybe Text)
-> MdocParser m (Many Inline, Maybe Text, Many Inline)
forall (m :: * -> *) x.
PandocMonad m =>
MdocParser m x -> MdocParser m (Many Inline, x, Many Inline)
delimitedArgs (ParsecT [MdocToken] MdocState m Text -> MdocParser m (Maybe Text)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (MdocToken -> Text
toString (MdocToken -> Text)
-> MdocParser m MdocToken -> ParsecT [MdocToken] MdocState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MdocParser m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
lit))
let v' = Text -> (Text -> Text) -> Maybe Text -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
"AT&T UNIX" Text -> Text
attVer Maybe Text
v
return $ o <> B.text v' <> c
where
isVersion :: a -> Bool
isVersion a
x = a
x a -> [a] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [a
"1", a
"2", a
"3", a
"4", a
"5", a
"6", a
"7"]
isRelease :: a -> Bool
isRelease a
x = a
x a -> [a] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [a
"1", a
"2", a
"3", a
"4"]
attVer :: Text -> Text
attVer (Text -> Text -> Maybe Text
T.stripPrefix Text
"v" -> Just Text
ver)
| Text -> Bool
forall {a}. (Eq a, IsString a) => a -> Bool
isVersion Text
ver = Text
"Version " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
ver Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" AT&T UNIX"
attVer Text
"32v" = Text
"Version 7 AT&T UNIX/32V"
attVer Text
"III" = Text
"AT&T System III UNIX"
attVer (Text -> Text -> Maybe Text
T.stripPrefix Text
"V." -> Just Text
release)
| Text -> Bool
forall {a}. (Eq a, IsString a) => a -> Bool
isRelease Text
release = Text
"AT&T System V Release " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
release Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" UNIX"
attVer Text
"V" = Text
"AT&T System V UNIX"
attVer Text
x = Text
"AT&T UNIX " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
x
parseBsx :: PandocMonad m => MdocParser m Inlines
parseBsx :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseBsx = Text -> Text -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> MdocParser m (Many Inline)
unixVersion Text
"Bsx" Text
"BSD/OS"
parseBx :: PandocMonad m => MdocParser m Inlines
parseBx :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseBx = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Bx"
(o, v, c) <- MdocParser m [Text]
-> MdocParser m (Many Inline, [Text], Many Inline)
forall (m :: * -> *) x.
PandocMonad m =>
MdocParser m x -> MdocParser m (Many Inline, x, Many Inline)
delimitedArgs MdocParser m [Text]
zeroToTwoLits
return $ o <> bsd v <> c
where
zeroToTwoLits :: MdocParser m [Text]
zeroToTwoLits = do
toks <- ParsecT [MdocToken] MdocState m [MdocToken]
-> ParsecT [MdocToken] MdocState m [MdocToken]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Int
-> MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m [MdocToken]
forall s (m :: * -> *) t u a.
Stream s m t =>
Int -> ParsecT s u m a -> ParsecT s u m [a]
count Int
2 MdocParser m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
lit) ParsecT [MdocToken] MdocState m [MdocToken]
-> ParsecT [MdocToken] MdocState m [MdocToken]
-> ParsecT [MdocToken] MdocState m [MdocToken]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Int
-> MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m [MdocToken]
forall s (m :: * -> *) t u a.
Stream s m t =>
Int -> ParsecT s u m a -> ParsecT s u m [a]
count Int
1 MdocParser m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
lit ParsecT [MdocToken] MdocState m [MdocToken]
-> ParsecT [MdocToken] MdocState m [MdocToken]
-> ParsecT [MdocToken] MdocState m [MdocToken]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Int
-> MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m [MdocToken]
forall s (m :: * -> *) t u a.
Stream s m t =>
Int -> ParsecT s u m a -> ParsecT s u m [a]
count Int
0 MdocParser m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
lit
return $ toString <$> toks
bsd :: [Text] -> Many Inline
bsd [] = Text -> Many Inline
B.str Text
"BSD"
bsd [Text
x] = Text -> Many Inline
B.str (Text -> Many Inline) -> Text -> Many Inline
forall a b. (a -> b) -> a -> b
$ Text
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"BSD"
bsd (Text
x:Text
y:[Text]
_) = Text -> Many Inline
B.str (Text
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"BSD" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"-" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> Text
T.toTitle Text
y)
parseDx :: PandocMonad m => MdocParser m Inlines
parseDx :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseDx = Text -> Text -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> MdocParser m (Many Inline)
unixVersion Text
"Dx" Text
"DragonFly"
parseFx :: PandocMonad m => MdocParser m Inlines
parseFx :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseFx = Text -> Text -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> MdocParser m (Many Inline)
unixVersion Text
"Fx" Text
"FreeBSD"
parseNx :: PandocMonad m => MdocParser m Inlines
parseNx :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseNx = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Nx"
(o, v, c) <- MdocParser m Text -> MdocParser m (Many Inline, Text, Many Inline)
forall (m :: * -> *) x.
PandocMonad m =>
MdocParser m x -> MdocParser m (Many Inline, x, Many Inline)
delimitedArgs (Text -> MdocParser m Text -> MdocParser m Text
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Text
forall a. Monoid a => a
mempty (MdocToken -> Text
toString (MdocToken -> Text) -> MdocParser m MdocToken -> MdocParser m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MdocParser m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
lit))
return $ o <> "NetBSD" <> f v <> c
where
f :: Text -> Many Inline
f Text
v | Text -> Bool
T.null Text
v = Many Inline
forall a. Monoid a => a
mempty
| Bool
otherwise = Many Inline
B.space Many Inline -> Many Inline -> Many Inline
forall a. Semigroup a => a -> a -> a
<> Text -> Many Inline
B.str (Text -> Either PandocError Text -> Text
forall b a. b -> Either a b -> b
fromRight Text
v (Either PandocError Text -> Text)
-> Either PandocError Text -> Text
forall a b. (a -> b) -> a -> b
$ Parsec Sources () Text -> () -> Text -> Either PandocError Text
forall t st a.
ToSources t =>
Parsec Sources st a -> st -> t -> Either PandocError a
readWith Parsec Sources () Text
forall {u}. ParsecT Sources u Identity Text
earlyNetBSDVersion () Text
v)
earlyNetBSDVersion :: ParsecT Sources u Identity Text
earlyNetBSDVersion = do
major <- String -> ParsecT Sources u Identity Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m Char
oneOf String
"01"
dot <- char '.'
minor <- digit
ltr <- satisfy isAsciiLower
return $ T.pack [major, dot, minor, toUpper ltr]
parseOx :: PandocMonad m => MdocParser m Inlines
parseOx :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseOx = Text -> Text -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> MdocParser m (Many Inline)
unixVersion Text
"Ox" Text
"OpenBSD"
parseUx :: PandocMonad m => MdocParser m Inlines
parseUx :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseUx = Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Ux" MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
forall a b.
ParsecT [MdocToken] MdocState m a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Many Inline -> ParsecT [MdocToken] MdocState m (Many Inline)
forall a. a -> ParsecT [MdocToken] MdocState m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Many Inline
B.str Text
"UNIX")
parseInlineMacro :: PandocMonad m => MdocParser m Inlines
parseInlineMacro :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseInlineMacro = [ParsecT [MdocToken] MdocState m (Many Inline)]
-> ParsecT [MdocToken] MdocState m (Many Inline)
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice ([ParsecT [MdocToken] MdocState m (Many Inline)]
forall (m :: * -> *). PandocMonad m => [MdocParser m (Many Inline)]
synopsisTopicMacros [ParsecT [MdocToken] MdocState m (Many Inline)]
-> [ParsecT [MdocToken] MdocState m (Many Inline)]
-> [ParsecT [MdocToken] MdocState m (Many Inline)]
forall a. Semigroup a => a -> a -> a
<> [ParsecT [MdocToken] MdocState m (Many Inline)]
forall (m :: * -> *). PandocMonad m => [MdocParser m (Many Inline)]
otherInlineMacros) ParsecT [MdocToken] MdocState m (Many Inline)
-> String -> ParsecT [MdocToken] MdocState m (Many Inline)
forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"inline macro"
synopsisTopicMacros :: PandocMonad m => [MdocParser m Inlines]
synopsisTopicMacros :: forall (m :: * -> *). PandocMonad m => [MdocParser m (Many Inline)]
synopsisTopicMacros =
[MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseNm, MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseCd, MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseFd, MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseFn, MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseFo, MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseIn, MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseVt, MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseFt]
otherInlineMacros :: PandocMonad m => [MdocParser m Inlines]
otherInlineMacros :: forall (m :: * -> *). PandocMonad m => [MdocParser m (Many Inline)]
otherInlineMacros =
[ MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseSy,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseEm,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseLk,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseLi,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseEv,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseDv,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseMt,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parsePa,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseFl,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseCm,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseIc,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseEr,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseAd,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseVa,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseAn,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseMs,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseSx,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseAr,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseFa,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseNo,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseTn,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseXr,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseQl,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseOp,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseSq,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseDq,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseQq,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parsePq,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseBq,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseBrq,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseAq,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseEo,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseSo,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseDo,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseQo,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parsePo,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseBo,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseBro,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseAo,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseOo,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseBf,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseRsInline,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseEx,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseRv,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseSt,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseLb,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseAt,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseBsx,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseBx,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseDx,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseFx,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseNx,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseOx,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseUx,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parsebr,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseAp,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parsePf,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseNs,
MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
skipUnsupportedInlines
]
parseInline :: PandocMonad m => MdocParser m Inlines
parseInline :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseInline = MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseStrs MdocParser m (Many Inline)
-> MdocParser m (Many Inline) -> MdocParser m (Many Inline)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (ParsecT [MdocToken] MdocState m [Many Inline]
controlLine ParsecT [MdocToken] MdocState m [Many Inline]
-> ([Many Inline] -> MdocParser m (Many Inline))
-> MdocParser m (Many Inline)
forall a b.
ParsecT [MdocToken] MdocState m a
-> (a -> ParsecT [MdocToken] MdocState m b)
-> ParsecT [MdocToken] MdocState m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [Many Inline] -> MdocParser m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
[Many Inline] -> MdocParser m (Many Inline)
spacify) MdocParser m (Many Inline) -> String -> MdocParser m (Many Inline)
forall s u (m :: * -> *) a.
ParsecT s u m a -> String -> ParsecT s u m a
<?> String
"text lines or inline macros"
where
safeEol :: ParsecT [MdocToken] MdocState m ()
safeEol = do
amNested <- MdocState -> Bool
inLineEnclosure (MdocState -> Bool)
-> ParsecT [MdocToken] MdocState m MdocState
-> ParsecT [MdocToken] MdocState m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m MdocState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
unless amNested $ optional eol
controlLine :: ParsecT [MdocToken] MdocState m [Many Inline]
controlLine = MdocParser m (Many Inline)
-> ParsecT [MdocToken] MdocState m [Many Inline]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 ((MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseInlineMacro MdocParser m (Many Inline)
-> MdocParser m (Many Inline) -> MdocParser m (Many Inline)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MdocParser m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
litsAndDelimsToInlines) MdocParser m (Many Inline)
-> ParsecT [MdocToken] MdocState m () -> MdocParser m (Many Inline)
forall a b.
ParsecT [MdocToken] MdocState m a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT [MdocToken] MdocState m ()
safeEol)
parseInlines :: PandocMonad m => MdocParser m Inlines
parseInlines :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseInlines = ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m [Many Inline]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 (ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseSmToggle ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseInline) ParsecT [MdocToken] MdocState m [Many Inline]
-> ([Many Inline] -> ParsecT [MdocToken] MdocState m (Many Inline))
-> ParsecT [MdocToken] MdocState m (Many Inline)
forall a b.
ParsecT [MdocToken] MdocState m a
-> (a -> ParsecT [MdocToken] MdocState m b)
-> ParsecT [MdocToken] MdocState m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [Many Inline] -> ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *).
PandocMonad m =>
[Many Inline] -> MdocParser m (Many Inline)
spacify
parsePara :: PandocMonad m => MdocParser m Blocks
parsePara :: forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parsePara = Many Inline -> Blocks
B.para (Many Inline -> Blocks)
-> (Many Inline -> Many Inline) -> Many Inline -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Many Inline -> Many Inline
B.trimInlines (Many Inline -> Blocks)
-> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseInlines ParsecT [MdocToken] MdocState m Blocks
-> ParsecT [MdocToken] MdocState m ()
-> ParsecT [MdocToken] MdocState m Blocks
forall a b.
ParsecT [MdocToken] MdocState m a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*
ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (Text -> ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
emptyMacro Text
"Pp" ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m MdocToken
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Text -> ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
emptyMacro Text
"Lp")
parseDisplay :: PandocMonad m => MdocParser m Blocks
parseDisplay :: forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseDisplay = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
"-filled" MdocParser m MdocToken
-> MdocParser m MdocToken -> MdocParser m MdocToken
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
"-ragged" MdocParser m MdocToken
-> MdocParser m MdocToken -> MdocParser m MdocToken
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
"-centered"
MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m [MdocToken]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m [MdocToken])
-> MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m [MdocToken]
forall a b. (a -> b) -> a -> b
$ (Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
"-offset" MdocParser m MdocToken
-> MdocParser m MdocToken -> MdocParser m MdocToken
forall a b.
ParsecT [MdocToken] MdocState m a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> MdocParser m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
lit) MdocParser m MdocToken
-> MdocParser m MdocToken -> MdocParser m MdocToken
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
"-compact")
MdocParser m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
eol
Attr -> Blocks -> Blocks
B.divWith (Text -> Attr
cls Text
"display") (Blocks -> Blocks) -> ([Blocks] -> Blocks) -> [Blocks] -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Blocks] -> Blocks
forall a. Monoid a => [a] -> a
mconcat ([Blocks] -> Blocks)
-> ParsecT [MdocToken] MdocState m [Blocks]
-> ParsecT [MdocToken] MdocState m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m Blocks
-> ParsecT [MdocToken] MdocState m [Blocks]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT [MdocToken] MdocState m Blocks
forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseRegularBlock
parseUnfilled :: PandocMonad m => MdocParser m Blocks
parseUnfilled :: forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseUnfilled = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
"-unfilled"
MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m [MdocToken]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m [MdocToken])
-> MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m [MdocToken]
forall a b. (a -> b) -> a -> b
$ (Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
"-offset" MdocParser m MdocToken
-> MdocParser m MdocToken -> MdocParser m MdocToken
forall a b.
ParsecT [MdocToken] MdocState m a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> MdocParser m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
lit) MdocParser m MdocToken
-> MdocParser m MdocToken -> MdocParser m MdocToken
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
"-compact")
MdocParser m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
eol
lns <- ParsecT [MdocToken] MdocState m (Maybe (Many Inline))
-> ParsecT [MdocToken] MdocState m [Maybe (Many Inline)]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (ParsecT [MdocToken] MdocState m (Maybe (Many Inline))
-> ParsecT [MdocToken] MdocState m [Maybe (Many Inline)])
-> ParsecT [MdocToken] MdocState m (Maybe (Many Inline))
-> ParsecT [MdocToken] MdocState m [Maybe (Many Inline)]
forall a b. (a -> b) -> a -> b
$ Many Inline -> Maybe (Many Inline)
forall a. a -> Maybe a
Just (Many Inline -> Maybe (Many Inline))
-> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Maybe (Many Inline))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m (Many Inline)
parseStrPreserveSpace
ParsecT [MdocToken] MdocState m (Maybe (Many Inline))
-> ParsecT [MdocToken] MdocState m (Maybe (Many Inline))
-> ParsecT [MdocToken] MdocState m (Maybe (Many Inline))
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Maybe (Many Inline)
forall a. Maybe a
Nothing Maybe (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Maybe (Many Inline))
forall a b.
a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseSmToggle
ParsecT [MdocToken] MdocState m (Maybe (Many Inline))
-> ParsecT [MdocToken] MdocState m (Maybe (Many Inline))
-> ParsecT [MdocToken] MdocState m (Maybe (Many Inline))
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Many Inline -> Maybe (Many Inline)
forall a. a -> Maybe a
Just (Many Inline -> Maybe (Many Inline))
-> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Maybe (Many Inline))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseInline
ParsecT [MdocToken] MdocState m (Maybe (Many Inline))
-> ParsecT [MdocToken] MdocState m (Maybe (Many Inline))
-> ParsecT [MdocToken] MdocState m (Maybe (Many Inline))
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Many Inline -> Maybe (Many Inline)
forall a. a -> Maybe a
Just Many Inline
"" Maybe (Many Inline)
-> MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m (Maybe (Many Inline))
forall a b.
a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
emptyMacro Text
"Pp"
return $ B.lineBlock (catMaybes lns)
where
parseStrPreserveSpace :: ParsecT [MdocToken] MdocState m (Many Inline)
parseStrPreserveSpace = (Text -> Many Inline
B.str (Text -> Many Inline)
-> (MdocToken -> Text) -> MdocToken -> Many Inline
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MdocToken -> Text
toString) (MdocToken -> Many Inline)
-> MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m (Many Inline)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MdocParser m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
str ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (MdocParser m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
blank MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
forall a b.
ParsecT [MdocToken] MdocState m a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT [MdocToken] MdocState m (Many Inline)
forall a. Monoid a => a
mempty)
parseCodeBlock :: PandocMonad m => MdocParser m Blocks
parseCodeBlock :: forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseCodeBlock = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
"-literal"
MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m [MdocToken]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m [MdocToken])
-> MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m [MdocToken]
forall a b. (a -> b) -> a -> b
$ (Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
"-offset" MdocParser m MdocToken
-> MdocParser m MdocToken -> MdocParser m MdocToken
forall a b.
ParsecT [MdocToken] MdocState m a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> MdocParser m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
lit) MdocParser m MdocToken
-> MdocParser m MdocToken -> MdocParser m MdocToken
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
"-compact")
MdocParser m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
eol
lns <- ParsecT [MdocToken] MdocState m (Maybe Text)
-> ParsecT [MdocToken] MdocState m [Maybe Text]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (ParsecT [MdocToken] MdocState m (Maybe Text)
-> ParsecT [MdocToken] MdocState m [Maybe Text])
-> ParsecT [MdocToken] MdocState m (Maybe Text)
-> ParsecT [MdocToken] MdocState m [Maybe Text]
forall a b. (a -> b) -> a -> b
$ Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text)
-> (MdocToken -> Text) -> MdocToken -> Maybe Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MdocToken -> Text
toString (MdocToken -> Maybe Text)
-> MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m (Maybe Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (MdocParser m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
str MdocParser m MdocToken
-> MdocParser m MdocToken -> MdocParser m MdocToken
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MdocParser m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
blank)
ParsecT [MdocToken] MdocState m (Maybe Text)
-> ParsecT [MdocToken] MdocState m (Maybe Text)
-> ParsecT [MdocToken] MdocState m (Maybe Text)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Maybe Text
forall a. Maybe a
Nothing Maybe Text
-> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Maybe Text)
forall a b.
a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseSmToggle
ParsecT [MdocToken] MdocState m (Maybe Text)
-> ParsecT [MdocToken] MdocState m (Maybe Text)
-> ParsecT [MdocToken] MdocState m (Maybe Text)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text)
-> (Many Inline -> Text) -> Many Inline -> Maybe Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Many Inline -> Text
forall a. Walkable Inline a => a -> Text
stringify (Many Inline -> Maybe Text)
-> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Maybe Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseInline
ParsecT [MdocToken] MdocState m (Maybe Text)
-> ParsecT [MdocToken] MdocState m (Maybe Text)
-> ParsecT [MdocToken] MdocState m (Maybe Text)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"" Maybe Text
-> MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m (Maybe Text)
forall a b.
a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
emptyMacro Text
"Pp"
return $ B.codeBlock (T.unlines (catMaybes lns))
parseBd :: PandocMonad m => MdocParser m Blocks
parseBd :: forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseBd = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Bd"
blk <- MdocParser m Blocks
forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseCodeBlock MdocParser m Blocks -> MdocParser m Blocks -> MdocParser m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MdocParser m Blocks
forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseDisplay MdocParser m Blocks -> MdocParser m Blocks -> MdocParser m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MdocParser m Blocks
forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseUnfilled
emptyMacro "Ed"
return blk
parseBf :: PandocMonad m => MdocParser m Inlines
parseBf :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseBf = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Bf"
xform <- Many Inline -> Many Inline
B.strong (Many Inline -> Many Inline)
-> MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m (Many Inline -> Many Inline)
forall a b.
a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
"Sy" MdocParser m MdocToken
-> MdocParser m MdocToken -> MdocParser m MdocToken
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
"-symbolic")
ParsecT [MdocToken] MdocState m (Many Inline -> Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline -> Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline -> Many Inline)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Many Inline -> Many Inline
B.emph (Many Inline -> Many Inline)
-> MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m (Many Inline -> Many Inline)
forall a b.
a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
"Em" MdocParser m MdocToken
-> MdocParser m MdocToken -> MdocParser m MdocToken
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
"-emphasis")
ParsecT [MdocToken] MdocState m (Many Inline -> Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline -> Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline -> Many Inline)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Many Inline -> Many Inline
code (Many Inline -> Many Inline)
-> MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m (Many Inline -> Many Inline)
forall a b.
a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
"Li" MdocParser m MdocToken
-> MdocParser m MdocToken -> MdocParser m MdocToken
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
"-literal")
eol
ins <- parseInlines
emptyMacro "Ef"
return $ xform ins
where
code :: Many Inline -> Many Inline
code = Text -> Many Inline
B.code (Text -> Many Inline)
-> (Many Inline -> Text) -> Many Inline -> Many Inline
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Many Inline -> Text
forall a. Walkable Inline a => a -> Text
stringify
skipListArgument :: (PandocMonad m) => MdocParser m ()
skipListArgument :: forall (m :: * -> *). PandocMonad m => MdocParser m ()
skipListArgument =
ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m ())
-> ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m ()
forall a b. (a -> b) -> a -> b
$ [ParsecT [MdocToken] MdocState m MdocToken]
-> ParsecT [MdocToken] MdocState m MdocToken
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
[ Text -> ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
"-width" ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m MdocToken
forall a b.
ParsecT [MdocToken] MdocState m a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
lit,
Text -> ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
"-offset" ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m MdocToken
forall a b.
ParsecT [MdocToken] MdocState m a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
lit,
Text -> ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
"-compact"
]
parseItemList :: PandocMonad m => MdocParser m Blocks
parseItemList :: forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseItemList = do
f <- ([ParsecT [MdocToken] MdocState m MdocToken]
-> ParsecT [MdocToken] MdocState m MdocToken
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice ((Text -> ParsecT [MdocToken] MdocState m MdocToken)
-> [Text] -> [ParsecT [MdocToken] MdocState m MdocToken]
forall a b. (a -> b) -> [a] -> [b]
map Text -> ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal [Text
"-bullet", Text
"-dash", Text
"-hyphen", Text
"-item"]) ParsecT [MdocToken] MdocState m MdocToken
-> ([Blocks] -> Blocks)
-> ParsecT [MdocToken] MdocState m ([Blocks] -> Blocks)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> [Blocks] -> Blocks
B.bulletList)
ParsecT [MdocToken] MdocState m ([Blocks] -> Blocks)
-> ParsecT [MdocToken] MdocState m ([Blocks] -> Blocks)
-> ParsecT [MdocToken] MdocState m ([Blocks] -> Blocks)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Text -> ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
"-enum" ParsecT [MdocToken] MdocState m MdocToken
-> ([Blocks] -> Blocks)
-> ParsecT [MdocToken] MdocState m ([Blocks] -> Blocks)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> [Blocks] -> Blocks
B.orderedList
many skipListArgument
eol
items <- many bulletItem
return $ f items
where
bulletItem :: ParsecT [MdocToken] MdocState m Blocks
bulletItem = do
Text -> ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
emptyMacro Text
"It"
[Blocks] -> Blocks
forall a. Monoid a => [a] -> a
mconcat ([Blocks] -> Blocks)
-> ParsecT [MdocToken] MdocState m [Blocks]
-> ParsecT [MdocToken] MdocState m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m Blocks
-> ParsecT [MdocToken] MdocState m [Blocks]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT [MdocToken] MdocState m Blocks
forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseRegularBlock
parseDefinitionList :: PandocMonad m => MdocParser m Blocks
parseDefinitionList :: forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseDefinitionList = do
headParser <- ([ParsecT [MdocToken] MdocState m MdocToken]
-> ParsecT [MdocToken] MdocState m MdocToken
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice ([ParsecT [MdocToken] MdocState m MdocToken]
-> ParsecT [MdocToken] MdocState m MdocToken)
-> ([Text] -> [ParsecT [MdocToken] MdocState m MdocToken])
-> [Text]
-> ParsecT [MdocToken] MdocState m MdocToken
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> ParsecT [MdocToken] MdocState m MdocToken)
-> [Text] -> [ParsecT [MdocToken] MdocState m MdocToken]
forall a b. (a -> b) -> [a] -> [b]
map Text -> ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal) [Text
"-hang", Text
"-inset", Text
"-ohang", Text
"-tag"] ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT
[MdocToken]
MdocState
m
(ParsecT [MdocToken] MdocState m (Many Inline))
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> ParsecT [MdocToken] MdocState m (Many Inline)
parsedHead ParsecT
[MdocToken]
MdocState
m
(ParsecT [MdocToken] MdocState m (Many Inline))
-> ParsecT
[MdocToken]
MdocState
m
(ParsecT [MdocToken] MdocState m (Many Inline))
-> ParsecT
[MdocToken]
MdocState
m
(ParsecT [MdocToken] MdocState m (Many Inline))
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Text -> ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
"-diag" ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT
[MdocToken]
MdocState
m
(ParsecT [MdocToken] MdocState m (Many Inline))
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> ParsecT [MdocToken] MdocState m (Many Inline)
diagHead
many skipListArgument
eol
items <- many (parseSmToggle *> mempty <|> dlItem headParser)
return $ B.definitionList items
where
parsedHead :: ParsecT [MdocToken] MdocState m (Many Inline)
parsedHead = ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT [MdocToken] MdocState m (Many Inline)
xoListHead ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT [MdocToken] MdocState m (Many Inline)
eolListHead
eolListHead :: ParsecT [MdocToken] MdocState m (Many Inline)
eolListHead = do
(MdocState -> MdocState) -> ParsecT [MdocToken] MdocState m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
modifyState ((MdocState -> MdocState) -> ParsecT [MdocToken] MdocState m ())
-> (MdocState -> MdocState) -> ParsecT [MdocToken] MdocState m ()
forall a b. (a -> b) -> a -> b
$ \MdocState
s -> MdocState
s{inLineEnclosure = True}
inner <- ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseInlines
eol
modifyState $ \MdocState
s -> MdocState
s{inLineEnclosure = False}
return inner
diagHead :: ParsecT [MdocToken] MdocState m (Many Inline)
diagHead = ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
argsToInlines
dlItem :: ParsecT [MdocToken] MdocState m a
-> ParsecT [MdocToken] MdocState m (a, [Blocks])
dlItem ParsecT [MdocToken] MdocState m a
hed = do
ParsecT [MdocToken] MdocState m ()
-> ParsecT [MdocToken] MdocState m [()]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ((ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m ())
-> (Text -> ParsecT [MdocToken] MdocState m MdocToken)
-> Text
-> ParsecT [MdocToken] MdocState m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
emptyMacro) Text
"Pp" ParsecT [MdocToken] MdocState m ()
-> ParsecT [MdocToken] MdocState m ()
-> ParsecT [MdocToken] MdocState m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Text -> ParsecT [MdocToken] MdocState m ()
forall (m :: * -> *). PandocMonad m => Text -> MdocParser m ()
skipUnsupportedMacro Text
"Tg")
Text -> ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"It"
dt <- ParsecT [MdocToken] MdocState m a
hed
dd <- mconcat <$> many parseRegularBlock
return (dt, [dd])
xoListHead :: ParsecT [MdocToken] MdocState m (Many Inline)
xoListHead = do
before <- Many Inline
-> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Many Inline
forall a. Monoid a => a
mempty ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseInline
macro "Xo"
optional eol
after <- many1Till parseInlines (emptyMacro "Xc")
spacify (before:after)
parseColumnList :: PandocMonad m => MdocParser m Blocks
parseColumnList :: forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseColumnList = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
literal Text
"-column"
ParsecT [MdocToken] MdocState m ()
-> ParsecT [MdocToken] MdocState m [()]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT [MdocToken] MdocState m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
skipListArgument
MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m [MdocToken]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m [MdocToken])
-> MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m [MdocToken]
forall a b. (a -> b) -> a -> b
$ MdocParser m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
arg MdocParser m MdocToken
-> MdocParser m MdocToken -> MdocParser m MdocToken
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DelimSide -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
DelimSide -> MdocParser m MdocToken
delim DelimSide
Open MdocParser m MdocToken
-> MdocParser m MdocToken -> MdocParser m MdocToken
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DelimSide -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
DelimSide -> MdocParser m MdocToken
delim DelimSide
Middle MdocParser m MdocToken
-> MdocParser m MdocToken -> MdocParser m MdocToken
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> DelimSide -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
DelimSide -> MdocParser m MdocToken
delim DelimSide
Close
ParsecT [MdocToken] MdocState m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
eol
rows <- ParsecT [MdocToken] MdocState m [Blocks]
-> ParsecT [MdocToken] MdocState m [[Blocks]]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many ParsecT [MdocToken] MdocState m [Blocks]
listRow
return $ B.simpleTable [] rows
where
listRow :: ParsecT [MdocToken] MdocState m [Blocks]
listRow = do
MdocParser m MdocToken -> ParsecT [MdocToken] MdocState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
emptyMacro Text
"Pp")
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"It"
(Many Inline -> Blocks) -> [Many Inline] -> [Blocks]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Many Inline -> Blocks
B.plain ([Many Inline] -> [Blocks])
-> ParsecT [MdocToken] MdocState m [Many Inline]
-> ParsecT [MdocToken] MdocState m [Blocks]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m (Many Inline)
-> MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m [Many Inline]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
sepBy (ParsecT [MdocToken] MdocState m (Many Inline)
forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseInlines ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Many Inline -> ParsecT [MdocToken] MdocState m (Many Inline)
forall a. a -> ParsecT [MdocToken] MdocState m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Many Inline
forall a. Monoid a => a
mempty) (Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Ta" MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m () -> MdocParser m MdocToken
forall a b.
ParsecT [MdocToken] MdocState m a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT [MdocToken] MdocState m ()
-> ParsecT [MdocToken] MdocState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional ParsecT [MdocToken] MdocState m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
eol)
parseBl :: PandocMonad m => MdocParser m Blocks
parseBl :: forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseBl = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Bl"
blk <- MdocParser m Blocks
forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseItemList MdocParser m Blocks -> MdocParser m Blocks -> MdocParser m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MdocParser m Blocks
forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseDefinitionList MdocParser m Blocks -> MdocParser m Blocks -> MdocParser m Blocks
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MdocParser m Blocks
forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseColumnList
emptyMacro "El"
return blk
referenceField :: PandocMonad m => T.Text -> ReferenceField -> MdocParser m ()
referenceField :: forall (m :: * -> *).
PandocMonad m =>
Text -> ReferenceField -> MdocParser m ()
referenceField Text
m ReferenceField
field = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
m
reference <- MdocState -> MdocReference
currentReference (MdocState -> MdocReference)
-> ParsecT [MdocToken] MdocState m MdocState
-> ParsecT [MdocToken] MdocState m MdocReference
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m MdocState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
contents <- stringify <$> litsAndDelimsToInlines
eol
modifyState $ \MdocState
s -> MdocState
s{currentReference = M.insertWith (++) field [contents] reference}
return ()
parsePercentA :: PandocMonad m => MdocParser m ()
parsePercentA :: forall (m :: * -> *). PandocMonad m => MdocParser m ()
parsePercentA = Text -> ReferenceField -> MdocParser m ()
forall (m :: * -> *).
PandocMonad m =>
Text -> ReferenceField -> MdocParser m ()
referenceField Text
"%A" ReferenceField
Author
parsePercentB :: PandocMonad m => MdocParser m ()
parsePercentB :: forall (m :: * -> *). PandocMonad m => MdocParser m ()
parsePercentB = Text -> ReferenceField -> MdocParser m ()
forall (m :: * -> *).
PandocMonad m =>
Text -> ReferenceField -> MdocParser m ()
referenceField Text
"%B" ReferenceField
BookTitle
parsePercentC :: PandocMonad m => MdocParser m ()
parsePercentC :: forall (m :: * -> *). PandocMonad m => MdocParser m ()
parsePercentC = Text -> ReferenceField -> MdocParser m ()
forall (m :: * -> *).
PandocMonad m =>
Text -> ReferenceField -> MdocParser m ()
referenceField Text
"%C" ReferenceField
PubLocation
parsePercentD :: PandocMonad m => MdocParser m ()
parsePercentD :: forall (m :: * -> *). PandocMonad m => MdocParser m ()
parsePercentD = Text -> ReferenceField -> MdocParser m ()
forall (m :: * -> *).
PandocMonad m =>
Text -> ReferenceField -> MdocParser m ()
referenceField Text
"%D" ReferenceField
PubDate
parsePercentI :: PandocMonad m => MdocParser m ()
parsePercentI :: forall (m :: * -> *). PandocMonad m => MdocParser m ()
parsePercentI = Text -> ReferenceField -> MdocParser m ()
forall (m :: * -> *).
PandocMonad m =>
Text -> ReferenceField -> MdocParser m ()
referenceField Text
"%I" ReferenceField
Publisher
parsePercentJ :: PandocMonad m => MdocParser m ()
parsePercentJ :: forall (m :: * -> *). PandocMonad m => MdocParser m ()
parsePercentJ = Text -> ReferenceField -> MdocParser m ()
forall (m :: * -> *).
PandocMonad m =>
Text -> ReferenceField -> MdocParser m ()
referenceField Text
"%J" ReferenceField
Journal
parsePercentN :: PandocMonad m => MdocParser m ()
parsePercentN :: forall (m :: * -> *). PandocMonad m => MdocParser m ()
parsePercentN = Text -> ReferenceField -> MdocParser m ()
forall (m :: * -> *).
PandocMonad m =>
Text -> ReferenceField -> MdocParser m ()
referenceField Text
"%N" ReferenceField
IssueNumber
parsePercentO :: PandocMonad m => MdocParser m ()
parsePercentO :: forall (m :: * -> *). PandocMonad m => MdocParser m ()
parsePercentO = Text -> ReferenceField -> MdocParser m ()
forall (m :: * -> *).
PandocMonad m =>
Text -> ReferenceField -> MdocParser m ()
referenceField Text
"%O" ReferenceField
Optional
parsePercentP :: PandocMonad m => MdocParser m ()
parsePercentP :: forall (m :: * -> *). PandocMonad m => MdocParser m ()
parsePercentP = Text -> ReferenceField -> MdocParser m ()
forall (m :: * -> *).
PandocMonad m =>
Text -> ReferenceField -> MdocParser m ()
referenceField Text
"%P" ReferenceField
Pages
parsePercentQ :: PandocMonad m => MdocParser m ()
parsePercentQ :: forall (m :: * -> *). PandocMonad m => MdocParser m ()
parsePercentQ = Text -> ReferenceField -> MdocParser m ()
forall (m :: * -> *).
PandocMonad m =>
Text -> ReferenceField -> MdocParser m ()
referenceField Text
"%Q" ReferenceField
Institution
parsePercentR :: PandocMonad m => MdocParser m ()
parsePercentR :: forall (m :: * -> *). PandocMonad m => MdocParser m ()
parsePercentR = Text -> ReferenceField -> MdocParser m ()
forall (m :: * -> *).
PandocMonad m =>
Text -> ReferenceField -> MdocParser m ()
referenceField Text
"%R" ReferenceField
TechReportTitle
parsePercentT :: PandocMonad m => MdocParser m ()
parsePercentT :: forall (m :: * -> *). PandocMonad m => MdocParser m ()
parsePercentT = Text -> ReferenceField -> MdocParser m ()
forall (m :: * -> *).
PandocMonad m =>
Text -> ReferenceField -> MdocParser m ()
referenceField Text
"%T" ReferenceField
ArticleTitle
parsePercentU :: PandocMonad m => MdocParser m ()
parsePercentU :: forall (m :: * -> *). PandocMonad m => MdocParser m ()
parsePercentU = Text -> ReferenceField -> MdocParser m ()
forall (m :: * -> *).
PandocMonad m =>
Text -> ReferenceField -> MdocParser m ()
referenceField Text
"%U" ReferenceField
Url
parsePercentV :: PandocMonad m => MdocParser m ()
parsePercentV :: forall (m :: * -> *). PandocMonad m => MdocParser m ()
parsePercentV = Text -> ReferenceField -> MdocParser m ()
forall (m :: * -> *).
PandocMonad m =>
Text -> ReferenceField -> MdocParser m ()
referenceField Text
"%V" ReferenceField
VolumeNumber
parseReferenceField :: PandocMonad m => MdocParser m ()
parseReferenceField :: forall (m :: * -> *). PandocMonad m => MdocParser m ()
parseReferenceField =
[ParsecT [MdocToken] MdocState m ()]
-> ParsecT [MdocToken] MdocState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [
ParsecT [MdocToken] MdocState m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
parsePercentA,
ParsecT [MdocToken] MdocState m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
parsePercentB,
ParsecT [MdocToken] MdocState m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
parsePercentC,
ParsecT [MdocToken] MdocState m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
parsePercentD,
ParsecT [MdocToken] MdocState m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
parsePercentI,
ParsecT [MdocToken] MdocState m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
parsePercentJ,
ParsecT [MdocToken] MdocState m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
parsePercentN,
ParsecT [MdocToken] MdocState m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
parsePercentO,
ParsecT [MdocToken] MdocState m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
parsePercentP,
ParsecT [MdocToken] MdocState m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
parsePercentQ,
ParsecT [MdocToken] MdocState m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
parsePercentR,
ParsecT [MdocToken] MdocState m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
parsePercentT,
ParsecT [MdocToken] MdocState m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
parsePercentU,
ParsecT [MdocToken] MdocState m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
parsePercentV
]
parseRsInline :: PandocMonad m => MdocParser m Inlines
parseRsInline :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseRsInline = do
sec <- MdocState -> MdocSection
currentSection (MdocState -> MdocSection)
-> ParsecT [MdocToken] MdocState m MdocState
-> ParsecT [MdocToken] MdocState m MdocSection
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m MdocState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
guard $ sec /= ShSeeAlso
parseRs
parseRs :: PandocMonad m => MdocParser m Inlines
parseRs :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseRs = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
emptyMacro Text
"Rs"
(MdocState -> MdocState) -> ParsecT [MdocToken] MdocState m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
modifyState ((MdocState -> MdocState) -> ParsecT [MdocToken] MdocState m ())
-> (MdocState -> MdocState) -> ParsecT [MdocToken] MdocState m ()
forall a b. (a -> b) -> a -> b
$ \MdocState
s -> MdocState
s{currentReference = M.empty}
ParsecT [MdocToken] MdocState m ()
-> ParsecT [MdocToken] MdocState m [()]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT [MdocToken] MdocState m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
parseReferenceField
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
emptyMacro Text
"Re"
ref <- MdocState -> MdocReference
currentReference (MdocState -> MdocReference)
-> ParsecT [MdocToken] MdocState m MdocState
-> ParsecT [MdocToken] MdocState m MdocReference
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m MdocState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
return $ B.text $ (M.foldl f mempty ref) <> "."
where join :: [Text] -> Text
join [Text]
v = [Text] -> Text
T.concat (Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
intersperse Text
", " [Text]
v)
f :: Text -> [Text] -> Text
f Text
a [Text]
v | Text -> Bool
T.null Text
a = [Text] -> Text
join [Text]
v
| Bool
otherwise = Text
a Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
", " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> [Text] -> Text
join [Text]
v
skipBlanks :: PandocMonad m => MdocParser m Blocks
skipBlanks :: forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
skipBlanks = ParsecT [MdocToken] MdocState m MdocToken
-> ParsecT [MdocToken] MdocState m [MdocToken]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT [MdocToken] MdocState m MdocToken
forall (m :: * -> *). PandocMonad m => MdocParser m MdocToken
blank ParsecT [MdocToken] MdocState m [MdocToken]
-> ParsecT [MdocToken] MdocState m Blocks
-> ParsecT [MdocToken] MdocState m Blocks
forall a b.
ParsecT [MdocToken] MdocState m a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT [MdocToken] MdocState m Blocks
forall a. Monoid a => a
mempty
parseSmToggle :: PandocMonad m => MdocParser m Inlines
parseSmToggle :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
parseSmToggle = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Sm"
cur <- MdocState -> Bool
spacingMode (MdocState -> Bool)
-> ParsecT [MdocToken] MdocState m MdocState
-> ParsecT [MdocToken] MdocState m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m MdocState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
mode <- optionMaybe (literal "on" $> True <|> literal "off" $> False)
eol
let newMode = Maybe Bool -> Bool -> Bool
update Maybe Bool
mode Bool
cur
modifyState $ \MdocState
s -> MdocState
s{spacingMode = newMode}
return $ if newMode then smOn else smOff
where
update :: Maybe Bool -> Bool -> Bool
update = \case
Maybe Bool
Nothing -> Bool -> Bool
not
Just Bool
x -> Bool -> Bool -> Bool
forall a b. a -> b -> a
const Bool
x
skipUnsupportedMacro :: PandocMonad m => T.Text -> MdocParser m ()
skipUnsupportedMacro :: forall (m :: * -> *). PandocMonad m => Text -> MdocParser m ()
skipUnsupportedMacro Text
nm = do
(Macro _ pos) <- Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
nm
manyTill anyToken eol
logMessage $ SkippedContent ("unsupported macro: " <> nm) pos
skipUnsupportedInlines :: PandocMonad m => MdocParser m Inlines
skipUnsupportedInlines :: forall (m :: * -> *). PandocMonad m => MdocParser m (Many Inline)
skipUnsupportedInlines = [ParsecT [MdocToken] MdocState m ()]
-> ParsecT [MdocToken] MdocState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
[ Text -> ParsecT [MdocToken] MdocState m ()
forall (m :: * -> *). PandocMonad m => Text -> MdocParser m ()
skipUnsupportedMacro Text
"Tg",
Text -> ParsecT [MdocToken] MdocState m ()
forall (m :: * -> *). PandocMonad m => Text -> MdocParser m ()
skipUnsupportedMacro Text
"Bk",
Text -> ParsecT [MdocToken] MdocState m ()
forall (m :: * -> *). PandocMonad m => Text -> MdocParser m ()
skipUnsupportedMacro Text
"Ek"
] ParsecT [MdocToken] MdocState m ()
-> ParsecT [MdocToken] MdocState m (Many Inline)
-> ParsecT [MdocToken] MdocState m (Many Inline)
forall a b.
ParsecT [MdocToken] MdocState m a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT [MdocToken] MdocState m (Many Inline)
forall a. Monoid a => a
mempty
skipUnknownMacro :: PandocMonad m => MdocParser m Blocks
skipUnknownMacro :: forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
skipUnknownMacro = do
pos <- ParsecT [MdocToken] MdocState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
m <- anyMacro
manyTill anyToken eol
logMessage $ SkippedContent ("unsupported macro: " <> toString m) pos
return mempty
parseRegularBlock :: PandocMonad m => MdocParser m Blocks
parseRegularBlock :: forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseRegularBlock =
[ParsecT [MdocToken] MdocState m Blocks]
-> ParsecT [MdocToken] MdocState m Blocks
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
[ ParsecT [MdocToken] MdocState m Blocks
forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseDl
, ParsecT [MdocToken] MdocState m Blocks
forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseD1
, ParsecT [MdocToken] MdocState m Blocks
forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parsePara
, Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
emptyMacro Text
"Pp" MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m Blocks
-> ParsecT [MdocToken] MdocState m Blocks
forall a b.
ParsecT [MdocToken] MdocState m a
-> ParsecT [MdocToken] MdocState m b
-> ParsecT [MdocToken] MdocState m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT [MdocToken] MdocState m Blocks
forall a. Monoid a => a
mempty
, ParsecT [MdocToken] MdocState m Blocks
forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseBd
, ParsecT [MdocToken] MdocState m Blocks
forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseBl
, ParsecT [MdocToken] MdocState m Blocks
forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
skipBlanks
]
parseBlock :: (PandocMonad m) => MdocParser m Blocks
parseBlock :: forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseBlock =
[ParsecT [MdocToken] MdocState m Blocks]
-> ParsecT [MdocToken] MdocState m Blocks
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
[ ParsecT [MdocToken] MdocState m Blocks
forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseHeader
, ParsecT [MdocToken] MdocState m Blocks
forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseNameSection
, ParsecT [MdocToken] MdocState m Blocks
forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseSynopsisSection
, ParsecT [MdocToken] MdocState m Blocks
forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseSeeAlsoSection
, ParsecT [MdocToken] MdocState m Blocks
forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseMiniSynopsis
, ParsecT [MdocToken] MdocState m Blocks
forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseRegularBlock
, ParsecT [MdocToken] MdocState m Blocks
forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
skipUnknownMacro
]