{-# 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 Inlines
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 -> Inlines) -> [MdocToken] -> [Inlines]
forall a b. (a -> b) -> [a] -> [b]
map (Text -> Inlines
B.str (Text -> Inlines) -> (MdocToken -> Text) -> MdocToken -> Inlines
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 Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
argsToInlines
macro "Dt"
(Lit title _) <- lit
(Lit section _) <- lit
arch <- optionMaybe (toString <$> lit)
eol
emptyMacro "Os"
let adjust = Text -> Inlines -> 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 -> Inlines
B.str Text
title)
(Meta -> Meta) -> (Meta -> Meta) -> Meta -> Meta
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines -> 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" Inlines
date
(Meta -> Meta) -> (Meta -> Meta) -> Meta -> Meta
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines -> 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 -> Inlines
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 -> Inlines -> 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" (Inlines -> Meta -> Meta)
-> (Text -> Inlines) -> Text -> Meta -> Meta
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines
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 Inlines
nameNm = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Nm"
nms <- ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m [Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT [MdocToken] MdocState m Inlines
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 Inlines
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 Inlines
-> ParsecT [MdocToken] MdocState m Blocks
synopsisGroup ParsecT [MdocToken] MdocState m Inlines
p = [Inlines] -> Blocks
B.lineBlock ([Inlines] -> Blocks)
-> ParsecT [MdocToken] MdocState m [Inlines]
-> ParsecT [MdocToken] MdocState m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m [Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT [MdocToken] MdocState m Inlines
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 Inlines
-> ParsecT [MdocToken] MdocState m Blocks
forall {m :: * -> *}.
PandocMonad m =>
ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Blocks
synopsisGroup ParsecT [MdocToken] MdocState m Inlines
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 Inlines
-> ParsecT [MdocToken] MdocState m Blocks
forall {m :: * -> *}.
PandocMonad m =>
ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Blocks
synopsisGroup (ParsecT [MdocToken] MdocState m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseCd ParsecT [MdocToken] MdocState m Inlines
-> MdocParser m () -> ParsecT [MdocToken] MdocState m Inlines
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 Inlines
-> ParsecT [MdocToken] MdocState m Blocks
forall {m :: * -> *}.
PandocMonad m =>
ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Blocks
synopsisGroup (ParsecT [MdocToken] MdocState m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseIn ParsecT [MdocToken] MdocState m Inlines
-> MdocParser m () -> ParsecT [MdocToken] MdocState m Inlines
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 Inlines
-> ParsecT [MdocToken] MdocState m Blocks
forall {m :: * -> *}.
PandocMonad m =>
ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Blocks
synopsisGroup (ParsecT [MdocToken] MdocState m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseFd ParsecT [MdocToken] MdocState m Inlines
-> MdocParser m () -> ParsecT [MdocToken] MdocState m Inlines
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 Inlines
-> ParsecT [MdocToken] MdocState m Blocks
forall {m :: * -> *}.
PandocMonad m =>
ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Blocks
synopsisGroup (ParsecT [MdocToken] MdocState m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseVt ParsecT [MdocToken] MdocState m Inlines
-> MdocParser m () -> ParsecT [MdocToken] MdocState m Inlines
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 Inlines
parseInvocation = do
nm <- ParsecT [MdocToken] MdocState m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseNm
optional eol
rest <- many synopsisInline
spacify (nm:rest)
parseSignature :: ParsecT [MdocToken] MdocState m Blocks
parseSignature = do
ft <- ParsecT [MdocToken] MdocState m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseFt ParsecT [MdocToken] MdocState m Inlines
-> MdocParser m () -> ParsecT [MdocToken] MdocState m Inlines
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 Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseFt ParsecT [MdocToken] MdocState m Inlines
-> MdocParser m () -> ParsecT [MdocToken] MdocState m Inlines
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 Inlines
synopsisInline = ParsecT [MdocToken] MdocState m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseSmToggle ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT [MdocToken] MdocState m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseStrs ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (ParsecT [MdocToken] MdocState m [Inlines]
controlLine ParsecT [MdocToken] MdocState m [Inlines]
-> ([Inlines] -> ParsecT [MdocToken] MdocState m Inlines)
-> ParsecT [MdocToken] MdocState m Inlines
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
>>= [Inlines] -> ParsecT [MdocToken] MdocState m Inlines
forall (m :: * -> *).
PandocMonad m =>
[Inlines] -> MdocParser m Inlines
spacify) ParsecT [MdocToken] MdocState m Inlines
-> String -> ParsecT [MdocToken] MdocState m Inlines
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 [Inlines]
controlLine = ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m [Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 (([ParsecT [MdocToken] MdocState m Inlines]
-> ParsecT [MdocToken] MdocState m Inlines
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 Inlines]
forall (m :: * -> *). PandocMonad m => [MdocParser m Inlines]
otherInlineMacros ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT [MdocToken] MdocState m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
litsAndDelimsToInlines) ParsecT [MdocToken] MdocState m Inlines
-> MdocParser m () -> ParsecT [MdocToken] MdocState m Inlines
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
<|> (Inlines -> Blocks
B.para (Inlines -> Blocks)
-> ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseRs)
parseStr :: PandocMonad m => MdocParser m Inlines
parseStr :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
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 Inlines
parseStrs = do
txt <- ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m [Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT [MdocToken] MdocState m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseStr
return $ mconcat $ intersperse B.space txt
parseDelim :: PandocMonad m => DelimSide -> MdocParser m Inlines
parseDelim :: forall (m :: * -> *).
PandocMonad m =>
DelimSide -> MdocParser m Inlines
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 Inlines
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 -> Inlines) -> [MdocToken] -> [Inlines]
forall a b. (a -> b) -> [a] -> [b]
map (Text -> Inlines
B.str (Text -> Inlines) -> (MdocToken -> Text) -> MdocToken -> Inlines
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 Inlines
litsAndDelimsToInlines = do
(o, ls, c) <- MdocParser m [MdocToken]
-> MdocParser m (Inlines, [MdocToken], Inlines)
forall (m :: * -> *) x.
PandocMonad m =>
MdocParser m x -> MdocParser m (Inlines, x, Inlines)
delimitedArgs (MdocParser m [MdocToken]
-> MdocParser m (Inlines, [MdocToken], Inlines))
-> MdocParser m [MdocToken]
-> MdocParser m (Inlines, [MdocToken], Inlines)
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 Inlines
openingDelimiters = do
openDelim <- [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ParsecT [MdocToken] MdocState m [Inlines]
-> ParsecT [MdocToken] MdocState m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m [Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (DelimSide -> ParsecT [MdocToken] MdocState m Inlines
forall (m :: * -> *).
PandocMonad m =>
DelimSide -> MdocParser m Inlines
parseDelim DelimSide
Open)
omids <- pipes
addSpace <- spacingMode <$> getState
let omid | Inlines -> Bool
forall a. Many a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Inlines
omids = Inlines
forall a. Monoid a => a
mempty
| Bool
addSpace = Inlines
omids Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
B.space
| Bool
otherwise = Inlines
omids
return $ openDelim <> omid
pipes :: PandocMonad m => MdocParser m Inlines
pipes :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
pipes = ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m [Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (DelimSide -> ParsecT [MdocToken] MdocState m Inlines
forall (m :: * -> *).
PandocMonad m =>
DelimSide -> MdocParser m Inlines
parseDelim DelimSide
Middle) ParsecT [MdocToken] MdocState m [Inlines]
-> ([Inlines] -> ParsecT [MdocToken] MdocState m Inlines)
-> ParsecT [MdocToken] MdocState m Inlines
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
>>= [Inlines] -> ParsecT [MdocToken] MdocState m Inlines
forall (m :: * -> *).
PandocMonad m =>
[Inlines] -> MdocParser m Inlines
spacify
closingDelimiters :: PandocMonad m => MdocParser m Inlines
closingDelimiters :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
closingDelimiters = do
cmids <- MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
pipes
addSpace <- spacingMode <$> getState
let cmid | Inlines -> Bool
forall a. Many a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Inlines
cmids = Inlines
forall a. Monoid a => a
mempty
| Bool
addSpace = Inlines
B.space Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
cmids
| Bool
otherwise = Inlines
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 (Inlines, x, Inlines)
delimitedArgs MdocParser m x
p = do
openDelim <- MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
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 -> (Inlines -> Inlines) -> MdocParser m Inlines
simpleInline Text
nm Inlines -> Inlines
xform = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
nm
segs <- ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m ()
-> ParsecT [MdocToken] MdocState m [Inlines]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT [MdocToken] MdocState m Inlines
segment ParsecT [MdocToken] MdocState m ()
forall (m :: * -> *). PandocMonad m => MdocParser m ()
inlineContextEnd
spacify segs
where
segment :: ParsecT [MdocToken] MdocState m Inlines
segment = do
(openDelim, inlines, closeDelim) <- ParsecT [MdocToken] MdocState m Inlines
-> MdocParser m (Inlines, Inlines, Inlines)
forall (m :: * -> *) x.
PandocMonad m =>
MdocParser m x -> MdocParser m (Inlines, x, Inlines)
delimitedArgs (ParsecT [MdocToken] MdocState m Inlines
-> MdocParser m (Inlines, Inlines, Inlines))
-> ParsecT [MdocToken] MdocState m Inlines
-> MdocParser m (Inlines, Inlines, Inlines)
forall a b. (a -> b) -> a -> b
$ Inlines
-> ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Inlines
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Inlines
forall a. Monoid a => a
mempty ParsecT [MdocToken] MdocState m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
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 Inlines
codeLikeInline' Text
nm Text
cl = Text -> (Inlines -> Inlines) -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> (Inlines -> Inlines) -> MdocParser m Inlines
simpleInline Text
nm ((Inlines -> Inlines) -> Inlines -> Inlines
eliminateEmpty (Attr -> Text -> Inlines
B.codeWith (Text -> Attr
cls Text
cl) (Text -> Inlines) -> (Inlines -> Text) -> Inlines -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> 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 Inlines
codeLikeInline Text
nm = Text -> Text -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> MdocParser m Inlines
codeLikeInline' Text
nm Text
nm
spanLikeInline :: PandocMonad m => T.Text -> MdocParser m Inlines
spanLikeInline :: forall (m :: * -> *). PandocMonad m => Text -> MdocParser m Inlines
spanLikeInline Text
nm = Text -> (Inlines -> Inlines) -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> (Inlines -> Inlines) -> MdocParser m Inlines
simpleInline Text
nm ((Inlines -> Inlines) -> Inlines -> Inlines
eliminateEmpty (Attr -> Inlines -> Inlines
B.spanWith (Text -> Attr
cls Text
nm)))
lineEnclosure :: PandocMonad m => T.Text -> (Inlines -> Inlines) -> MdocParser m Inlines
lineEnclosure :: forall (m :: * -> *).
PandocMonad m =>
Text -> (Inlines -> Inlines) -> MdocParser m Inlines
lineEnclosure Text
nm Inlines -> Inlines
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 :: Inlines
noSpace = Text -> Text -> Inlines
B.rawInline Text
"mdoc" Text
"Ns"
apMacro :: Inlines
apMacro :: Inlines
apMacro = Text -> Text -> Inlines
B.rawInline Text
"mdoc" Text
"Ap"
smOff :: Inlines
smOff :: Inlines
smOff = Text -> Text -> Inlines
B.rawInline Text
"mdoc" Text
"Sm off"
smOn :: Inlines
smOn :: Inlines
smOn = Text -> Text -> Inlines
B.rawInline Text
"mdoc" Text
"Sm on"
data SpacifyState = SpacifyState
{ SpacifyState -> [Inlines]
accum :: [Inlines],
SpacifyState -> Inlines
prev :: Inlines,
SpacifyState -> Bool
ns :: Bool,
SpacifyState -> Bool
sm :: Bool
}
instance Default SpacifyState where
def :: SpacifyState
def = [Inlines] -> Inlines -> Bool -> Bool -> SpacifyState
SpacifyState [] Inlines
forall a. Monoid a => a
mempty Bool
False Bool
True
foldNoSpaces :: [Inlines] -> [Inlines]
foldNoSpaces :: [Inlines] -> [Inlines]
foldNoSpaces [Inlines]
xs = (SpacifyState -> [Inlines]
finalize (SpacifyState -> [Inlines])
-> ([Inlines] -> SpacifyState) -> [Inlines] -> [Inlines]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SpacifyState -> Inlines -> SpacifyState)
-> SpacifyState -> [Inlines] -> 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 -> Inlines -> SpacifyState
go SpacifyState
forall a. Default a => a
def) [Inlines]
xs
where
go :: SpacifyState -> Inlines -> SpacifyState
go :: SpacifyState -> Inlines -> SpacifyState
go SpacifyState
s Inlines
x
| SpacifyState -> Bool
ns SpacifyState
s Bool -> Bool -> Bool
&& Inlines
x Inlines -> Inlines -> Bool
forall a. Eq a => a -> a -> Bool
== Inlines
noSpace = SpacifyState
s
| Inlines
x Inlines -> Inlines -> Bool
forall a. Eq a => a -> a -> Bool
== Inlines
apMacro = SpacifyState
s{prev = prev s <> "'", ns = True}
| Inlines
x Inlines -> Inlines -> Bool
forall a. Eq a => a -> a -> Bool
== Inlines
noSpace = SpacifyState
s{ns = True}
| Inlines
x Inlines -> Inlines -> Bool
forall a. Eq a => a -> a -> Bool
== Inlines
smOn = SpacifyState
s{sm = True}
| SpacifyState -> Bool
sm SpacifyState
s Bool -> Bool -> Bool
&& Inlines
x Inlines -> Inlines -> Bool
forall a. Eq a => a -> a -> Bool
== Inlines
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}
| Inlines -> Bool
forall a. Many a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (SpacifyState -> Inlines
prev SpacifyState
s) = SpacifyState
s{prev = x}
| Bool
otherwise = SpacifyState
s{accum = accum s <> [prev s], prev = x}
finalize :: SpacifyState -> [Inlines]
finalize SpacifyState
s
| Inlines -> Bool
forall a. Many a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (SpacifyState -> Inlines
prev SpacifyState
s) = SpacifyState -> [Inlines]
accum SpacifyState
s
| Bool
otherwise = SpacifyState -> [Inlines]
accum SpacifyState
s [Inlines] -> [Inlines] -> [Inlines]
forall a. Semigroup a => a -> a -> a
<> [SpacifyState -> Inlines
prev SpacifyState
s]
spacify :: PandocMonad m => [Inlines] -> MdocParser m Inlines
spacify :: forall (m :: * -> *).
PandocMonad m =>
[Inlines] -> MdocParser m Inlines
spacify [Inlines]
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 -> [Inlines] -> Inlines
go Bool
True = [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ([Inlines] -> [Inlines]) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> [Inlines] -> [Inlines]
forall a. a -> [a] -> [a]
intersperse Inlines
B.space ([Inlines] -> [Inlines])
-> ([Inlines] -> [Inlines]) -> [Inlines] -> [Inlines]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> [Inlines]
foldNoSpaces
go Bool
False = [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ([Inlines] -> [Inlines]) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> [Inlines]
foldNoSpaces
multilineEnclosure :: PandocMonad m => T.Text -> T.Text -> (Inlines -> Inlines) -> MdocParser m Inlines
multilineEnclosure :: forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> (Inlines -> Inlines) -> MdocParser m Inlines
multilineEnclosure Text
op Text
cl Inlines -> Inlines
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 Inlines
parseEo = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Eo"
odel <- ParsecT [MdocToken] MdocState m Inlines
del
optional eol
inner <- parseInlines
macro "Ec"
cdel <- del
optional eol
return $ odel <> inner <> cdel
where
del :: ParsecT [MdocToken] MdocState m Inlines
del = Text -> Inlines
B.str (Text -> Inlines) -> (MdocToken -> Text) -> MdocToken -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MdocToken -> Text
toString (MdocToken -> Inlines)
-> MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m Inlines
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 :: (Inlines -> Inlines) -> Inlines -> Inlines
eliminateEmpty Inlines -> Inlines
x Inlines
y = if Inlines -> Bool
forall a. Many a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Inlines
y then Inlines
forall a. Monoid a => a
mempty else Inlines -> Inlines
x Inlines
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 Inlines
parseSy = Text -> (Inlines -> Inlines) -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> (Inlines -> Inlines) -> MdocParser m Inlines
simpleInline Text
"Sy" ((Inlines -> Inlines) -> Inlines -> Inlines
eliminateEmpty Inlines -> Inlines
B.strong)
parseEm :: PandocMonad m => MdocParser m Inlines
parseEm :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseEm = Text -> (Inlines -> Inlines) -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> (Inlines -> Inlines) -> MdocParser m Inlines
simpleInline Text
"Em" ((Inlines -> Inlines) -> Inlines -> Inlines
eliminateEmpty Inlines -> Inlines
B.emph)
parseNo :: PandocMonad m => MdocParser m Inlines
parseNo :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseNo = Text -> (Inlines -> Inlines) -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> (Inlines -> Inlines) -> MdocParser m Inlines
simpleInline Text
"No" ((Inlines -> Inlines) -> Inlines -> Inlines
eliminateEmpty Inlines -> Inlines
forall a. a -> a
id)
parseTn :: PandocMonad m => MdocParser m Inlines
parseTn :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseTn = Text -> (Inlines -> Inlines) -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> (Inlines -> Inlines) -> MdocParser m Inlines
simpleInline Text
"Tn" ((Inlines -> Inlines) -> Inlines -> Inlines
eliminateEmpty Inlines -> Inlines
forall a. a -> a
id)
parseLi :: PandocMonad m => MdocParser m Inlines
parseLi :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseLi = Text -> MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => Text -> MdocParser m Inlines
codeLikeInline Text
"Li"
parseEv :: PandocMonad m => MdocParser m Inlines
parseEv :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseEv = Text -> MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => Text -> MdocParser m Inlines
codeLikeInline Text
"Ev"
parseDv :: PandocMonad m => MdocParser m Inlines
parseDv :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseDv = Text -> MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => Text -> MdocParser m Inlines
codeLikeInline Text
"Dv"
parseAd :: PandocMonad m => MdocParser m Inlines
parseAd :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseAd = Text -> MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => Text -> MdocParser m Inlines
spanLikeInline Text
"Ad"
parseVa :: PandocMonad m => MdocParser m Inlines
parseVa :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseVa = Text -> Text -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> MdocParser m Inlines
codeLikeInline' Text
"Va" Text
"variable"
parseVt :: PandocMonad m => MdocParser m Inlines
parseVt :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseVt = Text -> Text -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> MdocParser m Inlines
codeLikeInline' Text
"Vt" Text
"variable"
parseAn :: PandocMonad m => MdocParser m Inlines
parseAn :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseAn = ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT [MdocToken] MdocState m Inlines
anSplit ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT [MdocToken] MdocState m Inlines
anRegular
where
anSplit :: ParsecT [MdocToken] MdocState m Inlines
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 Inlines
anRegular = do
an <- Text -> ParsecT [MdocToken] MdocState m Inlines
forall (m :: * -> *). PandocMonad m => Text -> MdocParser m Inlines
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 Inlines
parseMs = Text -> MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => Text -> MdocParser m Inlines
spanLikeInline Text
"Ms"
parseSx :: PandocMonad m => MdocParser m Inlines
parseSx :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseSx = Text -> MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => Text -> MdocParser m Inlines
spanLikeInline Text
"Sx"
parseMt :: PandocMonad m => MdocParser m Inlines
parseMt :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseMt = Text -> (Inlines -> Inlines) -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> (Inlines -> Inlines) -> MdocParser m Inlines
simpleInline Text
"Mt" Inlines -> Inlines
mailto
where mailto :: Inlines -> Inlines
mailto Inlines
x | Inlines -> Bool
forall a. Many a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Inlines
x = Text -> Text -> Inlines -> Inlines
B.link (Text
"mailto:~") Text
"" Inlines
"~"
| Bool
otherwise = Text -> Text -> Inlines -> Inlines
B.link (Text
"mailto:" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Inlines -> Text
forall a. Walkable Inline a => a -> Text
stringify Inlines
x) Text
"" Inlines
x
parsePa :: PandocMonad m => MdocParser m Inlines
parsePa :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parsePa = Text -> (Inlines -> Inlines) -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> (Inlines -> Inlines) -> MdocParser m Inlines
simpleInline Text
"Pa" Inlines -> Inlines
p
where p :: Inlines -> Inlines
p Inlines
x | Inlines -> Bool
forall a. Many a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Inlines
x = Attr -> Inlines -> Inlines
B.spanWith (Text -> Attr
cls Text
"Pa") Inlines
"~"
| Bool
otherwise = Attr -> Inlines -> Inlines
B.spanWith (Text -> Attr
cls Text
"Pa") Inlines
x
parseFl :: PandocMonad m => MdocParser m Inlines
parseFl :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseFl = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Fl"
start <- Inlines
-> ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Inlines
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Inlines
forall a. Monoid a => a
mempty (ParsecT [MdocToken] MdocState m Inlines
emptyWithDelim ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT [MdocToken] MdocState m Inlines
flfl ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT [MdocToken] MdocState m Inlines
emptyWithMacro ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT [MdocToken] MdocState m Inlines
emptyEmpty)
segs <- manyTill segment inlineContextEnd
spacify ([start] <> segs)
where
emptyWithDelim :: ParsecT [MdocToken] MdocState m Inlines
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 Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
closingDelimiters
return $ fl "-" <> ds
flfl :: ParsecT [MdocToken] MdocState m Inlines
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 <- Inlines -> [Inline]
forall a. Many a -> [a]
B.toList (Inlines -> [Inline])
-> ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m [Inline]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseFl
let xx = Attr -> Text -> Inlines
B.codeWith (Text -> Attr
cls Text
"Fl") (Text -> Inlines) -> Text -> Inlines
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 Inlines
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 Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseInline
return $ fl "-" <> rest
emptyEmpty :: ParsecT [MdocToken] MdocState m Inlines
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 ()
-> Inlines -> ParsecT [MdocToken] MdocState m Inlines
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Text -> Inlines
fl Text
"-"
segment :: ParsecT [MdocToken] MdocState m Inlines
segment = do
(openDelim, inlines, closeDelim) <- MdocParser m [Text] -> MdocParser m (Inlines, [Text], Inlines)
forall (m :: * -> *) x.
PandocMonad m =>
MdocParser m x -> MdocParser m (Inlines, x, Inlines)
delimitedArgs (MdocParser m [Text] -> MdocParser m (Inlines, [Text], Inlines))
-> MdocParser m [Text] -> MdocParser m (Inlines, [Text], Inlines)
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 -> Inlines
fl = Attr -> Text -> Inlines
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 Inlines
parseAr = Text -> (Inlines -> Inlines) -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> (Inlines -> Inlines) -> MdocParser m Inlines
simpleInline Text
"Ar" Inlines -> Inlines
forall {t :: * -> *} {a}.
(Foldable t, Walkable Inline (t a)) =>
t a -> Inlines
ar
where ar :: t a -> Inlines
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 -> Inlines
B.codeWith (Text -> Attr
cls Text
"variable") Text
"file ..."
| Bool
otherwise = Attr -> Text -> Inlines
B.codeWith (Text -> Attr
cls Text
"variable") (Text -> Inlines) -> Text -> Inlines
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 Inlines
parseCm = Text -> MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => Text -> MdocParser m Inlines
codeLikeInline Text
"Cm"
parseIc :: PandocMonad m => MdocParser m Inlines
parseIc :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseIc = Text -> MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => Text -> MdocParser m Inlines
codeLikeInline Text
"Ic"
parseEr :: PandocMonad m => MdocParser m Inlines
parseEr :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseEr = Text -> MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => Text -> MdocParser m Inlines
codeLikeInline Text
"Er"
parseCd :: PandocMonad m => MdocParser m Inlines
parseCd :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseCd = Text -> MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => Text -> MdocParser m Inlines
codeLikeInline Text
"Cd"
parseQl :: PandocMonad m => MdocParser m Inlines
parseQl :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseQl = Text -> (Inlines -> Inlines) -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> (Inlines -> Inlines) -> MdocParser m Inlines
lineEnclosure Text
"Ql" ((Inlines -> Inlines) -> MdocParser m Inlines)
-> (Inlines -> Inlines) -> MdocParser m Inlines
forall a b. (a -> b) -> a -> b
$ Attr -> Text -> Inlines
B.codeWith (Text -> Attr
cls Text
"Ql") (Text -> Inlines) -> (Inlines -> Text) -> Inlines -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Text
forall a. Walkable Inline a => a -> Text
stringify
parseDq :: PandocMonad m => MdocParser m Inlines
parseDq :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseDq = Text -> (Inlines -> Inlines) -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> (Inlines -> Inlines) -> MdocParser m Inlines
lineEnclosure Text
"Dq" Inlines -> Inlines
B.doubleQuoted
parseDo :: PandocMonad m => MdocParser m Inlines
parseDo :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseDo = Text -> Text -> (Inlines -> Inlines) -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> (Inlines -> Inlines) -> MdocParser m Inlines
multilineEnclosure Text
"Do" Text
"Dc" Inlines -> Inlines
B.doubleQuoted
parseSq :: PandocMonad m => MdocParser m Inlines
parseSq :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseSq = Text -> (Inlines -> Inlines) -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> (Inlines -> Inlines) -> MdocParser m Inlines
lineEnclosure Text
"Sq" Inlines -> Inlines
B.singleQuoted
parseSo :: PandocMonad m => MdocParser m Inlines
parseSo :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseSo = Text -> Text -> (Inlines -> Inlines) -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> (Inlines -> Inlines) -> MdocParser m Inlines
multilineEnclosure Text
"So" Text
"Sc" Inlines -> Inlines
B.singleQuoted
parseQq :: PandocMonad m => MdocParser m Inlines
parseQq :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseQq = Text -> (Inlines -> Inlines) -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> (Inlines -> Inlines) -> MdocParser m Inlines
lineEnclosure Text
"Qq" ((Inlines -> Inlines) -> MdocParser m Inlines)
-> (Inlines -> Inlines) -> MdocParser m Inlines
forall a b. (a -> b) -> a -> b
$ \Inlines
x -> Inlines
"\"" Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
x Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
"\""
parseQo :: PandocMonad m => MdocParser m Inlines
parseQo :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseQo = Text -> Text -> (Inlines -> Inlines) -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> (Inlines -> Inlines) -> MdocParser m Inlines
multilineEnclosure Text
"Qo" Text
"Qc" ((Inlines -> Inlines) -> MdocParser m Inlines)
-> (Inlines -> Inlines) -> MdocParser m Inlines
forall a b. (a -> b) -> a -> b
$ \Inlines
x -> Inlines
"\"" Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
x Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
"\""
parsePq :: PandocMonad m => MdocParser m Inlines
parsePq :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parsePq = Text -> (Inlines -> Inlines) -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> (Inlines -> Inlines) -> MdocParser m Inlines
lineEnclosure Text
"Pq" ((Inlines -> Inlines) -> MdocParser m Inlines)
-> (Inlines -> Inlines) -> MdocParser m Inlines
forall a b. (a -> b) -> a -> b
$ \Inlines
x -> Inlines
"(" Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
x Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
")"
parsePo :: PandocMonad m => MdocParser m Inlines
parsePo :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parsePo = Text -> Text -> (Inlines -> Inlines) -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> (Inlines -> Inlines) -> MdocParser m Inlines
multilineEnclosure Text
"Po" Text
"Pc" ((Inlines -> Inlines) -> MdocParser m Inlines)
-> (Inlines -> Inlines) -> MdocParser m Inlines
forall a b. (a -> b) -> a -> b
$ \Inlines
x -> Inlines
"(" Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
x Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
")"
parseBq :: PandocMonad m => MdocParser m Inlines
parseBq :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseBq = Text -> (Inlines -> Inlines) -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> (Inlines -> Inlines) -> MdocParser m Inlines
lineEnclosure Text
"Bq" ((Inlines -> Inlines) -> MdocParser m Inlines)
-> (Inlines -> Inlines) -> MdocParser m Inlines
forall a b. (a -> b) -> a -> b
$ \Inlines
x -> Inlines
"[" Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
x Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
"]"
parseBo :: PandocMonad m => MdocParser m Inlines
parseBo :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseBo = Text -> Text -> (Inlines -> Inlines) -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> (Inlines -> Inlines) -> MdocParser m Inlines
multilineEnclosure Text
"Bo" Text
"Bc" ((Inlines -> Inlines) -> MdocParser m Inlines)
-> (Inlines -> Inlines) -> MdocParser m Inlines
forall a b. (a -> b) -> a -> b
$ \Inlines
x -> Inlines
"[" Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
x Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
"]"
parseOp :: PandocMonad m => MdocParser m Inlines
parseOp :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseOp = Text -> (Inlines -> Inlines) -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> (Inlines -> Inlines) -> MdocParser m Inlines
lineEnclosure Text
"Op" ((Inlines -> Inlines) -> MdocParser m Inlines)
-> (Inlines -> Inlines) -> MdocParser m Inlines
forall a b. (a -> b) -> a -> b
$ \Inlines
x -> Inlines
"[" Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
x Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
"]"
parseOo :: PandocMonad m => MdocParser m Inlines
parseOo :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseOo = Text -> Text -> (Inlines -> Inlines) -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> (Inlines -> Inlines) -> MdocParser m Inlines
multilineEnclosure Text
"Oo" Text
"Oc" ((Inlines -> Inlines) -> MdocParser m Inlines)
-> (Inlines -> Inlines) -> MdocParser m Inlines
forall a b. (a -> b) -> a -> b
$ \Inlines
x -> Inlines
"[" Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
x Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
"]"
parseBrq :: PandocMonad m => MdocParser m Inlines
parseBrq :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseBrq = Text -> (Inlines -> Inlines) -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> (Inlines -> Inlines) -> MdocParser m Inlines
lineEnclosure Text
"Brq" ((Inlines -> Inlines) -> MdocParser m Inlines)
-> (Inlines -> Inlines) -> MdocParser m Inlines
forall a b. (a -> b) -> a -> b
$ \Inlines
x -> Inlines
"{" Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
x Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
"}"
parseBro :: PandocMonad m => MdocParser m Inlines
parseBro :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseBro = Text -> Text -> (Inlines -> Inlines) -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> (Inlines -> Inlines) -> MdocParser m Inlines
multilineEnclosure Text
"Bro" Text
"Brc" ((Inlines -> Inlines) -> MdocParser m Inlines)
-> (Inlines -> Inlines) -> MdocParser m Inlines
forall a b. (a -> b) -> a -> b
$ \Inlines
x -> Inlines
"{" Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
x Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
"}"
parseAq :: PandocMonad m => MdocParser m Inlines
parseAq :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseAq = Text -> (Inlines -> Inlines) -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> (Inlines -> Inlines) -> MdocParser m Inlines
lineEnclosure Text
"Aq" ((Inlines -> Inlines) -> MdocParser m Inlines)
-> (Inlines -> Inlines) -> MdocParser m Inlines
forall a b. (a -> b) -> a -> b
$ \Inlines
x -> Inlines
"⟨" Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
x Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
"⟩"
parseAo :: PandocMonad m => MdocParser m Inlines
parseAo :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseAo = Text -> Text -> (Inlines -> Inlines) -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> (Inlines -> Inlines) -> MdocParser m Inlines
multilineEnclosure Text
"Ao" Text
"Ac" ((Inlines -> Inlines) -> MdocParser m Inlines)
-> (Inlines -> Inlines) -> MdocParser m Inlines
forall a b. (a -> b) -> a -> b
$ \Inlines
x -> Inlines
"⟨" Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
x Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
"⟩"
parseDl :: PandocMonad m => MdocParser m Blocks
parseDl :: forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parseDl = do
inner <- Text -> (Inlines -> Inlines) -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> (Inlines -> Inlines) -> MdocParser m Inlines
lineEnclosure Text
"Dl" Inlines -> Inlines
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 -> (Inlines -> Inlines) -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> (Inlines -> Inlines) -> MdocParser m Inlines
lineEnclosure Text
"D1" Inlines -> Inlines
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 Inlines
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, Inlines
x) | Inlines -> Bool
forall a. Many a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Inlines
x ->
Inlines
op Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Text -> Inlines
ok Text
nm Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
cl
(Maybe Text
_, Inlines
x) ->
Inlines
op Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> (Text -> Inlines
ok (Text -> Inlines) -> (Inlines -> Text) -> Inlines -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Text
forall a. Walkable Inline a => a -> Text
stringify) Inlines
x Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
cl
where
ok :: Text -> Inlines
ok = Attr -> Text -> Inlines
B.codeWith (Text -> Attr
cls Text
"Nm")
parseXr :: PandocMonad m => MdocParser m Inlines
parseXr :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
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 (Inlines, (Text, Text), Inlines)
forall (m :: * -> *) x.
PandocMonad m =>
MdocParser m x -> MdocParser m (Inlines, x, Inlines)
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 Inlines
parseIn = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"In"
openClose <- MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
closingDelimiters
openOpen <- openingDelimiters
header <- toString <$> lit
close <- closingDelimiters
return $ open openClose openOpen <> B.codeWith (cls "In") ("<" <> header <> ">") <> close
where
open :: Inlines -> Inlines -> Inlines
open Inlines
a Inlines
b
| Inlines -> Bool
forall a. Many a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Inlines
a = Inlines
b
| Inlines -> Bool
forall a. Many a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Inlines
b = Inlines
a
| Bool
otherwise = Inlines
a Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
B.space Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
b
parseFd :: PandocMonad m => MdocParser m Inlines
parseFd :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseFd = Text -> MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => Text -> MdocParser m Inlines
codeLikeInline Text
"Fd"
parseFt :: PandocMonad m => MdocParser m Inlines
parseFt :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseFt = Text -> Text -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> MdocParser m Inlines
codeLikeInline' Text
"Ft" Text
"variable"
formatFunction :: T.Text -> [Inlines] -> Inlines
formatFunction :: Text -> [Inlines] -> Inlines
formatFunction Text
nm [Inlines]
args = Attr -> Text -> Inlines
B.codeWith (Text -> Attr
cls Text
"Fn") Text
nm Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
"(" Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
args' Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
")"
where
args' :: Inlines
args' = [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall a b. (a -> b) -> a -> b
$ Inlines -> [Inlines] -> [Inlines]
forall a. a -> [a] -> [a]
intersperse (Inlines
", ") [Inlines]
args
parseFn :: PandocMonad m => MdocParser m Inlines
parseFn :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
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 (Inlines, (Text, [Text]), Inlines)
forall (m :: * -> *) x.
PandocMonad m =>
MdocParser m x -> MdocParser m (Inlines, x, Inlines)
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 Inlines
parseFa = Text -> Text -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> MdocParser m Inlines
codeLikeInline' Text
"Fa" Text
"variable"
parseFo :: PandocMonad m => MdocParser m Inlines
parseFo :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
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 Inlines
parseLk = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Lk"
openClose <- MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
closingDelimiters
openOpen <- openingDelimiters
url <- toString <$> lit
inner <- many segment >>= spacify
close <- closingDelimiters
let label | Inlines -> Bool
forall a. Many a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Inlines
inner = Text -> Inlines
B.str Text
url
| Bool
otherwise = Inlines
inner
return $ open openClose openOpen <> B.link url "" label <> close
where
open :: Inlines -> Inlines -> Inlines
open Inlines
a Inlines
b
| Inlines -> Bool
forall a. Many a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Inlines
a = Inlines
b
| Inlines -> Bool
forall a. Many a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Inlines
b = Inlines
a
| Bool
otherwise = Inlines
a Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
B.space Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
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 Inlines
segment = do
a <- MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
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 Inlines
parsebr = Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
emptyMacro Text
"br" MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Inlines
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
>> Inlines -> ParsecT [MdocToken] MdocState m Inlines
forall a. a -> ParsecT [MdocToken] MdocState m a
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
B.linebreak
parseNs :: PandocMonad m => MdocParser m Inlines
parseNs :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseNs = Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Ns" MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Inlines
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
>> Inlines -> ParsecT [MdocToken] MdocState m Inlines
forall a. a -> ParsecT [MdocToken] MdocState m a
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
noSpace
parsePf :: PandocMonad m => MdocParser m Inlines
parsePf :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
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 Inlines
parseAp = Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Ap" MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Inlines
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
>> Inlines -> ParsecT [MdocToken] MdocState m Inlines
forall a. a -> ParsecT [MdocToken] MdocState m a
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
apMacro
parseEx :: PandocMonad m => MdocParser m Inlines
parseEx :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
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 -> Inlines
nm = Attr -> Text -> Inlines
B.codeWith (Text -> Attr
cls Text
"Nm")
sing :: Inlines
sing = Inlines
"utility exits"
plur :: Inlines
plur = Inlines
"utilities exit"
utils :: Maybe Text -> [Text] -> Inlines
utils (Just Text
x) [] = Text -> Inlines
nm Text
x Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
B.space Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
sing
utils Maybe Text
_ [Text
x] = Text -> Inlines
nm Text
x Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
B.space Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
sing
utils Maybe Text
_ [Text
x,Text
y] = Text -> Inlines
nm Text
x Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
B.space Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
"and" Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
B.space Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Text -> Inlines
nm Text
y Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
B.space Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
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) -> Inlines
sing
(Maybe Text
_, Just ([Text]
hd, Text
end)) -> [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ((Inlines -> [Inlines] -> [Inlines]
forall a. a -> [a] -> [a]
intersperse (Inlines
", ") ([Inlines] -> [Inlines])
-> ([Text] -> [Inlines]) -> [Text] -> [Inlines]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> Inlines) -> [Text] -> [Inlines]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> Inlines
nm) [Text]
hd) Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
", and " Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Text -> Inlines
nm Text
end Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
B.space Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
plur
(Just Text
p, Maybe ([Text], Text)
Nothing) -> Text -> Inlines
nm Text
p Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
B.space Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
sing
parseRv :: (PandocMonad m) => MdocParser m Inlines
parseRv :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
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 -> Inlines
nm Text
a = Attr -> Text -> Inlines
B.codeWith (Text -> Attr
cls Text
"Fn") Text
a Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
"()"
nothing :: Inlines
nothing = Inlines
"Upon successful completion, the value 0 is returned;"
sing :: Inlines
sing = Inlines
"function returns"
plur :: Inlines
plur = Inlines
"functions return"
success :: Inlines
success = Inlines
"the value 0 if successful;"
errno :: Inlines
errno =
Inlines
"otherwise the value -1 is returned and the global variable"
Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Attr -> Text -> Inlines
B.codeWith (Text -> Attr
cls Text
"variable") Text
"errno"
Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
"is set to indicate the error."
message :: Inlines -> Inlines
message Inlines
conj =
Inlines
"The"
Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
B.space
Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
conj
Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
B.space
Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
success
Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
B.space
Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
errno
go :: Maybe Text -> [Text] -> Inlines
go (Just Text
x) [] = Inlines -> Inlines
message (Text -> Inlines
nm Text
x Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
B.space Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
sing)
go Maybe Text
_ [Text
x] = Inlines -> Inlines
message (Text -> Inlines
nm Text
x Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
B.space Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
sing)
go Maybe Text
_ [Text
x, Text
y] = Inlines -> Inlines
message (Text -> Inlines
nm Text
x Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
B.space Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
"and" Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
B.space Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Text -> Inlines
nm Text
y Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
B.space Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
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) -> Inlines
nothing Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
B.space Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
errno
(Maybe Text
_, Just ([Text]
hd, Text
end)) -> Inlines -> Inlines
message ([Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ((Inlines -> [Inlines] -> [Inlines]
forall a. a -> [a] -> [a]
intersperse (Inlines
", ") ([Inlines] -> [Inlines])
-> ([Text] -> [Inlines]) -> [Text] -> [Inlines]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> Inlines) -> [Text] -> [Inlines]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> Inlines
nm) [Text]
hd) Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
", and " Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Text -> Inlines
nm Text
end Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
B.space Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
plur)
(Just Text
p, Maybe ([Text], Text)
Nothing) -> Inlines -> Inlines
message (Text -> Inlines
nm Text
p Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
B.space Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
sing)
parseSt :: PandocMonad m => MdocParser m Inlines
parseSt :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
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
Inlines -> ParsecT [MdocToken] MdocState m Inlines
forall a. a -> ParsecT [MdocToken] MdocState m a
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
forall a. Monoid a => a
mempty
Just Text
t -> Inlines -> ParsecT [MdocToken] MdocState m Inlines
forall a. a -> ParsecT [MdocToken] MdocState m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> ParsecT [MdocToken] MdocState m Inlines)
-> Inlines -> ParsecT [MdocToken] MdocState m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.text Text
t
parseLb :: PandocMonad m => MdocParser m Inlines
parseLb :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
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 Inlines
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 (Inlines, Text, Inlines)
forall (m :: * -> *) x.
PandocMonad m =>
MdocParser m x -> MdocParser m (Inlines, x, Inlines)
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 -> Inlines
f Text
v | Text -> Bool
T.null Text
v = Inlines
forall a. Monoid a => a
mempty
| Bool
otherwise = Inlines
B.space Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Text -> Inlines
B.str Text
v
parseAt :: PandocMonad m => MdocParser m Inlines
parseAt :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
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 (Inlines, Maybe Text, Inlines)
forall (m :: * -> *) x.
PandocMonad m =>
MdocParser m x -> MdocParser m (Inlines, x, Inlines)
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 Inlines
parseBsx = Text -> Text -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> MdocParser m Inlines
unixVersion Text
"Bsx" Text
"BSD/OS"
parseBx :: PandocMonad m => MdocParser m Inlines
parseBx :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
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 (Inlines, [Text], Inlines)
forall (m :: * -> *) x.
PandocMonad m =>
MdocParser m x -> MdocParser m (Inlines, x, Inlines)
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] -> Inlines
bsd [] = Text -> Inlines
B.str Text
"BSD"
bsd [Text
x] = Text -> Inlines
B.str (Text -> Inlines) -> Text -> Inlines
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 -> Inlines
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 Inlines
parseDx = Text -> Text -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> MdocParser m Inlines
unixVersion Text
"Dx" Text
"DragonFly"
parseFx :: PandocMonad m => MdocParser m Inlines
parseFx :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseFx = Text -> Text -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> MdocParser m Inlines
unixVersion Text
"Fx" Text
"FreeBSD"
parseNx :: PandocMonad m => MdocParser m Inlines
parseNx :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
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 (Inlines, Text, Inlines)
forall (m :: * -> *) x.
PandocMonad m =>
MdocParser m x -> MdocParser m (Inlines, x, Inlines)
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 -> Inlines
f Text
v | Text -> Bool
T.null Text
v = Inlines
forall a. Monoid a => a
mempty
| Bool
otherwise = Inlines
B.space Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Text -> Inlines
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 Inlines
parseOx = Text -> Text -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> Text -> MdocParser m Inlines
unixVersion Text
"Ox" Text
"OpenBSD"
parseUx :: PandocMonad m => MdocParser m Inlines
parseUx :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseUx = Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Ux" MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Inlines
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
>> Inlines -> ParsecT [MdocToken] MdocState m Inlines
forall a. a -> ParsecT [MdocToken] MdocState m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Inlines
B.str Text
"UNIX")
parseInlineMacro :: PandocMonad m => MdocParser m Inlines
parseInlineMacro :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseInlineMacro = [ParsecT [MdocToken] MdocState m Inlines]
-> ParsecT [MdocToken] MdocState m Inlines
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 Inlines]
forall (m :: * -> *). PandocMonad m => [MdocParser m Inlines]
synopsisTopicMacros [ParsecT [MdocToken] MdocState m Inlines]
-> [ParsecT [MdocToken] MdocState m Inlines]
-> [ParsecT [MdocToken] MdocState m Inlines]
forall a. Semigroup a => a -> a -> a
<> [ParsecT [MdocToken] MdocState m Inlines]
forall (m :: * -> *). PandocMonad m => [MdocParser m Inlines]
otherInlineMacros) ParsecT [MdocToken] MdocState m Inlines
-> String -> ParsecT [MdocToken] MdocState m Inlines
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 Inlines]
synopsisTopicMacros =
[MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseNm, MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseCd, MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseFd, MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseFn, MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseFo, MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseIn, MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseVt, MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseFt]
otherInlineMacros :: PandocMonad m => [MdocParser m Inlines]
otherInlineMacros :: forall (m :: * -> *). PandocMonad m => [MdocParser m Inlines]
otherInlineMacros =
[ MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseSy,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseEm,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseLk,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseLi,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseEv,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseDv,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseMt,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parsePa,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseFl,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseCm,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseIc,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseEr,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseAd,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseVa,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseAn,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseMs,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseSx,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseAr,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseFa,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseNo,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseTn,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseXr,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseQl,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseOp,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseSq,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseDq,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseQq,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parsePq,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseBq,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseBrq,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseAq,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseEo,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseSo,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseDo,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseQo,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parsePo,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseBo,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseBro,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseAo,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseOo,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseBf,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseRsInline,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseEx,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseRv,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseSt,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseLb,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseAt,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseBsx,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseBx,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseDx,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseFx,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseNx,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseOx,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseUx,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parsebr,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseAp,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parsePf,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseNs,
MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
skipUnsupportedInlines
]
parseInline :: PandocMonad m => MdocParser m Inlines
parseInline :: forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseInline = MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseStrs MdocParser m Inlines
-> MdocParser m Inlines -> MdocParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> (ParsecT [MdocToken] MdocState m [Inlines]
controlLine ParsecT [MdocToken] MdocState m [Inlines]
-> ([Inlines] -> MdocParser m Inlines) -> MdocParser m Inlines
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
>>= [Inlines] -> MdocParser m Inlines
forall (m :: * -> *).
PandocMonad m =>
[Inlines] -> MdocParser m Inlines
spacify) MdocParser m Inlines -> String -> MdocParser m Inlines
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 [Inlines]
controlLine = MdocParser m Inlines -> ParsecT [MdocToken] MdocState m [Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 ((MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseInlineMacro MdocParser m Inlines
-> MdocParser m Inlines -> MdocParser m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> MdocParser m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
litsAndDelimsToInlines) MdocParser m Inlines
-> ParsecT [MdocToken] MdocState m () -> MdocParser m Inlines
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 Inlines
parseInlines = ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m [Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many1 (ParsecT [MdocToken] MdocState m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseSmToggle ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT [MdocToken] MdocState m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseInline) ParsecT [MdocToken] MdocState m [Inlines]
-> ([Inlines] -> ParsecT [MdocToken] MdocState m Inlines)
-> ParsecT [MdocToken] MdocState m Inlines
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
>>= [Inlines] -> ParsecT [MdocToken] MdocState m Inlines
forall (m :: * -> *).
PandocMonad m =>
[Inlines] -> MdocParser m Inlines
spacify
parsePara :: PandocMonad m => MdocParser m Blocks
parsePara :: forall (m :: * -> *). PandocMonad m => MdocParser m Blocks
parsePara = Inlines -> Blocks
B.para (Inlines -> Blocks) -> (Inlines -> Inlines) -> Inlines -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Inlines
B.trimInlines (Inlines -> Blocks)
-> ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
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 Inlines)
-> ParsecT [MdocToken] MdocState m [Maybe Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (ParsecT [MdocToken] MdocState m (Maybe Inlines)
-> ParsecT [MdocToken] MdocState m [Maybe Inlines])
-> ParsecT [MdocToken] MdocState m (Maybe Inlines)
-> ParsecT [MdocToken] MdocState m [Maybe Inlines]
forall a b. (a -> b) -> a -> b
$ Inlines -> Maybe Inlines
forall a. a -> Maybe a
Just (Inlines -> Maybe Inlines)
-> ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m (Maybe Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m Inlines
parseStrPreserveSpace
ParsecT [MdocToken] MdocState m (Maybe Inlines)
-> ParsecT [MdocToken] MdocState m (Maybe Inlines)
-> ParsecT [MdocToken] MdocState m (Maybe Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Maybe Inlines
forall a. Maybe a
Nothing Maybe Inlines
-> ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m (Maybe Inlines)
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 Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseSmToggle
ParsecT [MdocToken] MdocState m (Maybe Inlines)
-> ParsecT [MdocToken] MdocState m (Maybe Inlines)
-> ParsecT [MdocToken] MdocState m (Maybe Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Inlines -> Maybe Inlines
forall a. a -> Maybe a
Just (Inlines -> Maybe Inlines)
-> ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m (Maybe Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseInline
ParsecT [MdocToken] MdocState m (Maybe Inlines)
-> ParsecT [MdocToken] MdocState m (Maybe Inlines)
-> ParsecT [MdocToken] MdocState m (Maybe Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Inlines -> Maybe Inlines
forall a. a -> Maybe a
Just Inlines
"" Maybe Inlines
-> MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m (Maybe Inlines)
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 Inlines
parseStrPreserveSpace = (Text -> Inlines
B.str (Text -> Inlines) -> (MdocToken -> Text) -> MdocToken -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MdocToken -> Text
toString) (MdocToken -> Inlines)
-> MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m Inlines
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 Inlines
-> ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Inlines
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 Inlines
-> ParsecT [MdocToken] MdocState m Inlines
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 Inlines
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 Inlines
-> 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 Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
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) -> (Inlines -> Text) -> Inlines -> Maybe Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Text
forall a. Walkable Inline a => a -> Text
stringify (Inlines -> Maybe Text)
-> ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m (Maybe Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
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 Inlines
parseBf = do
Text -> MdocParser m MdocToken
forall (m :: * -> *).
PandocMonad m =>
Text -> MdocParser m MdocToken
macro Text
"Bf"
xform <- Inlines -> Inlines
B.strong (Inlines -> Inlines)
-> MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m (Inlines -> Inlines)
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 (Inlines -> Inlines)
-> ParsecT [MdocToken] MdocState m (Inlines -> Inlines)
-> ParsecT [MdocToken] MdocState m (Inlines -> Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Inlines -> Inlines
B.emph (Inlines -> Inlines)
-> MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m (Inlines -> Inlines)
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 (Inlines -> Inlines)
-> ParsecT [MdocToken] MdocState m (Inlines -> Inlines)
-> ParsecT [MdocToken] MdocState m (Inlines -> Inlines)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Inlines -> Inlines
code (Inlines -> Inlines)
-> MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m (Inlines -> Inlines)
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 :: Inlines -> Inlines
code = Text -> Inlines
B.code (Text -> Inlines) -> (Inlines -> Text) -> Inlines -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> 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 Inlines
-> ParsecT
[MdocToken] MdocState m (ParsecT [MdocToken] MdocState m Inlines)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> ParsecT [MdocToken] MdocState m Inlines
parsedHead ParsecT
[MdocToken] MdocState m (ParsecT [MdocToken] MdocState m Inlines)
-> ParsecT
[MdocToken] MdocState m (ParsecT [MdocToken] MdocState m Inlines)
-> ParsecT
[MdocToken] MdocState m (ParsecT [MdocToken] MdocState m Inlines)
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 Inlines
-> ParsecT
[MdocToken] MdocState m (ParsecT [MdocToken] MdocState m Inlines)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> ParsecT [MdocToken] MdocState m Inlines
diagHead
many skipListArgument
eol
items <- many (parseSmToggle *> mempty <|> dlItem headParser)
return $ B.definitionList items
where
parsedHead :: ParsecT [MdocToken] MdocState m Inlines
parsedHead = ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT [MdocToken] MdocState m Inlines
xoListHead ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT [MdocToken] MdocState m Inlines
eolListHead
eolListHead :: ParsecT [MdocToken] MdocState m Inlines
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 Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseInlines
eol
modifyState $ \MdocState
s -> MdocState
s{inLineEnclosure = False}
return inner
diagHead :: ParsecT [MdocToken] MdocState m Inlines
diagHead = ParsecT [MdocToken] MdocState m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
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 Inlines
xoListHead = do
before <- Inlines
-> ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Inlines
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Inlines
forall a. Monoid a => a
mempty ParsecT [MdocToken] MdocState m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
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"
(Inlines -> Blocks) -> [Inlines] -> [Blocks]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Inlines -> Blocks
B.plain ([Inlines] -> [Blocks])
-> ParsecT [MdocToken] MdocState m [Inlines]
-> ParsecT [MdocToken] MdocState m [Blocks]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [MdocToken] MdocState m Inlines
-> MdocParser m MdocToken
-> ParsecT [MdocToken] MdocState m [Inlines]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
sepBy (ParsecT [MdocToken] MdocState m Inlines
forall (m :: * -> *). PandocMonad m => MdocParser m Inlines
parseInlines ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Inlines
-> ParsecT [MdocToken] MdocState m Inlines
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Inlines -> ParsecT [MdocToken] MdocState m Inlines
forall a. a -> ParsecT [MdocToken] MdocState m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Inlines
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 Inlines
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 Inlines
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 Inlines
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 Inlines
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 Inlines
-> ParsecT [MdocToken] MdocState m Inlines
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 Inlines
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
]