    {-# LANGUAGE FlexibleContexts #-}
    {-# LANGUAGE OverloadedStrings #-}
    {-# LANGUAGE MultiParamTypeClasses #-}
    {-# LANGUAGE TypeFamilyDependencies #-}
    module Text.Pandoc.Readers.Roff.Escape
      ( escape,
        escapeArg,
        escIgnore,
        RoffLikeLexer(..),
      )
    where
    import Text.Pandoc.Class.PandocMonad
        ( PandocMonad(..), report, PandocMonad(..), report )
    import Control.Monad
        ( mzero, mplus, mzero, mplus )
    import Data.Char (chr, isAscii, isAlphaNum)
    import qualified Data.Map as M
    import qualified Data.Text as T
    import Text.Pandoc.Logging (LogMessage(..))
    import Text.Pandoc.Parsing
    import Text.Pandoc.Shared (safeRead)
    import qualified Data.Text.Normalize as Normalize
    import Text.Pandoc.RoffChar (characterCodes, combiningAccents)

    -- | Functions and typeclass for escaping special characters in languages
    -- that inherit the Roff syntax.
    --
    -- For various reasons, the mdoc reader doesn't directly reuse the previously
    -- existing roff lexer. The main one is to make it possible to simultaneously
    -- process roff escapes and to tokenize mdoc macros correctly based on the
    -- control line contents. The extracted interface here allows the same `escape`
    -- function to work with lexers that target different token types and support
    -- different subsets of the original roff language.

    type Lexer m x = ParsecT Sources (State x) m

    -- | Lexers for Roff macro
    class (Monoid (Token x)) => RoffLikeLexer x where
      -- | Type family for the lexer state
      type State x = a | a -> x
      -- | Type family for the token type being lexed
      type Token x = a | a -> x
      -- | Turn a `T.Text` into a token of the output
      emit :: T.Text -> Token x
      -- | Attempt to parse a roff predefined string sequence and push its expansion
      -- onto the input stream.
      expandString :: PandocMonad m => Lexer m x ()
      -- | Parse the name of a defined string and return its expansion as a `Token`
      escString :: PandocMonad m => Lexer m x (Token x)
      -- | Parse the escape character
      backslash :: PandocMonad m => Lexer m x ()
      -- | If the given custom macro is defined in this document, emit a
      -- tokenized "1", otherwise emit a tokenized "0", implementing the roff
      -- escape @\A@.
      checkDefined :: PandocMonad m => T.Text -> Lexer m x (Token x)
      -- | Output an appropriate token for the @\E@ escape sequence. In roff, @\E@
      -- is an "escape character intended to not be interpreted in copy mode".
      -- If the lexer being defined doesn't implement copy mode, @\E@ can just be
      -- lexed by 'backslash'
      escE :: PandocMonad m => Lexer m x (Token x)
      -- | Lex the low-level roff font selection escape @\f@.
      escFont :: PandocMonad m => Lexer m x (Token x)

    characterCodeMap :: M.Map T.Text Char
    characterCodeMap :: Map Text Char
    characterCodeMap =
      [(Text, Char)] -> Map Text Char
    forall k a. Ord k => [(k, a)] -> Map k a
    M.fromList ([(Text, Char)] -> Map Text Char)
    -> [(Text, Char)] -> Map Text Char
    forall a b. (a -> b) -> a -> b
    $ ((Char, Text) -> (Text, Char)) -> [(Char, Text)] -> [(Text, Char)]
    forall a b. (a -> b) -> [a] -> [b]
    map (\(Char
    x,Text
    y) -> (Text
    y,Char
    x)) [(Char, Text)]
    characterCodes

    combiningAccentsMap :: M.Map T.Text Char
    combiningAccentsMap :: Map Text Char
    combiningAccentsMap =
      [(Text, Char)] -> Map Text Char
    forall k a. Ord k => [(k, a)] -> Map k a
    M.fromList ([(Text, Char)] -> Map Text Char)
    -> [(Text, Char)] -> Map Text Char
    forall a b. (a -> b) -> a -> b
    $ ((Char, Text) -> (Text, Char)) -> [(Char, Text)] -> [(Text, Char)]
    forall a b. (a -> b) -> [a] -> [b]
    map (\(Char
    x,Text
    y) -> (Text
    y,Char
    x)) [(Char, Text)]
    combiningAccents

    escape ::  (PandocMonad m, RoffLikeLexer x) => Lexer m x (Token x)
    escape :: forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Lexer m x (Token x)
    escape = ParsecT Sources (State x) m (Token x)
    -> ParsecT Sources (State x) m (Token x)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources (State x) m (Token x)
     -> ParsecT Sources (State x) m (Token x))
    -> ParsecT Sources (State x) m (Token x)
    -> ParsecT Sources (State x) m (Token x)
    forall a b. (a -> b) -> a -> b
    $ do
      Lexer m x ()
    forall x (m :: * -> *).
    (RoffLikeLexer x, PandocMonad m) =>
    Lexer m x ()
    forall (m :: * -> *). PandocMonad m => Lexer m x ()
    backslash
      ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Lexer m x (Token x)
    escapeGlyph ParsecT Sources (State x) m (Token x)
    -> ParsecT Sources (State x) m (Token x)
    -> ParsecT Sources (State x) m (Token x)
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Lexer m x (Token x)
    escapeNormal

    escapeGlyph :: (PandocMonad m, RoffLikeLexer x) => Lexer m x (Token x)
    escapeGlyph :: forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Lexer m x (Token x)
    escapeGlyph = do
      c <- ParsecT Sources (State x) m Char
    -> ParsecT Sources (State x) m Char
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m a
    lookAhead ([Char] -> ParsecT Sources (State x) m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    [Char] -> ParsecT s u m Char
    oneOf [Char
    '[',Char
    '('])
      escapeArg >>= resolveGlyph c

    resolveGlyph :: (PandocMonad m, RoffLikeLexer x) => Char -> T.Text -> Lexer m x (Token x)
    resolveGlyph :: forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> Text -> Lexer m x (Token x)
    resolveGlyph Char
    delimChar Text
    glyph = do
      let cs :: Text
    cs = HasCallStack => Text -> Text -> Text -> Text
    Text -> Text -> Text -> Text
    T.replace Text
    "_u" Text
    " u" Text
    glyph -- unicode glyphs separated by _
      (case Text -> [Text]
    T.words Text
    cs of
          []  -> ParsecT Sources (State x) m (Token x)
    forall a. ParsecT Sources (State x) m a
    forall (m :: * -> *) a. MonadPlus m => m a
    mzero
          [Text
    s] -> case Text -> Map Text Char -> Maybe Char
    forall k a. Ord k => k -> Map k a -> Maybe a
    M.lookup Text
    s Map Text Char
    characterCodeMap Maybe Char -> Maybe Char -> Maybe Char
    forall a. Maybe a -> Maybe a -> Maybe a
    forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
    `mplus` Text -> Maybe Char
    readUnicodeChar Text
    s of
                   Maybe Char
    Nothing -> ParsecT Sources (State x) m (Token x)
    forall a. ParsecT Sources (State x) m a
    forall (m :: * -> *) a. MonadPlus m => m a
    mzero
                   Just Char
    c  -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a. a -> ParsecT Sources (State x) m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Token x -> ParsecT Sources (State x) m (Token x))
    -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a b. (a -> b) -> a -> b
    $ Text -> Token x
    forall x. RoffLikeLexer x => Text -> Token x
    emit (Text -> Token x) -> Text -> Token x
    forall a b. (a -> b) -> a -> b
    $ Char -> Text
    T.singleton Char
    c
          (Text
    s:[Text]
    ss) -> do
            basechar <- case Text -> Map Text Char -> Maybe Char
    forall k a. Ord k => k -> Map k a -> Maybe a
    M.lookup Text
    s Map Text Char
    characterCodeMap Maybe Char -> Maybe Char -> Maybe Char
    forall a. Maybe a -> Maybe a -> Maybe a
    forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
    `mplus`
                             Text -> Maybe Char
    readUnicodeChar Text
    s of
                          Maybe Char
    Nothing ->
                            case Text -> [Char]
    T.unpack Text
    s of
                              [Char
    ch] | Char -> Bool
    isAscii Char
    ch Bool -> Bool -> Bool
    && Char -> Bool
    isAlphaNum Char
    ch ->
                                     Char -> ParsecT Sources (State x) m Char
    forall a. a -> ParsecT Sources (State x) m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Char
    ch
                              [Char]
    _ -> ParsecT Sources (State x) m Char
    forall a. ParsecT Sources (State x) m a
    forall (m :: * -> *) a. MonadPlus m => m a
    mzero
                          Just Char
    c  -> Char -> ParsecT Sources (State x) m Char
    forall a. a -> ParsecT Sources (State x) m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Char
    c
            let addAccents [] Text
    xs = Text -> m Text
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Text -> m Text) -> Text -> m Text
    forall a b. (a -> b) -> a -> b
    $ NormalizationMode -> Text -> Text
    Normalize.normalize NormalizationMode
    Normalize.NFC (Text -> Text) -> Text -> Text
    forall a b. (a -> b) -> a -> b
    $
                                            Text -> Text
    T.reverse Text
    xs
                addAccents (Text
    a:[Text]
    as) Text
    xs =
                  case Text -> Map Text Char -> Maybe Char
    forall k a. Ord k => k -> Map k a -> Maybe a
    M.lookup Text
    a Map Text Char
    combiningAccentsMap Maybe Char -> Maybe Char -> Maybe Char
    forall a. Maybe a -> Maybe a -> Maybe a
    forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
    `mplus` Text -> Maybe Char
    readUnicodeChar Text
    a of
                    Just Char
    x  -> [Text] -> Text -> m Text
    addAccents [Text]
    as (Text -> m Text) -> Text -> m Text
    forall a b. (a -> b) -> a -> b
    $ Char -> Text -> Text
    T.cons Char
    x Text
    xs
                    Maybe Char
    Nothing -> m Text
    forall a. m a
    forall (m :: * -> *) a. MonadPlus m => m a
    mzero
            addAccents ss (T.singleton basechar) >>= \Text
    xs -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a. a -> ParsecT Sources (State x) m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Token x -> ParsecT Sources (State x) m (Token x))
    -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a b. (a -> b) -> a -> b
    $ Text -> Token x
    forall x. RoffLikeLexer x => Text -> Token x
    emit Text
    xs)
          ParsecT Sources (State x) m (Token x)
    -> ParsecT Sources (State x) m (Token x)
    -> ParsecT Sources (State x) m (Token x)
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> case Char
    delimChar of
                Char
    '['  -> Text -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Text -> Lexer m x (Token x)
    escUnknown (Text
    "\\[" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    glyph Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    "]")
                Char
    '('  -> Text -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Text -> Lexer m x (Token x)
    escUnknown (Text
    "\\(" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    glyph)
                Char
    '\'' -> Text -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Text -> Lexer m x (Token x)
    escUnknown (Text
    "\\C'" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    glyph Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    "'")
                Char
    _    -> [Char] -> ParsecT Sources (State x) m (Token x)
    forall a. [Char] -> ParsecT Sources (State x) m a
    forall (m :: * -> *) a. MonadFail m => [Char] -> m a
    Prelude.fail [Char]
    "resolveGlyph: unknown glyph delimiter"

    readUnicodeChar :: T.Text -> Maybe Char
    readUnicodeChar :: Text -> Maybe Char
    readUnicodeChar Text
    t = case Text -> Maybe (Char, Text)
    T.uncons Text
    t of
      Just (Char
    'u', Text
    cs) | Text -> Int
    T.length Text
    cs Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    > Int
    3 -> Int -> Char
    chr (Int -> Char) -> Maybe Int -> Maybe Char
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Text -> Maybe Int
    forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
    safeRead (Text
    "0x" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    cs)
      Maybe (Char, Text)
    _ -> Maybe Char
    forall a. Maybe a
    Nothing

    escapeNormal :: (PandocMonad m, RoffLikeLexer x) => Lexer m x (Token x)
    escapeNormal :: forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Lexer m x (Token x)
    escapeNormal = do
      c <- [Char] -> ParsecT Sources (State x) m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    [Char] -> ParsecT s u m Char
    noneOf [Char]
    "{}"
      optional expandString
      let groffSkip = [ParsecT Sources (State x) m Text
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Lexer m x Text
    escapeArg, Int
    -> ParsecT Sources (State x) m Char
    -> ParsecT Sources (State x) m Text
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char, Monad m) =>
    Int -> ParsecT s st m Char -> ParsecT s st m Text
    countChar Int
    1 ((Char -> Bool) -> ParsecT Sources (State x) m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    (Char -> Bool) -> ParsecT s u m Char
    satisfy (Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    /=Char
    '\n'))]
      case c of
        Char
    ' ' -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a. a -> ParsecT Sources (State x) m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Token x -> ParsecT Sources (State x) m (Token x))
    -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a b. (a -> b) -> a -> b
    $ Text -> Token x
    forall x. RoffLikeLexer x => Text -> Token x
    emit Text
    " " -- mandoc_char(7) says this should be a nonbreaking space
        Char
    '"' -> Token x
    forall a. Monoid a => a
    mempty Token x
    -> ParsecT Sources (State x) m ()
    -> ParsecT Sources (State x) m (Token x)
    forall a b.
    a -> ParsecT Sources (State x) m b -> ParsecT Sources (State x) m a
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ ParsecT Sources (State x) m Char -> ParsecT Sources (State x) m ()
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
    skipMany ((Char -> Bool) -> ParsecT Sources (State x) m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    (Char -> Bool) -> ParsecT s u m Char
    satisfy (Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    /=Char
    '\n')) -- line comment
        Char
    '#' -> Token x
    forall a. Monoid a => a
    mempty Token x
    -> ParsecT Sources (State x) m [Char]
    -> ParsecT Sources (State x) m (Token x)
    forall a b.
    a -> ParsecT Sources (State x) m b -> ParsecT Sources (State x) m a
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ ParsecT Sources (State x) m Char
    -> ParsecT Sources (State x) m Char
    -> ParsecT Sources (State x) m [Char]
    forall s (m :: * -> *) t u a end.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
    manyTill ParsecT Sources (State x) m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    anyChar ParsecT Sources (State x) m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    newline
        Char
    '%' -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a. a -> ParsecT Sources (State x) m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Token x
    forall a. Monoid a => a
    mempty  -- optional hyphenation
        Char
    '&' -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a. a -> ParsecT Sources (State x) m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Token x
    forall a. Monoid a => a
    mempty  -- nonprintable zero-width
        Char
    ')' -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a. a -> ParsecT Sources (State x) m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Token x
    forall a. Monoid a => a
    mempty  -- nonprintable zero-width
        Char
    '*' -> ParsecT Sources (State x) m (Token x)
    forall x (m :: * -> *).
    (RoffLikeLexer x, PandocMonad m) =>
    Lexer m x (Token x)
    forall (m :: * -> *). PandocMonad m => Lexer m x (Token x)
    escString
        Char
    ',' -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a. a -> ParsecT Sources (State x) m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Token x
    forall a. Monoid a => a
    mempty  -- to fix spacing after roman
        Char
    '-' -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a. a -> ParsecT Sources (State x) m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Token x -> ParsecT Sources (State x) m (Token x))
    -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a b. (a -> b) -> a -> b
    $ Text -> Token x
    forall x. RoffLikeLexer x => Text -> Token x
    emit Text
    "-"
        Char
    '.' -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a. a -> ParsecT Sources (State x) m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Token x -> ParsecT Sources (State x) m (Token x))
    -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a b. (a -> b) -> a -> b
    $ Text -> Token x
    forall x. RoffLikeLexer x => Text -> Token x
    emit Text
    "."
        Char
    '/' -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a. a -> ParsecT Sources (State x) m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Token x
    forall a. Monoid a => a
    mempty  -- to fix spacing before roman
        Char
    '0' -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a. a -> ParsecT Sources (State x) m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Token x -> ParsecT Sources (State x) m (Token x))
    -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a b. (a -> b) -> a -> b
    $ Text -> Token x
    forall x. RoffLikeLexer x => Text -> Token x
    emit Text
    "\x2007" -- digit-width space
        Char
    ':' -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a. a -> ParsecT Sources (State x) m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Token x
    forall a. Monoid a => a
    mempty  -- zero-width break
        Char
    'A' -> ParsecT Sources (State x) m Text
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Lexer m x Text
    quoteArg ParsecT Sources (State x) m Text
    -> (Text -> ParsecT Sources (State x) m (Token x))
    -> ParsecT Sources (State x) m (Token x)
    forall a b.
    ParsecT Sources (State x) m a
    -> (a -> ParsecT Sources (State x) m b)
    -> ParsecT Sources (State x) m b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= Text -> ParsecT Sources (State x) m (Token x)
    forall x (m :: * -> *).
    (RoffLikeLexer x, PandocMonad m) =>
    Text -> Lexer m x (Token x)
    forall (m :: * -> *). PandocMonad m => Text -> Lexer m x (Token x)
    checkDefined
        Char
    'B' -> Char
    -> [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    'B' [ParsecT Sources (State x) m Text
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Lexer m x Text
    quoteArg]
        Char
    'C' -> ParsecT Sources (State x) m Text
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Lexer m x Text
    quoteArg ParsecT Sources (State x) m Text
    -> (Text -> ParsecT Sources (State x) m (Token x))
    -> ParsecT Sources (State x) m (Token x)
    forall a b.
    ParsecT Sources (State x) m a
    -> (a -> ParsecT Sources (State x) m b)
    -> ParsecT Sources (State x) m b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= Char -> Text -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> Text -> Lexer m x (Token x)
    resolveGlyph Char
    '\''
        Char
    'D' -> Char
    -> [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    'D' [ParsecT Sources (State x) m Text
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Lexer m x Text
    quoteArg]
        Char
    'E' -> ParsecT Sources (State x) m (Token x)
    forall x (m :: * -> *).
    (RoffLikeLexer x, PandocMonad m) =>
    Lexer m x (Token x)
    forall (m :: * -> *). PandocMonad m => Lexer m x (Token x)
    escE
        Char
    'F' -> Char
    -> [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    'F' [ParsecT Sources (State x) m Text]
    groffSkip
        Char
    'H' -> Char
    -> [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    'H' [ParsecT Sources (State x) m Text
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Lexer m x Text
    quoteArg]
        Char
    'L' -> Char
    -> [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    'L' [ParsecT Sources (State x) m Text
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Lexer m x Text
    quoteArg]
        Char
    'M' -> Char
    -> [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    'M' [ParsecT Sources (State x) m Text]
    groffSkip
        Char
    'N' -> Char
    -> [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    'N' [ParsecT Sources (State x) m Text
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Lexer m x Text
    quoteArg]
        Char
    'O' -> Char
    -> [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    'O' [Int
    -> ParsecT Sources (State x) m Char
    -> ParsecT Sources (State x) m Text
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char, Monad m) =>
    Int -> ParsecT s st m Char -> ParsecT s st m Text
    countChar Int
    1 ([Char] -> ParsecT Sources (State x) m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    [Char] -> ParsecT s u m Char
    oneOf [Char
    '0',Char
    '1'])]
        Char
    'R' -> Char
    -> [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    'R' [ParsecT Sources (State x) m Text
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Lexer m x Text
    quoteArg]
        Char
    'S' -> Char
    -> [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    'S' [ParsecT Sources (State x) m Text
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Lexer m x Text
    quoteArg]
        Char
    'V' -> Char
    -> [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    'V' [ParsecT Sources (State x) m Text]
    groffSkip
        Char
    'X' -> Char
    -> [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    'X' [ParsecT Sources (State x) m Text
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Lexer m x Text
    quoteArg]
        Char
    'Y' -> Char
    -> [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    'Y' [ParsecT Sources (State x) m Text]
    groffSkip
        Char
    'Z' -> Char
    -> [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    'Z' [ParsecT Sources (State x) m Text
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Lexer m x Text
    quoteArg]
        Char
    '\'' -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a. a -> ParsecT Sources (State x) m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Token x -> ParsecT Sources (State x) m (Token x))
    -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a b. (a -> b) -> a -> b
    $ Text -> Token x
    forall x. RoffLikeLexer x => Text -> Token x
    emit Text
    "'"
        Char
    '\n' -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a. a -> ParsecT Sources (State x) m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Token x
    forall a. Monoid a => a
    mempty  -- line continuation
        Char
    '^' -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a. a -> ParsecT Sources (State x) m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Token x -> ParsecT Sources (State x) m (Token x))
    -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a b. (a -> b) -> a -> b
    $ Text -> Token x
    forall x. RoffLikeLexer x => Text -> Token x
    emit Text
    "\x200A" -- 1/12 em space
        Char
    '_' -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a. a -> ParsecT Sources (State x) m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Token x -> ParsecT Sources (State x) m (Token x))
    -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a b. (a -> b) -> a -> b
    $ Text -> Token x
    forall x. RoffLikeLexer x => Text -> Token x
    emit Text
    "_"
        Char
    '`' -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a. a -> ParsecT Sources (State x) m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Token x -> ParsecT Sources (State x) m (Token x))
    -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a b. (a -> b) -> a -> b
    $ Text -> Token x
    forall x. RoffLikeLexer x => Text -> Token x
    emit Text
    "`"
        Char
    'a' -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a. a -> ParsecT Sources (State x) m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Token x
    forall a. Monoid a => a
    mempty  -- "non-interpreted leader character"
        Char
    'b' -> Char
    -> [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    'b' [ParsecT Sources (State x) m Text
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Lexer m x Text
    quoteArg]
        Char
    'c' -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a. a -> ParsecT Sources (State x) m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Token x
    forall a. Monoid a => a
    mempty  -- interrupt text processing
        Char
    'd' -> Char
    -> [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    'd' [] -- forward down 1/2em
        Char
    'e' -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a. a -> ParsecT Sources (State x) m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Token x -> ParsecT Sources (State x) m (Token x))
    -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a b. (a -> b) -> a -> b
    $ Text -> Token x
    forall x. RoffLikeLexer x => Text -> Token x
    emit Text
    "\\"
        Char
    'f' -> ParsecT Sources (State x) m (Token x)
    forall x (m :: * -> *).
    (RoffLikeLexer x, PandocMonad m) =>
    Lexer m x (Token x)
    forall (m :: * -> *). PandocMonad m => Lexer m x (Token x)
    escFont
        Char
    'g' -> Char
    -> [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    'g' [ParsecT Sources (State x) m Text]
    groffSkip
        Char
    'h' -> Char
    -> [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    'h' [ParsecT Sources (State x) m Text
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Lexer m x Text
    quoteArg]
        Char
    'k' -> Char
    -> [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    'k' [ParsecT Sources (State x) m Text]
    groffSkip
        Char
    'l' -> Char
    -> [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    'l' [ParsecT Sources (State x) m Text
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Lexer m x Text
    quoteArg]
        Char
    'm' -> Char
    -> [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    'm' [ParsecT Sources (State x) m Text]
    groffSkip
        Char
    'n' -> Char
    -> [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    'm' [ParsecT Sources (State x) m Text]
    groffSkip
        Char
    'o' -> Char
    -> [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    'o' [ParsecT Sources (State x) m Text
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Lexer m x Text
    quoteArg]
        Char
    'p' -> Char
    -> [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    'p' []
        Char
    'r' -> Char
    -> [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    'r' []
        Char
    's' -> Char
    -> [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    's' [ParsecT Sources (State x) m Text
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Lexer m x Text
    escapeArg, ParsecT Sources (State x) m Text
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Lexer m x Text
    signedNumber]
        Char
    't' -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a. a -> ParsecT Sources (State x) m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Token x -> ParsecT Sources (State x) m (Token x))
    -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a b. (a -> b) -> a -> b
    $ Text -> Token x
    forall x. RoffLikeLexer x => Text -> Token x
    emit Text
    "\t"
        Char
    'u' -> Char
    -> [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    'u' []
        Char
    'v' -> Char
    -> [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    'v' [ParsecT Sources (State x) m Text
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Lexer m x Text
    quoteArg]
        Char
    'w' -> Char
    -> [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    'w' [ParsecT Sources (State x) m Text
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Lexer m x Text
    quoteArg]
        Char
    'x' -> Char
    -> [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    'x' [ParsecT Sources (State x) m Text
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Lexer m x Text
    quoteArg]
        Char
    'z' -> Char
    -> [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m (Token x)
    forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    'z' [Int
    -> ParsecT Sources (State x) m Char
    -> ParsecT Sources (State x) m Text
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char, Monad m) =>
    Int -> ParsecT s st m Char -> ParsecT s st m Text
    countChar Int
    1 ParsecT Sources (State x) m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    ParsecT s u m Char
    anyChar]
        Char
    '|' -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a. a -> ParsecT Sources (State x) m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Token x -> ParsecT Sources (State x) m (Token x))
    -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a b. (a -> b) -> a -> b
    $ Text -> Token x
    forall x. RoffLikeLexer x => Text -> Token x
    emit Text
    "\x2006" --1/6 em space
        Char
    '~' -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a. a -> ParsecT Sources (State x) m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Token x -> ParsecT Sources (State x) m (Token x))
    -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a b. (a -> b) -> a -> b
    $ Text -> Token x
    forall x. RoffLikeLexer x => Text -> Token x
    emit Text
    "\160" -- nonbreaking space
        Char
    '\\' -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a. a -> ParsecT Sources (State x) m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Token x -> ParsecT Sources (State x) m (Token x))
    -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a b. (a -> b) -> a -> b
    $ Text -> Token x
    forall x. RoffLikeLexer x => Text -> Token x
    emit Text
    "\\"
        Char
    _   -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a. a -> ParsecT Sources (State x) m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Token x -> ParsecT Sources (State x) m (Token x))
    -> Token x -> ParsecT Sources (State x) m (Token x)
    forall a b. (a -> b) -> a -> b
    $ Text -> Token x
    forall x. RoffLikeLexer x => Text -> Token x
    emit (Text -> Token x) -> Text -> Token x
    forall a b. (a -> b) -> a -> b
    $ Char -> Text
    T.singleton Char
    c
        -- man 7 groff: "If  a  backslash  is followed by a character that
        -- does not constitute a defined escape sequence, the backslash
        -- is  silently  ignored  and  the character maps to itself."

    escIgnore :: (PandocMonad m, RoffLikeLexer x)
              => Char
              -> [Lexer m x T.Text]
              -> Lexer m x (Token x)
    escIgnore :: forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Char -> [Lexer m x Text] -> Lexer m x (Token x)
    escIgnore Char
    c [Lexer m x Text]
    argparsers = do
      pos <- ParsecT Sources (State x) m SourcePos
    forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
    getPosition
      arg <- snd <$> withRaw (choice argparsers) <|> return ""
      report $ SkippedContent ("\\" <> T.cons c arg) pos
      return mempty

    escUnknown :: (PandocMonad m, RoffLikeLexer x) => T.Text -> Lexer m x (Token x)
    escUnknown :: forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Text -> Lexer m x (Token x)
    escUnknown Text
    s = do
      pos <- ParsecT Sources (State x) m SourcePos
    forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
    getPosition
      report $ SkippedContent s pos
      return $ emit "\xFFFD"

    signedNumber :: (PandocMonad m, RoffLikeLexer x) => Lexer m x T.Text
    signedNumber :: forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Lexer m x Text
    signedNumber = ParsecT Sources (State x) m Text
    -> ParsecT Sources (State x) m Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Sources (State x) m Text
     -> ParsecT Sources (State x) m Text)
    -> ParsecT Sources (State x) m Text
    -> ParsecT Sources (State x) m Text
    forall a b. (a -> b) -> a -> b
    $ do
      sign <- Text
    -> ParsecT Sources (State x) m Text
    -> ParsecT Sources (State x) 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
    "" (Text
    "-" Text
    -> ParsecT Sources (State x) m Char
    -> ParsecT Sources (State x) m Text
    forall a b.
    a -> ParsecT Sources (State x) m b -> ParsecT Sources (State x) m a
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ Char -> ParsecT Sources (State x) m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    '-' ParsecT Sources (State x) m Text
    -> ParsecT Sources (State x) m Text
    -> ParsecT Sources (State x) m Text
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> Text
    "" Text
    -> ParsecT Sources (State x) m Char
    -> ParsecT Sources (State x) m Text
    forall a b.
    a -> ParsecT Sources (State x) m b -> ParsecT Sources (State x) m a
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ Char -> ParsecT Sources (State x) m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    '+')
      ds <- many1Char digit
      return (sign <> ds)

    -- Parses: [..] or (..
    escapeArg :: (PandocMonad m, RoffLikeLexer x) => Lexer m x T.Text
    escapeArg :: forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Lexer m x Text
    escapeArg = [ParsecT Sources (State x) m Text]
    -> ParsecT Sources (State x) m Text
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    [ParsecT s u m a] -> ParsecT s u m a
    choice
        [ Char -> ParsecT Sources (State x) m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    '[' ParsecT Sources (State x) m Char
    -> ParsecT Sources (State x) m () -> ParsecT Sources (State x) m ()
    forall a b.
    ParsecT Sources (State x) m a
    -> ParsecT Sources (State x) m b -> ParsecT Sources (State x) m b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> ParsecT Sources (State x) m () -> ParsecT Sources (State x) m ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m ()
    optional ParsecT Sources (State x) m ()
    forall x (m :: * -> *).
    (RoffLikeLexer x, PandocMonad m) =>
    Lexer m x ()
    forall (m :: * -> *). PandocMonad m => Lexer m x ()
    expandString ParsecT Sources (State x) m ()
    -> ParsecT Sources (State x) m Text
    -> ParsecT Sources (State x) m Text
    forall a b.
    ParsecT Sources (State x) m a
    -> ParsecT Sources (State x) m b -> ParsecT Sources (State x) m b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *>
                      ParsecT Sources (State x) m Char
    -> ParsecT Sources (State x) m Char
    -> ParsecT Sources (State x) m Text
    forall s (m :: * -> *) t st a.
    Stream s m t =>
    ParsecT s st m Char -> ParsecT s st m a -> ParsecT s st m Text
    manyTillChar ([Char] -> ParsecT Sources (State x) m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    [Char] -> ParsecT s u m Char
    noneOf [Char
    '\n',Char
    ']']) (Char -> ParsecT Sources (State x) m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    ']')
        , Char -> ParsecT Sources (State x) m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    '(' ParsecT Sources (State x) m Char
    -> ParsecT Sources (State x) m () -> ParsecT Sources (State x) m ()
    forall a b.
    ParsecT Sources (State x) m a
    -> ParsecT Sources (State x) m b -> ParsecT Sources (State x) m b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> ParsecT Sources (State x) m () -> ParsecT Sources (State x) m ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m ()
    optional ParsecT Sources (State x) m ()
    forall x (m :: * -> *).
    (RoffLikeLexer x, PandocMonad m) =>
    Lexer m x ()
    forall (m :: * -> *). PandocMonad m => Lexer m x ()
    expandString ParsecT Sources (State x) m ()
    -> ParsecT Sources (State x) m Text
    -> ParsecT Sources (State x) m Text
    forall a b.
    ParsecT Sources (State x) m a
    -> ParsecT Sources (State x) m b -> ParsecT Sources (State x) m b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *>
                      Int
    -> ParsecT Sources (State x) m Char
    -> ParsecT Sources (State x) m Text
    forall s (m :: * -> *) st.
    (Stream s m Char, UpdateSourcePos s Char, Monad m) =>
    Int -> ParsecT s st m Char -> ParsecT s st m Text
    countChar Int
    2 ((Char -> Bool) -> ParsecT Sources (State x) m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    (Char -> Bool) -> ParsecT s u m Char
    satisfy (Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    /=Char
    '\n'))
        ]

    -- Parses: '..'
    quoteArg :: (PandocMonad m, RoffLikeLexer x) => Lexer m x T.Text
    quoteArg :: forall (m :: * -> *) x.
    (PandocMonad m, RoffLikeLexer x) =>
    Lexer m x Text
    quoteArg = Char -> ParsecT Sources (State x) m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    '\'' ParsecT Sources (State x) m Char
    -> ParsecT Sources (State x) m Text
    -> ParsecT Sources (State x) m Text
    forall a b.
    ParsecT Sources (State x) m a
    -> ParsecT Sources (State x) m b -> ParsecT Sources (State x) m b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> ParsecT Sources (State x) m Char
    -> ParsecT Sources (State x) m Char
    -> ParsecT Sources (State x) m Text
    forall s (m :: * -> *) t st a.
    Stream s m t =>
    ParsecT s st m Char -> ParsecT s st m a -> ParsecT s st m Text
    manyTillChar ([Char] -> ParsecT Sources (State x) m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    [Char] -> ParsecT s u m Char
    noneOf [Char
    '\n',Char
    '\'']) (Char -> ParsecT Sources (State x) m Char
    forall (m :: * -> *) s u.
    (Monad m, Stream s m Char, UpdateSourcePos s Char) =>
    Char -> ParsecT s u m Char
    char Char
    '\'')