    {-# LANGUAGE FlexibleContexts    #-}
    {-# LANGUAGE OverloadedStrings   #-}
    {-# LANGUAGE ScopedTypeVariables #-}
    {-# LANGUAGE ViewPatterns        #-}
    {- |
       Module      : Text.Pandoc.Readers.RST
       Copyright   : Copyright (C) 2006-2020 John MacFarlane
       License     : GNU GPL, version 2 or above

       Maintainer  : John MacFarlane <jgm@berkeley.edu>
       Stability   : alpha
       Portability : portable

    Conversion from reStructuredText to 'Pandoc' document.
    -}
    module Text.Pandoc.Readers.RST ( readRST ) where
    import Control.Arrow (second)
    import Control.Monad (forM_, guard, liftM, mplus, mzero, when)
    import Control.Monad.Except (throwError)
    import Control.Monad.Identity (Identity (..))
    import Data.Char (isHexDigit, isSpace, toUpper, isAlphaNum)
    import Data.List (deleteFirstsBy, elemIndex, nub, sort, transpose)
    import qualified Data.Map as M
    import Data.Maybe (fromMaybe, maybeToList)
    import Data.Sequence (ViewR (..), viewr)
    import Data.Text (Text)
    import qualified Data.Text as T
    import Text.Pandoc.Builder (Blocks, Inlines, fromList, setMeta, trimInlines)
    import qualified Text.Pandoc.Builder as B
    import Text.Pandoc.Class.PandocMonad (PandocMonad, fetchItem, readFileFromDirs)
    import Text.Pandoc.CSV (CSVOptions (..), defaultCSVOptions, parseCSV)
    import Text.Pandoc.Definition
    import Text.Pandoc.Error
    import Text.Pandoc.ImageSize (lengthToDim, scaleDimension)
    import Text.Pandoc.Logging
    import Text.Pandoc.Options
    import Text.Pandoc.Parsing
    import Text.Pandoc.Shared
    import qualified Text.Pandoc.UTF8 as UTF8
    import Text.Printf (printf)

    -- TODO:
    -- [ ] .. parsed-literal

    -- | Parse reStructuredText string and return Pandoc document.
    readRST :: PandocMonad m
            => ReaderOptions -- ^ Reader options
            -> Text          -- ^ Text to parse (assuming @'\n'@ line endings)
            -> m Pandoc
    readRST :: ReaderOptions -> Text -> m Pandoc
    readRST opts :: ReaderOptions
    opts s :: Text
    s = do
      Either PandocError Pandoc
    parsed <- ParserT Text ParserState m Pandoc
    -> ParserState -> Text -> m (Either PandocError Pandoc)
    forall s (m :: * -> *) st a.
    (Stream s m Char, ToText s) =>
    ParserT s st m a -> st -> s -> m (Either PandocError a)
    readWithM ParserT Text ParserState m Pandoc
    forall (m :: * -> *). PandocMonad m => RSTParser m Pandoc
    parseRST ParserState
    forall a. Default a => a
    def{ stateOptions :: ReaderOptions
    stateOptions = ReaderOptions
    opts }
                   (Text -> Text
    crFilter Text
    s Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> "\n\n")
      case Either PandocError Pandoc
    parsed of
        Right result :: Pandoc
    result -> Pandoc -> m Pandoc
    forall (m :: * -> *) a. Monad m => a -> m a
    return Pandoc
    result
        Left e :: PandocError
    e       -> PandocError -> m Pandoc
    forall e (m :: * -> *) a. MonadError e m => e -> m a
    throwError PandocError
    e

    type RSTParser m = ParserT Text ParserState m

    --
    -- Constants and data structure definitions
    ---

    bulletListMarkers :: [Char]
    bulletListMarkers :: [Char]
    bulletListMarkers = "*+-•‣⁃"

    underlineChars :: [Char]
    underlineChars :: [Char]
    underlineChars = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"

    -- treat these as potentially non-text when parsing inline:
    specialChars :: [Char]
    specialChars :: [Char]
    specialChars = "\\`|*_<>$:/[]{}()-.\"'\8216\8217\8220\8221"

    --
    -- parsing documents
    --

    isHeader :: Int -> Block -> Bool
    isHeader :: Int -> Block -> Bool
    isHeader n :: Int
    n (Header x :: Int
    x _ _) = Int
    x Int -> Int -> Bool
    forall a. Eq a => a -> a -> Bool
    == Int
    n
    isHeader _ _              = Bool
    False

    -- | Promote all headers in a list of blocks.  (Part of
    -- title transformation for RST.)
    promoteHeaders :: Int -> [Block] -> [Block]
    promoteHeaders :: Int -> [Block] -> [Block]
    promoteHeaders num :: Int
    num (Header level :: Int
    level attr :: Attr
    attr text :: [Inline]
    text:rest :: [Block]
    rest) =
        Int -> Attr -> [Inline] -> Block
    Header (Int
    level Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    num) Attr
    attr [Inline]
    textBlock -> [Block] -> [Block]
    forall a. a -> [a] -> [a]
    :Int -> [Block] -> [Block]
    promoteHeaders Int
    num [Block]
    rest
    promoteHeaders num :: Int
    num (other :: Block
    other:rest :: [Block]
    rest) = Block
    otherBlock -> [Block] -> [Block]
    forall a. a -> [a] -> [a]
    :Int -> [Block] -> [Block]
    promoteHeaders Int
    num [Block]
    rest
    promoteHeaders _   [] = []

    -- | If list of blocks starts with a header (or a header and subheader)
    -- of level that are not found elsewhere, return it as a title and
    -- promote all the other headers.  Also process a definition list right
    -- after the title block as metadata.
    titleTransform :: ([Block], Meta)  -- ^ list of blocks, metadata
                   -> ([Block], Meta)  -- ^ modified list of blocks, metadata
    titleTransform :: ([Block], Meta) -> ([Block], Meta)
    titleTransform (bs :: [Block]
    bs, meta :: Meta
    meta) =
      let (bs' :: [Block]
    bs', meta' :: Meta
    meta') =
           case [Block]
    bs of
              (Header 1 _ head1 :: [Inline]
    head1:Header 2 _ head2 :: [Inline]
    head2:rest :: [Block]
    rest)
               | Bool -> Bool
    not ((Block -> Bool) -> [Block] -> Bool
    forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
    any (Int -> Block -> Bool
    isHeader 1) [Block]
    rest Bool -> Bool -> Bool
    || (Block -> Bool) -> [Block] -> Bool
    forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
    any (Int -> Block -> Bool
    isHeader 2) [Block]
    rest) -> -- tit/sub
                (Int -> [Block] -> [Block]
    promoteHeaders 2 [Block]
    rest, Text -> Many Inline -> Meta -> Meta
    forall a b. (HasMeta a, ToMetaValue b) => Text -> b -> a -> a
    setMeta "title" ([Inline] -> Many Inline
    forall a. [a] -> Many a
    fromList [Inline]
    head1) (Meta -> Meta) -> Meta -> Meta
    forall a b. (a -> b) -> a -> b
    $
                  Text -> Many Inline -> Meta -> Meta
    forall a b. (HasMeta a, ToMetaValue b) => Text -> b -> a -> a
    setMeta "subtitle" ([Inline] -> Many Inline
    forall a. [a] -> Many a
    fromList [Inline]
    head2) Meta
    meta)
              (Header 1 _ head1 :: [Inline]
    head1:rest :: [Block]
    rest)
               | Bool -> Bool
    not ((Block -> Bool) -> [Block] -> Bool
    forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
    any (Int -> Block -> Bool
    isHeader 1) [Block]
    rest) -> -- title only
                (Int -> [Block] -> [Block]
    promoteHeaders 1 [Block]
    rest,
                    Text -> Many Inline -> Meta -> Meta
    forall a b. (HasMeta a, ToMetaValue b) => Text -> b -> a -> a
    setMeta "title" ([Inline] -> Many Inline
    forall a. [a] -> Many a
    fromList [Inline]
    head1) Meta
    meta)
              _ -> ([Block]
    bs, Meta
    meta)
      in   case [Block]
    bs' of
              (DefinitionList ds :: [([Inline], [[Block]])]
    ds : rest :: [Block]
    rest) ->
                ([Block]
    rest, [([Inline], [[Block]])] -> Meta -> Meta
    metaFromDefList [([Inline], [[Block]])]
    ds Meta
    meta')
              _ -> ([Block]
    bs', Meta
    meta')

    metaFromDefList :: [([Inline], [[Block]])] -> Meta -> Meta
    metaFromDefList :: [([Inline], [[Block]])] -> Meta -> Meta
    metaFromDefList ds :: [([Inline], [[Block]])]
    ds meta :: Meta
    meta = Meta -> Meta
    adjustAuthors (Meta -> Meta) -> Meta -> Meta
    forall a b. (a -> b) -> a -> b
    $ (([Inline], [[Block]]) -> Meta -> Meta)
    -> Meta -> [([Inline], [[Block]])] -> Meta
    forall (t :: * -> *) a b.
    Foldable t =>
    (a -> b -> b) -> b -> t a -> b
    foldr ([Inline], [[Block]]) -> Meta -> Meta
    forall a a a.
    (HasMeta a, ToMetaValue (Many a), Walkable Inline a,
     Monoid (Many a)) =>
    (a, [[a]]) -> a -> a
    f Meta
    meta [([Inline], [[Block]])]
    ds
     where f :: (a, [[a]]) -> a -> a
    f (k :: a
    k,v :: [[a]]
    v) = Text -> Many a -> a -> a
    forall a b. (HasMeta a, ToMetaValue b) => Text -> b -> a -> a
    setMeta (Text -> Text
    T.toLower (Text -> Text) -> Text -> Text
    forall a b. (a -> b) -> a -> b
    $ a -> Text
    forall a. Walkable Inline a => a -> Text
    stringify a
    k) ([Many a] -> Many a
    forall a. Monoid a => [a] -> a
    mconcat ([Many a] -> Many a) -> [Many a] -> Many a
    forall a b. (a -> b) -> a -> b
    $ ([a] -> Many a) -> [[a]] -> [Many a]
    forall a b. (a -> b) -> [a] -> [b]
    map [a] -> Many a
    forall a. [a] -> Many a
    fromList [[a]]
    v)
           adjustAuthors :: Meta -> Meta
    adjustAuthors (Meta metamap :: Map Text MetaValue
    metamap) = Map Text MetaValue -> Meta
    Meta (Map Text MetaValue -> Meta) -> Map Text MetaValue -> Meta
    forall a b. (a -> b) -> a -> b
    $ (MetaValue -> MetaValue)
    -> Text -> Map Text MetaValue -> Map Text MetaValue
    forall k a. Ord k => (a -> a) -> k -> Map k a -> Map k a
    M.adjust MetaValue -> MetaValue
    splitAuthors "author"
                                               (Map Text MetaValue -> Map Text MetaValue)
    -> Map Text MetaValue -> Map Text MetaValue
    forall a b. (a -> b) -> a -> b
    $ (MetaValue -> MetaValue)
    -> Text -> Map Text MetaValue -> Map Text MetaValue
    forall k a. Ord k => (a -> a) -> k -> Map k a -> Map k a
    M.adjust MetaValue -> MetaValue
    toPlain "date"
                                               (Map Text MetaValue -> Map Text MetaValue)
    -> Map Text MetaValue -> Map Text MetaValue
    forall a b. (a -> b) -> a -> b
    $ (MetaValue -> MetaValue)
    -> Text -> Map Text MetaValue -> Map Text MetaValue
    forall k a. Ord k => (a -> a) -> k -> Map k a -> Map k a
    M.adjust MetaValue -> MetaValue
    toPlain "title"
                                               (Map Text MetaValue -> Map Text MetaValue)
    -> Map Text MetaValue -> Map Text MetaValue
    forall a b. (a -> b) -> a -> b
    $ (Text -> Text) -> Map Text MetaValue -> Map Text MetaValue
    forall k2 k1 a. Ord k2 => (k1 -> k2) -> Map k1 a -> Map k2 a
    M.mapKeys (\k :: Text
    k ->
                                                     if Text
    k Text -> Text -> Bool
    forall a. Eq a => a -> a -> Bool
    == "authors"
                                                        then "author"
                                                        else Text
    k) Map Text MetaValue
    metamap
           toPlain :: MetaValue -> MetaValue
    toPlain (MetaBlocks [Para xs :: [Inline]
    xs]) = [Inline] -> MetaValue
    MetaInlines [Inline]
    xs
           toPlain x :: MetaValue
    x                      = MetaValue
    x
           splitAuthors :: MetaValue -> MetaValue
    splitAuthors (MetaBlocks [Para xs :: [Inline]
    xs])
                                          = [MetaValue] -> MetaValue
    MetaList ([MetaValue] -> MetaValue) -> [MetaValue] -> MetaValue
    forall a b. (a -> b) -> a -> b
    $ ([Inline] -> MetaValue) -> [[Inline]] -> [MetaValue]
    forall a b. (a -> b) -> [a] -> [b]
    map [Inline] -> MetaValue
    MetaInlines
                                                     ([[Inline]] -> [MetaValue]) -> [[Inline]] -> [MetaValue]
    forall a b. (a -> b) -> a -> b
    $ [Inline] -> [[Inline]]
    splitAuthors' [Inline]
    xs
           splitAuthors x :: MetaValue
    x                 = MetaValue
    x
           splitAuthors' :: [Inline] -> [[Inline]]
    splitAuthors'                  = ([Inline] -> [Inline]) -> [[Inline]] -> [[Inline]]
    forall a b. (a -> b) -> [a] -> [b]
    map [Inline] -> [Inline]
    normalizeSpaces ([[Inline]] -> [[Inline]])
    -> ([Inline] -> [[Inline]]) -> [Inline] -> [[Inline]]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                                             [Inline] -> [[Inline]]
    splitOnSemi ([Inline] -> [[Inline]])
    -> ([Inline] -> [Inline]) -> [Inline] -> [[Inline]]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Inline -> [Inline]) -> [Inline] -> [Inline]
    forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
    concatMap Inline -> [Inline]
    factorSemi
           normalizeSpaces :: [Inline] -> [Inline]
    normalizeSpaces                = [Inline] -> [Inline]
    forall a. [a] -> [a]
    reverse ([Inline] -> [Inline])
    -> ([Inline] -> [Inline]) -> [Inline] -> [Inline]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Inline -> Bool) -> [Inline] -> [Inline]
    forall a. (a -> Bool) -> [a] -> [a]
    dropWhile Inline -> Bool
    isSp ([Inline] -> [Inline])
    -> ([Inline] -> [Inline]) -> [Inline] -> [Inline]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Inline] -> [Inline]
    forall a. [a] -> [a]
    reverse ([Inline] -> [Inline])
    -> ([Inline] -> [Inline]) -> [Inline] -> [Inline]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                                             (Inline -> Bool) -> [Inline] -> [Inline]
    forall a. (a -> Bool) -> [a] -> [a]
    dropWhile Inline -> Bool
    isSp
           isSp :: Inline -> Bool
    isSp Space     = Bool
    True
           isSp SoftBreak = Bool
    True
           isSp LineBreak = Bool
    True
           isSp _         = Bool
    False
           splitOnSemi :: [Inline] -> [[Inline]]
    splitOnSemi                    = (Inline -> Bool) -> [Inline] -> [[Inline]]
    forall a. (a -> Bool) -> [a] -> [[a]]
    splitBy (Inline -> Inline -> Bool
    forall a. Eq a => a -> a -> Bool
    ==Text -> Inline
    Str ";")
           factorSemi :: Inline -> [Inline]
    factorSemi (Str "")            = []
           factorSemi (Str s :: Text
    s)             = case (Char -> Bool) -> Text -> (Text, Text)
    T.break (Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    ==';') Text
    s of
                                              (xs :: Text
    xs,"") -> [Text -> Inline
    Str Text
    xs]
                                              (xs :: Text
    xs,Text -> Maybe (Char, Text)
    T.uncons -> Just (';',ys :: Text
    ys)) -> Text -> Inline
    Str Text
    xs Inline -> [Inline] -> [Inline]
    forall a. a -> [a] -> [a]
    : Text -> Inline
    Str ";" Inline -> [Inline] -> [Inline]
    forall a. a -> [a] -> [a]
    :
                                                Inline -> [Inline]
    factorSemi (Text -> Inline
    Str Text
    ys)
                                              (xs :: Text
    xs,ys :: Text
    ys) -> Text -> Inline
    Str Text
    xs Inline -> [Inline] -> [Inline]
    forall a. a -> [a] -> [a]
    :
                                                Inline -> [Inline]
    factorSemi (Text -> Inline
    Str Text
    ys)
           factorSemi x :: Inline
    x                   = [Inline
    x]

    parseRST :: PandocMonad m => RSTParser m Pandoc
    parseRST :: RSTParser m Pandoc
    parseRST = do
      ParsecT Text ParserState m Text -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m ()
    optional ParsecT Text ParserState m Text
    forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Text
    blanklines -- skip blank lines at beginning of file
      SourcePos
    startPos <- ParsecT Text ParserState m SourcePos
    forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
    getPosition
      -- go through once just to get list of reference keys and notes
      -- docMinusKeys is the raw document with blanks where the keys were...
      Text
    docMinusKeys <- [Text] -> Text
    T.concat ([Text] -> Text)
    -> ParsecT Text ParserState m [Text]
    -> ParsecT Text ParserState m Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$>
                      ParsecT Text ParserState m Text
    -> ParsecT Text ParserState m ()
    -> ParsecT Text ParserState m [Text]
    forall s (m :: * -> *) t u a end.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
    manyTill (ParsecT Text ParserState m Text
    forall (m :: * -> *). PandocMonad m => RSTParser m Text
    referenceKey ParsecT Text ParserState m Text
    -> ParsecT Text ParserState m Text
    -> ParsecT Text ParserState m Text
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT Text ParserState m Text
    forall (m :: * -> *). PandocMonad m => RSTParser m Text
    anchorDef ParsecT Text ParserState m Text
    -> ParsecT Text ParserState m Text
    -> ParsecT Text ParserState m Text
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|>
                                ParsecT Text ParserState m Text
    forall (m :: * -> *). Monad m => RSTParser m Text
    noteBlock ParsecT Text ParserState m Text
    -> ParsecT Text ParserState m Text
    -> ParsecT Text ParserState m Text
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT Text ParserState m Text
    forall (m :: * -> *). Monad m => RSTParser m Text
    citationBlock ParsecT Text ParserState m Text
    -> ParsecT Text ParserState m Text
    -> ParsecT Text ParserState m Text
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|>
                                ((Blocks, Text) -> Text
    forall a b. (a, b) -> b
    snd ((Blocks, Text) -> Text)
    -> ParsecT Text ParserState m (Blocks, Text)
    -> ParsecT Text ParserState m Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Text ParserState m Blocks
    -> ParsecT Text ParserState m (Blocks, Text)
    forall (m :: * -> *) st a.
    Monad m =>
    ParsecT Text st m a -> ParsecT Text st m (a, Text)
    withRaw ParsecT Text ParserState m Blocks
    forall (m :: * -> *). Monad m => RSTParser m Blocks
    comment) ParsecT Text ParserState m Text
    -> ParsecT Text ParserState m Text
    -> ParsecT Text ParserState m Text
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|>
                                ParsecT Text ParserState m Text
    forall (m :: * -> *). PandocMonad m => RSTParser m Text
    headerBlock ParsecT Text ParserState m Text
    -> ParsecT Text ParserState m Text
    -> ParsecT Text ParserState m Text
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT Text ParserState m Text
    forall (m :: * -> *) st. Monad m => ParserT Text st m Text
    lineClump) ParsecT Text ParserState m ()
    forall s (m :: * -> *) t u.
    (Stream s m t, Show t) =>
    ParsecT s u m ()
    eof
      Text -> ParsecT Text ParserState m ()
    forall (m :: * -> *) s u. Monad m => s -> ParsecT s u m ()
    setInput Text
    docMinusKeys
      SourcePos -> ParsecT Text ParserState m ()
    forall (m :: * -> *) s u. Monad m => SourcePos -> ParsecT s u m ()
    setPosition SourcePos
    startPos
      ParserState
    st' <- ParsecT Text ParserState m ParserState
    forall (m :: * -> *) s u. Monad m => ParsecT s u m u
    getState
      let reversedNotes :: NoteTable
    reversedNotes = ParserState -> NoteTable
    stateNotes ParserState
    st'
      (ParserState -> ParserState) -> ParsecT Text ParserState m ()
    forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
    updateState ((ParserState -> ParserState) -> ParsecT Text ParserState m ())
    -> (ParserState -> ParserState) -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ \s :: ParserState
    s -> ParserState
    s { stateNotes :: NoteTable
    stateNotes = NoteTable -> NoteTable
    forall a. [a] -> [a]
    reverse NoteTable
    reversedNotes
                            , stateIdentifiers :: Set Text
    stateIdentifiers = Set Text
    forall a. Monoid a => a
    mempty }
      -- now parse it for real...
      [Block]
    blocks <- Blocks -> [Block]
    forall a. Many a -> [a]
    B.toList (Blocks -> [Block])
    -> ParsecT Text ParserState m Blocks
    -> ParsecT Text ParserState m [Block]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Text ParserState m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    parseBlocks
      NoteTable
    citations <- (NoteTable -> NoteTable
    forall a. Ord a => [a] -> [a]
    sort (NoteTable -> NoteTable)
    -> (ParserState -> NoteTable) -> ParserState -> NoteTable
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Map Text Text -> NoteTable
    forall k a. Map k a -> [(k, a)]
    M.toList (Map Text Text -> NoteTable)
    -> (ParserState -> Map Text Text) -> ParserState -> NoteTable
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ParserState -> Map Text Text
    stateCitations) (ParserState -> NoteTable)
    -> ParsecT Text ParserState m ParserState
    -> ParsecT Text ParserState m NoteTable
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Text ParserState m ParserState
    forall (m :: * -> *) s u. Monad m => ParsecT s u m u
    getState
      [(Many Inline, [Blocks])]
    citationItems <- ((Text, Text)
     -> ParsecT Text ParserState m (Many Inline, [Blocks]))
    -> NoteTable
    -> ParsecT Text ParserState m [(Many Inline, [Blocks])]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    mapM (Text, Text) -> ParsecT Text ParserState m (Many Inline, [Blocks])
    forall (m :: * -> *).
    PandocMonad m =>
    (Text, Text) -> RSTParser m (Many Inline, [Blocks])
    parseCitation NoteTable
    citations
      let refBlock :: [Block]
    refBlock = [Attr -> [Block] -> Block
    Div ("citations",[],[]) ([Block] -> Block) -> [Block] -> Block
    forall a b. (a -> b) -> a -> b
    $
                     Blocks -> [Block]
    forall a. Many a -> [a]
    B.toList (Blocks -> [Block]) -> Blocks -> [Block]
    forall a b. (a -> b) -> a -> b
    $ [(Many Inline, [Blocks])] -> Blocks
    B.definitionList [(Many Inline, [Blocks])]
    citationItems | Bool -> Bool
    not ([(Many Inline, [Blocks])] -> Bool
    forall (t :: * -> *) a. Foldable t => t a -> Bool
    null [(Many Inline, [Blocks])]
    citationItems)]
      Bool
    standalone <- (ReaderOptions -> Bool) -> ParserT Text ParserState m Bool
    forall st s (m :: * -> *) t b.
    (HasReaderOptions st, Stream s m t) =>
    (ReaderOptions -> b) -> ParserT s st m b
    getOption ReaderOptions -> Bool
    readerStandalone
      ParserState
    state <- ParsecT Text ParserState m ParserState
    forall (m :: * -> *) s u. Monad m => ParsecT s u m u
    getState
      let meta :: Meta
    meta = ParserState -> Meta
    stateMeta ParserState
    state
      let (blocks' :: [Block]
    blocks', meta' :: Meta
    meta') = if Bool
    standalone
                                then ([Block], Meta) -> ([Block], Meta)
    titleTransform ([Block]
    blocks, Meta
    meta)
                                else ([Block]
    blocks, Meta
    meta)
      ParsecT Text ParserState m ()
    forall (m :: * -> *) st s.
    (PandocMonad m, HasLogMessages st) =>
    ParserT s st m ()
    reportLogMessages
      Pandoc -> RSTParser m Pandoc
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Pandoc -> RSTParser m Pandoc) -> Pandoc -> RSTParser m Pandoc
    forall a b. (a -> b) -> a -> b
    $ Meta -> [Block] -> Pandoc
    Pandoc Meta
    meta' ([Block]
    blocks' [Block] -> [Block] -> [Block]
    forall a. [a] -> [a] -> [a]
    ++ [Block]
    refBlock)

    parseCitation :: PandocMonad m
                  => (Text, Text) -> RSTParser m (Inlines, [Blocks])
    parseCitation :: (Text, Text) -> RSTParser m (Many Inline, [Blocks])
    parseCitation (ref :: Text
    ref, raw :: Text
    raw) = do
      Blocks
    contents <- ParserT Text ParserState m Blocks
    -> Text -> ParserT Text ParserState m Blocks
    forall s (m :: * -> *) u a.
    (Stream s m Char, IsString s, HasLastStrPosition u) =>
    ParserT s u m a -> Text -> ParserT s u m a
    parseFromString' ParserT Text ParserState m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    parseBlocks Text
    raw
      (Many Inline, [Blocks]) -> RSTParser m (Many Inline, [Blocks])
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Attr -> Many Inline -> Many Inline
    B.spanWith (Text
    ref, ["citation-label"], []) (Text -> Many Inline
    B.str Text
    ref),
               [Blocks
    contents])

    --
    -- parsing blocks
    --

    parseBlocks :: PandocMonad m => RSTParser m Blocks
    parseBlocks :: RSTParser m Blocks
    parseBlocks = [Blocks] -> Blocks
    forall a. Monoid a => [a] -> a
    mconcat ([Blocks] -> Blocks)
    -> ParsecT Text ParserState m [Blocks] -> RSTParser m Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> RSTParser m Blocks
    -> ParsecT Text ParserState m ()
    -> ParsecT Text ParserState 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 RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    block ParsecT Text ParserState m ()
    forall s (m :: * -> *) t u.
    (Stream s m t, Show t) =>
    ParsecT s u m ()
    eof

    block :: PandocMonad m => RSTParser m Blocks
    block :: RSTParser m Blocks
    block = [RSTParser m Blocks] -> RSTParser m Blocks
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    [ParsecT s u m a] -> ParsecT s u m a
    choice [ RSTParser m Blocks
    forall (m :: * -> *). Monad m => RSTParser m Blocks
    codeBlock
                   , RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    blockQuote
                   , RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    fieldList
                   , RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    directive
                   , RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    anchor
                   , RSTParser m Blocks
    forall (m :: * -> *). Monad m => RSTParser m Blocks
    comment
                   , RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    header
                   , RSTParser m Blocks
    forall (m :: * -> *) st. Monad m => ParserT Text st m Blocks
    hrule
                   , RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    lineBlock     -- must go before definitionList
                   , RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    table
                   , RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    list
                   , RSTParser m Blocks
    forall (m :: * -> *). Monad m => RSTParser m Blocks
    lhsCodeBlock
                   , RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    para
                   , Blocks
    forall a. Monoid a => a
    mempty Blocks -> ParsecT Text ParserState m Text -> RSTParser m Blocks
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ ParsecT Text ParserState m Text
    forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Text
    blanklines
                   ] RSTParser m Blocks -> [Char] -> RSTParser m Blocks
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> [Char] -> ParsecT s u m a
    <?> "block"

    --
    -- field list
    --

    rawFieldListItem :: Monad m => Int -> RSTParser m (Text, Text)
    rawFieldListItem :: Int -> RSTParser m (Text, Text)
    rawFieldListItem minIndent :: Int
    minIndent = RSTParser m (Text, Text) -> RSTParser m (Text, Text)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m (Text, Text) -> RSTParser m (Text, Text))
    -> RSTParser m (Text, Text) -> RSTParser m (Text, Text)
    forall a b. (a -> b) -> a -> b
    $ do
      Int
    indent <- [Char] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length ([Char] -> Int)
    -> ParsecT Text ParserState m [Char]
    -> ParsecT Text ParserState m Int
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m [Char]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many (Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char ' ')
      Bool -> ParsecT Text ParserState m ()
    forall (f :: * -> *). Alternative f => Bool -> f ()
    guard (Bool -> ParsecT Text ParserState m ())
    -> Bool -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ Int
    indent Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    >= Int
    minIndent
      Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char ':'
      Text
    name <- ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m Char
    -> ParserT Text ParserState m Text
    forall end s (m :: * -> *) t st.
    (Show end, Stream s m t) =>
    ParserT s st m Char -> ParserT s st m end -> ParserT s st m Text
    many1TillChar ([Char] -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m Char
    noneOf "\n") (Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char ':')
      (() ()
    -> ParsecT Text ParserState m Char -> ParsecT Text ParserState m ()
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ ParsecT Text ParserState m Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m a
    lookAhead ParsecT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    newline) ParsecT Text ParserState m ()
    -> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT Text ParserState m Char -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m ()
    skipMany1 ParsecT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    spaceChar
      Text
    first <- ParserT Text ParserState m Text
    forall (m :: * -> *) st. Monad m => ParserT Text st m Text
    anyLine
      Text
    rest <- Text
    -> ParserT Text ParserState m Text
    -> ParserT Text ParserState m Text
    forall s (m :: * -> *) t a u.
    Stream s m t =>
    a -> ParsecT s u m a -> ParsecT s u m a
    option "" (ParserT Text ParserState m Text
     -> ParserT Text ParserState m Text)
    -> ParserT Text ParserState m Text
    -> ParserT Text ParserState m Text
    forall a b. (a -> b) -> a -> b
    $ ParserT Text ParserState m Text -> ParserT Text ParserState m Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParserT Text ParserState m Text
     -> ParserT Text ParserState m Text)
    -> ParserT Text ParserState m Text
    -> ParserT Text ParserState m Text
    forall a b. (a -> b) -> a -> b
    $ do ParsecT Text ParserState m Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m a
    lookAhead (Int
    -> ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m [Char]
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    Int -> ParsecT s u m a -> ParsecT s u m [a]
    count Int
    indent (Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char ' ') ParsecT Text ParserState m [Char]
    -> ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m Char
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    spaceChar)
                                   ParserT Text ParserState m Text
    forall st (m :: * -> *).
    (HasReaderOptions st, Monad m) =>
    ParserT Text st m Text
    indentedBlock
      let raw :: Text
    raw = (if Text -> Bool
    T.null Text
    first then "" else Text
    first Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> "\n") Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    rest Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> "\n"
      (Text, Text) -> RSTParser m (Text, Text)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Text
    name, Text
    raw)

    fieldListItem :: PandocMonad m => Int -> RSTParser m (Inlines, [Blocks])
    fieldListItem :: Int -> RSTParser m (Many Inline, [Blocks])
    fieldListItem minIndent :: Int
    minIndent = RSTParser m (Many Inline, [Blocks])
    -> RSTParser m (Many Inline, [Blocks])
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m (Many Inline, [Blocks])
     -> RSTParser m (Many Inline, [Blocks]))
    -> RSTParser m (Many Inline, [Blocks])
    -> RSTParser m (Many Inline, [Blocks])
    forall a b. (a -> b) -> a -> b
    $ do
      (name :: Text
    name, raw :: Text
    raw) <- Int -> RSTParser m (Text, Text)
    forall (m :: * -> *). Monad m => Int -> RSTParser m (Text, Text)
    rawFieldListItem Int
    minIndent
      Many Inline
    term <- Text -> RSTParser m (Many Inline)
    forall (m :: * -> *).
    PandocMonad m =>
    Text -> RSTParser m (Many Inline)
    parseInlineFromText Text
    name
      Blocks
    contents <- ParserT Text ParserState m Blocks
    -> Text -> ParserT Text ParserState m Blocks
    forall s (m :: * -> *) u a.
    (Stream s m Char, IsString s, HasLastStrPosition u) =>
    ParserT s u m a -> Text -> ParserT s u m a
    parseFromString' ParserT Text ParserState m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    parseBlocks Text
    raw
      ParsecT Text ParserState m Text -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m ()
    optional ParsecT Text ParserState m Text
    forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Text
    blanklines
      (Many Inline, [Blocks]) -> RSTParser m (Many Inline, [Blocks])
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline
    term, [Blocks
    contents])

    fieldList :: PandocMonad m => RSTParser m Blocks
    fieldList :: RSTParser m Blocks
    fieldList = RSTParser m Blocks -> RSTParser m Blocks
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m Blocks -> RSTParser m Blocks)
    -> RSTParser m Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ do
      Int
    indent <- [Char] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length ([Char] -> Int)
    -> ParsecT Text ParserState m [Char]
    -> ParsecT Text ParserState m Int
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Text ParserState m [Char]
    -> ParsecT Text ParserState m [Char]
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m a
    lookAhead (ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m [Char]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many ParsecT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    spaceChar)
      [(Many Inline, [Blocks])]
    items <- ParsecT Text ParserState m (Many Inline, [Blocks])
    -> ParsecT Text ParserState m [(Many Inline, [Blocks])]
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m [a]
    many1 (ParsecT Text ParserState m (Many Inline, [Blocks])
     -> ParsecT Text ParserState m [(Many Inline, [Blocks])])
    -> ParsecT Text ParserState m (Many Inline, [Blocks])
    -> ParsecT Text ParserState m [(Many Inline, [Blocks])]
    forall a b. (a -> b) -> a -> b
    $ Int -> ParsecT Text ParserState m (Many Inline, [Blocks])
    forall (m :: * -> *).
    PandocMonad m =>
    Int -> RSTParser m (Many Inline, [Blocks])
    fieldListItem Int
    indent
      case [(Many Inline, [Blocks])]
    items of
         []     -> Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return Blocks
    forall a. Monoid a => a
    mempty
         items' :: [(Many Inline, [Blocks])]
    items' -> Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> RSTParser m Blocks) -> Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ [(Many Inline, [Blocks])] -> Blocks
    B.definitionList [(Many Inline, [Blocks])]
    items'

    --
    -- line block
    --

    lineBlock :: PandocMonad m => RSTParser m Blocks
    lineBlock :: RSTParser m Blocks
    lineBlock = RSTParser m Blocks -> RSTParser m Blocks
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m Blocks -> RSTParser m Blocks)
    -> RSTParser m Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ do
      [Text]
    lines' <- ParserT Text ParserState m [Text]
    forall (m :: * -> *) st. Monad m => ParserT Text st m [Text]
    lineBlockLines
      [Many Inline]
    lines'' <- (Text -> ParsecT Text ParserState m (Many Inline))
    -> [Text] -> ParsecT Text ParserState m [Many Inline]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    mapM Text -> ParsecT Text ParserState m (Many Inline)
    forall (m :: * -> *).
    PandocMonad m =>
    Text -> RSTParser m (Many Inline)
    parseInlineFromText [Text]
    lines'
      Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> RSTParser m Blocks) -> Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ [Many Inline] -> Blocks
    B.lineBlock [Many Inline]
    lines''

    lineBlockDirective :: PandocMonad m => Text -> RSTParser m Blocks
    lineBlockDirective :: Text -> RSTParser m Blocks
    lineBlockDirective body :: Text
    body = do
      [Many Inline]
    lines' <- (Text -> ParsecT Text ParserState m (Many Inline))
    -> [Text] -> ParsecT Text ParserState m [Many Inline]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    mapM Text -> ParsecT Text ParserState m (Many Inline)
    forall (m :: * -> *).
    PandocMonad m =>
    Text -> RSTParser m (Many Inline)
    parseInlineFromText ([Text] -> ParsecT Text ParserState m [Many Inline])
    -> [Text] -> ParsecT Text ParserState m [Many Inline]
    forall a b. (a -> b) -> a -> b
    $ Text -> [Text]
    T.lines (Text -> [Text]) -> Text -> [Text]
    forall a b. (a -> b) -> a -> b
    $ Text -> Text
    stripTrailingNewlines Text
    body
      Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> RSTParser m Blocks) -> Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ [Many Inline] -> Blocks
    B.lineBlock [Many Inline]
    lines'

    --
    -- paragraph block
    --

    -- note: paragraph can end in a :: starting a code block
    para :: PandocMonad m => RSTParser m Blocks
    para :: RSTParser m Blocks
    para = RSTParser m Blocks -> RSTParser m Blocks
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m Blocks -> RSTParser m Blocks)
    -> RSTParser m Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ do
      Many Inline
    result <- Many Inline -> Many Inline
    trimInlines (Many Inline -> Many Inline)
    -> ([Many Inline] -> Many Inline) -> [Many Inline] -> Many Inline
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Many Inline] -> Many Inline
    forall a. Monoid a => [a] -> a
    mconcat ([Many Inline] -> Many Inline)
    -> ParsecT Text ParserState m [Many Inline]
    -> ParsecT Text ParserState m (Many Inline)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Text ParserState m (Many Inline)
    -> ParsecT Text ParserState m [Many Inline]
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m [a]
    many1 ParsecT Text ParserState m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    inline
      Blocks -> RSTParser m Blocks -> RSTParser m Blocks
    forall s (m :: * -> *) t a u.
    Stream s m t =>
    a -> ParsecT s u m a -> ParsecT s u m a
    option (Many Inline -> Blocks
    B.plain Many Inline
    result) (RSTParser m Blocks -> RSTParser m Blocks)
    -> RSTParser m Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ RSTParser m Blocks -> RSTParser m Blocks
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m Blocks -> RSTParser m Blocks)
    -> RSTParser m Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ do
        ParsecT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    newline
        ParserT Text ParserState m Text
    forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Text
    blanklines
        case Seq Inline -> ViewR Inline
    forall a. Seq a -> ViewR a
    viewr (Many Inline -> Seq Inline
    forall a. Many a -> Seq a
    B.unMany Many Inline
    result) of
             ys :: Seq Inline
    ys :> Str xs :: Text
    xs | "::" Text -> Text -> Bool
    `T.isSuffixOf` Text
    xs -> do
                  Blocks
    raw <- Blocks -> RSTParser m Blocks -> RSTParser m Blocks
    forall s (m :: * -> *) t a u.
    Stream s m t =>
    a -> ParsecT s u m a -> ParsecT s u m a
    option Blocks
    forall a. Monoid a => a
    mempty RSTParser m Blocks
    forall (m :: * -> *). Monad m => RSTParser m Blocks
    codeBlockBody
                  Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> RSTParser m Blocks) -> Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ Many Inline -> Blocks
    B.para (Seq Inline -> Many Inline
    forall a. Seq a -> Many a
    B.Many Seq Inline
    ys Many Inline -> Many Inline -> Many Inline
    forall a. Semigroup a => a -> a -> a
    <> Text -> Many Inline
    B.str (Int -> Text -> Text
    T.take (Text -> Int
    T.length Text
    xs Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - 1) Text
    xs))
                             Blocks -> Blocks -> Blocks
    forall a. Semigroup a => a -> a -> a
    <> Blocks
    raw
             _ -> Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline -> Blocks
    B.para Many Inline
    result)

    plain :: PandocMonad m => RSTParser m Blocks
    plain :: RSTParser m Blocks
    plain = Many Inline -> Blocks
    B.plain (Many Inline -> Blocks)
    -> ([Many Inline] -> Many Inline) -> [Many Inline] -> Blocks
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Many Inline -> Many Inline
    trimInlines (Many Inline -> Many Inline)
    -> ([Many Inline] -> Many Inline) -> [Many Inline] -> Many Inline
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Many Inline] -> Many Inline
    forall a. Monoid a => [a] -> a
    mconcat ([Many Inline] -> Blocks)
    -> ParsecT Text ParserState m [Many Inline] -> RSTParser m Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Text ParserState m (Many Inline)
    -> ParsecT Text ParserState m [Many Inline]
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m [a]
    many1 ParsecT Text ParserState m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    inline

    --
    -- header blocks
    --

    header :: PandocMonad m => RSTParser m Blocks
    header :: RSTParser m Blocks
    header = RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    doubleHeader RSTParser m Blocks -> RSTParser m Blocks -> RSTParser m Blocks
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    singleHeader RSTParser m Blocks -> [Char] -> RSTParser m Blocks
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> [Char] -> ParsecT s u m a
    <?> "header"

    -- a header with lines on top and bottom
    doubleHeader :: PandocMonad m => RSTParser m Blocks
    doubleHeader :: RSTParser m Blocks
    doubleHeader = do
      (txt :: Many Inline
    txt, c :: Char
    c) <- RSTParser m (Many Inline, Char)
    forall (m :: * -> *).
    PandocMonad m =>
    RSTParser m (Many Inline, Char)
    doubleHeader'
      -- check to see if we've had this kind of header before.
      -- if so, get appropriate level.  if not, add to list.
      ParserState
    state <- ParsecT Text ParserState m ParserState
    forall (m :: * -> *) s u. Monad m => ParsecT s u m u
    getState
      let headerTable :: [HeaderType]
    headerTable = ParserState -> [HeaderType]
    stateHeaderTable ParserState
    state
      let (headerTable' :: [HeaderType]
    headerTable',level :: Int
    level) = case HeaderType -> [HeaderType] -> Maybe Int
    forall a. Eq a => a -> [a] -> Maybe Int
    elemIndex (Char -> HeaderType
    DoubleHeader Char
    c) [HeaderType]
    headerTable of
            Just ind :: Int
    ind -> ([HeaderType]
    headerTable, Int
    ind Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + 1)
            Nothing  -> ([HeaderType]
    headerTable [HeaderType] -> [HeaderType] -> [HeaderType]
    forall a. [a] -> [a] -> [a]
    ++ [Char -> HeaderType
    DoubleHeader Char
    c], [HeaderType] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length [HeaderType]
    headerTable Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + 1)
      ParserState -> ParsecT Text ParserState m ()
    forall (m :: * -> *) u s. Monad m => u -> ParsecT s u m ()
    setState (ParserState
    state { stateHeaderTable :: [HeaderType]
    stateHeaderTable = [HeaderType]
    headerTable' })
      Attr
    attr <- Attr -> Many Inline -> ParserT Text ParserState m Attr
    forall s (m :: * -> *) a st.
    (Stream s m a, HasReaderOptions st, HasLogMessages st,
     HasIdentifierList st) =>
    Attr -> Many Inline -> ParserT s st m Attr
    registerHeader Attr
    nullAttr Many Inline
    txt
      Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> RSTParser m Blocks) -> Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ Attr -> Int -> Many Inline -> Blocks
    B.headerWith Attr
    attr Int
    level Many Inline
    txt

    doubleHeader' :: PandocMonad m => RSTParser m (Inlines, Char)
    doubleHeader' :: RSTParser m (Many Inline, Char)
    doubleHeader' = RSTParser m (Many Inline, Char) -> RSTParser m (Many Inline, Char)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m (Many Inline, Char)
     -> RSTParser m (Many Inline, Char))
    -> RSTParser m (Many Inline, Char)
    -> RSTParser m (Many Inline, Char)
    forall a b. (a -> b) -> a -> b
    $ do
      Char
    c <- [Char] -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m Char
    oneOf [Char]
    underlineChars
      [Char]
    rest <- ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m [Char]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many (Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char Char
    c)  -- the top line
      let lenTop :: Int
    lenTop = [Char] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length (Char
    cChar -> [Char] -> [Char]
    forall a. a -> [a] -> [a]
    :[Char]
    rest)
      ParserT Text ParserState m ()
    forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
    skipSpaces
      ParsecT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    newline
      Many Inline
    txt <- Many Inline -> Many Inline
    trimInlines (Many Inline -> Many Inline)
    -> ([Many Inline] -> Many Inline) -> [Many Inline] -> Many Inline
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Many Inline] -> Many Inline
    forall a. Monoid a => [a] -> a
    mconcat ([Many Inline] -> Many Inline)
    -> ParsecT Text ParserState m [Many Inline]
    -> ParsecT Text ParserState m (Many Inline)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Text ParserState m (Many Inline)
    -> ParsecT Text ParserState m [Many Inline]
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m [a]
    many1 (ParsecT Text ParserState m Char -> ParserT Text ParserState m ()
    forall s (m :: * -> *) t a u.
    (Stream s m t, Show a) =>
    ParsecT s u m a -> ParsecT s u m ()
    notFollowedBy ParsecT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    blankline ParserT Text ParserState m ()
    -> ParsecT Text ParserState m (Many Inline)
    -> ParsecT Text ParserState m (Many Inline)
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> ParsecT Text ParserState m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    inline)
      SourcePos
    pos <- ParsecT Text ParserState m SourcePos
    forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
    getPosition
      let len :: Int
    len = SourcePos -> Int
    sourceColumn SourcePos
    pos Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - 1
      Bool
    -> ParserT Text ParserState m () -> ParserT Text ParserState m ()
    forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
    when (Int
    len Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    > Int
    lenTop) (ParserT Text ParserState m () -> ParserT Text ParserState m ())
    -> ParserT Text ParserState m () -> ParserT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ [Char] -> ParserT Text ParserState m ()
    forall (m :: * -> *) a. MonadFail m => [Char] -> m a
    Prelude.fail "title longer than border"
      ParsecT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    blankline              -- spaces and newline
      Int
    -> ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m [Char]
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    Int -> ParsecT s u m a -> ParsecT s u m [a]
    count Int
    lenTop (Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char Char
    c)  -- the bottom line
      ParserT Text ParserState m Text
    forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Text
    blanklines
      (Many Inline, Char) -> RSTParser m (Many Inline, Char)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline
    txt, Char
    c)

    -- a header with line on the bottom only
    singleHeader :: PandocMonad m => RSTParser m Blocks
    singleHeader :: RSTParser m Blocks
    singleHeader = do
      (txt :: Many Inline
    txt, c :: Char
    c) <- RSTParser m (Many Inline, Char)
    forall (m :: * -> *).
    PandocMonad m =>
    RSTParser m (Many Inline, Char)
    singleHeader'
      ParserState
    state <- ParsecT Text ParserState m ParserState
    forall (m :: * -> *) s u. Monad m => ParsecT s u m u
    getState
      let headerTable :: [HeaderType]
    headerTable = ParserState -> [HeaderType]
    stateHeaderTable ParserState
    state
      let (headerTable' :: [HeaderType]
    headerTable',level :: Int
    level) = case HeaderType -> [HeaderType] -> Maybe Int
    forall a. Eq a => a -> [a] -> Maybe Int
    elemIndex (Char -> HeaderType
    SingleHeader Char
    c) [HeaderType]
    headerTable of
            Just ind :: Int
    ind -> ([HeaderType]
    headerTable, Int
    ind Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + 1)
            Nothing  -> ([HeaderType]
    headerTable [HeaderType] -> [HeaderType] -> [HeaderType]
    forall a. [a] -> [a] -> [a]
    ++ [Char -> HeaderType
    SingleHeader Char
    c], [HeaderType] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length [HeaderType]
    headerTable Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + 1)
      ParserState -> ParsecT Text ParserState m ()
    forall (m :: * -> *) u s. Monad m => u -> ParsecT s u m ()
    setState (ParserState
    state { stateHeaderTable :: [HeaderType]
    stateHeaderTable = [HeaderType]
    headerTable' })
      Attr
    attr <- Attr -> Many Inline -> ParserT Text ParserState m Attr
    forall s (m :: * -> *) a st.
    (Stream s m a, HasReaderOptions st, HasLogMessages st,
     HasIdentifierList st) =>
    Attr -> Many Inline -> ParserT s st m Attr
    registerHeader Attr
    nullAttr Many Inline
    txt
      Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> RSTParser m Blocks) -> Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ Attr -> Int -> Many Inline -> Blocks
    B.headerWith Attr
    attr Int
    level Many Inline
    txt

    singleHeader' :: PandocMonad m => RSTParser m (Inlines, Char)
    singleHeader' :: RSTParser m (Many Inline, Char)
    singleHeader' = RSTParser m (Many Inline, Char) -> RSTParser m (Many Inline, Char)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m (Many Inline, Char)
     -> RSTParser m (Many Inline, Char))
    -> RSTParser m (Many Inline, Char)
    -> RSTParser m (Many Inline, Char)
    forall a b. (a -> b) -> a -> b
    $ do
      ParserT Text ParserState m (Many Inline)
    -> ParserT Text ParserState m ()
    forall b s (m :: * -> *) a st.
    (Show b, Stream s m a) =>
    ParserT s st m b -> ParserT s st m ()
    notFollowedBy' ParserT Text ParserState m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    whitespace
      ParsecT Text ParserState m Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m a
    lookAhead (ParsecT Text ParserState m Char
     -> ParsecT Text ParserState m Char)
    -> ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m Char
    forall a b. (a -> b) -> a -> b
    $ ParserT Text ParserState m Text
    forall (m :: * -> *) st. Monad m => ParserT Text st m Text
    anyLine ParserT Text ParserState m Text
    -> ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m Char
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> [Char] -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m Char
    oneOf [Char]
    underlineChars
      Many Inline
    txt <- Many Inline -> Many Inline
    trimInlines (Many Inline -> Many Inline)
    -> ([Many Inline] -> Many Inline) -> [Many Inline] -> Many Inline
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Many Inline] -> Many Inline
    forall a. Monoid a => [a] -> a
    mconcat ([Many Inline] -> Many Inline)
    -> ParsecT Text ParserState m [Many Inline]
    -> ParserT Text ParserState m (Many Inline)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParserT Text ParserState m (Many Inline)
    -> ParsecT Text ParserState m [Many Inline]
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m [a]
    many1 (ParsecT Text ParserState m Char -> ParserT Text ParserState m ()
    forall s (m :: * -> *) t a u.
    (Stream s m t, Show a) =>
    ParsecT s u m a -> ParsecT s u m ()
    notFollowedBy ParsecT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    blankline ParserT Text ParserState m ()
    -> ParserT Text ParserState m (Many Inline)
    -> ParserT Text ParserState m (Many Inline)
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> ParserT Text ParserState m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    inline)
      SourcePos
    pos <- ParsecT Text ParserState m SourcePos
    forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
    getPosition
      let len :: Int
    len = SourcePos -> Int
    sourceColumn SourcePos
    pos Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - 1
      ParsecT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    blankline
      Char
    c <- [Char] -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m Char
    oneOf [Char]
    underlineChars
      Int
    -> ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m [Char]
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    Int -> ParsecT s u m a -> ParsecT s u m [a]
    count (Int
    len Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - 1) (Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char Char
    c)
      ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m [Char]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many (Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char Char
    c)
      ParserT Text ParserState m Text
    forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Text
    blanklines
      (Many Inline, Char) -> RSTParser m (Many Inline, Char)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline
    txt, Char
    c)

    --
    -- hrule block
    --

    hrule :: Monad m => ParserT Text st m Blocks
    hrule :: ParserT Text st m Blocks
    hrule = ParserT Text st m Blocks -> ParserT Text st m Blocks
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParserT Text st m Blocks -> ParserT Text st m Blocks)
    -> ParserT Text st m Blocks -> ParserT Text st m Blocks
    forall a b. (a -> b) -> a -> b
    $ do
      Char
    chr <- [Char] -> ParsecT Text st m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m Char
    oneOf [Char]
    underlineChars
      Int -> ParsecT Text st m Char -> ParsecT Text st m [Char]
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    Int -> ParsecT s u m a -> ParsecT s u m [a]
    count 3 (Char -> ParsecT Text st m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char Char
    chr)
      ParsecT Text st m Char -> ParsecT Text st m ()
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
    skipMany (Char -> ParsecT Text st m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char Char
    chr)
      ParsecT Text st m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    blankline
      ParserT Text st m Text
    forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Text
    blanklines
      Blocks -> ParserT Text st m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return Blocks
    B.horizontalRule

    --
    -- code blocks
    --

    -- read a line indented by a given string
    indentedLine :: (HasReaderOptions st, Monad m)
                 => Int -> ParserT Text st m Text
    indentedLine :: Int -> ParserT Text st m Text
    indentedLine indents :: Int
    indents = ParserT Text st m Text -> ParserT Text st m Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParserT Text st m Text -> ParserT Text st m Text)
    -> ParserT Text st m Text -> ParserT Text st m Text
    forall a b. (a -> b) -> a -> b
    $ do
      ParsecT Text st m Char -> ParsecT Text st m Char
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m a
    lookAhead ParsecT Text st m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    spaceChar
      Int -> ParserT Text st m Int
    forall st (m :: * -> *).
    (HasReaderOptions st, Monad m) =>
    Int -> ParserT Text st m Int
    gobbleAtMostSpaces Int
    indents
      ParserT Text st m Text
    forall (m :: * -> *) st. Monad m => ParserT Text st m Text
    anyLine

    -- one or more indented lines, possibly separated by blank lines.
    -- any amount of indentation will work.
    indentedBlock :: (HasReaderOptions st, Monad m)
                  => ParserT Text st m Text
    indentedBlock :: ParserT Text st m Text
    indentedBlock = ParserT Text st m Text -> ParserT Text st m Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParserT Text st m Text -> ParserT Text st m Text)
    -> ParserT Text st m Text -> ParserT Text st m Text
    forall a b. (a -> b) -> a -> b
    $ do
      Int
    indents <- [Char] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length ([Char] -> Int)
    -> ParsecT Text st m [Char] -> ParsecT Text st m Int
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Text st m [Char] -> ParsecT Text st m [Char]
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m a
    lookAhead (ParsecT Text st m Char -> ParsecT Text st m [Char]
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m [a]
    many1 ParsecT Text st m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    spaceChar)
      [Text]
    lns <- ParserT Text st m Text -> ParsecT Text st m [Text]
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m [a]
    many1 (ParserT Text st m Text -> ParsecT Text st m [Text])
    -> ParserT Text st m Text -> ParsecT Text st m [Text]
    forall a b. (a -> b) -> a -> b
    $ ParserT Text st m Text -> ParserT Text st m Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParserT Text st m Text -> ParserT Text st m Text)
    -> ParserT Text st m Text -> ParserT Text st m Text
    forall a b. (a -> b) -> a -> b
    $ do Text
    b <- Text -> ParserT Text st m Text -> ParserT Text st m Text
    forall s (m :: * -> *) t a u.
    Stream s m t =>
    a -> ParsecT s u m a -> ParsecT s u m a
    option "" ParserT Text st m Text
    forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Text
    blanklines
                              Text
    l <- Int -> ParserT Text st m Text
    forall st (m :: * -> *).
    (HasReaderOptions st, Monad m) =>
    Int -> ParserT Text st m Text
    indentedLine Int
    indents
                              Text -> ParserT Text st m Text
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Text
    b Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    l)
      ParserT Text st m Text -> ParsecT Text st m ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m ()
    optional ParserT Text st m Text
    forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Text
    blanklines
      Text -> ParserT Text st m Text
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Text -> ParserT Text st m Text) -> Text -> ParserT Text st m Text
    forall a b. (a -> b) -> a -> b
    $ [Text] -> Text
    T.unlines [Text]
    lns

    quotedBlock :: Monad m => ParserT Text st m Text
    quotedBlock :: ParserT Text st m Text
    quotedBlock = ParserT Text st m Text -> ParserT Text st m Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParserT Text st m Text -> ParserT Text st m Text)
    -> ParserT Text st m Text -> ParserT Text st m Text
    forall a b. (a -> b) -> a -> b
    $ do
        Char
    quote <- ParsecT Text st m Char -> ParsecT Text st m Char
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m a
    lookAhead (ParsecT Text st m Char -> ParsecT Text st m Char)
    -> ParsecT Text st m Char -> ParsecT Text st m Char
    forall a b. (a -> b) -> a -> b
    $ [Char] -> ParsecT Text st m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m Char
    oneOf "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
        [Text]
    lns <- ParserT Text st m Text -> ParsecT Text st m [Text]
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m [a]
    many1 (ParserT Text st m Text -> ParsecT Text st m [Text])
    -> ParserT Text st m Text -> ParsecT Text st m [Text]
    forall a b. (a -> b) -> a -> b
    $ ParsecT Text st m Char -> ParsecT Text st m Char
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m a
    lookAhead (Char -> ParsecT Text st m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char Char
    quote) ParsecT Text st m Char
    -> ParserT Text st m Text -> ParserT Text st m Text
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> ParserT Text st m Text
    forall (m :: * -> *) st. Monad m => ParserT Text st m Text
    anyLine
        ParserT Text st m Text -> ParsecT Text st m ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m ()
    optional ParserT Text st m Text
    forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Text
    blanklines
        Text -> ParserT Text st m Text
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Text -> ParserT Text st m Text) -> Text -> ParserT Text st m Text
    forall a b. (a -> b) -> a -> b
    $ [Text] -> Text
    T.unlines [Text]
    lns

    codeBlockStart :: Monad m => ParserT Text st m Char
    codeBlockStart :: ParserT Text st m Char
    codeBlockStart = [Char] -> ParsecT Text st m [Char]
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m [Char]
    string "::" ParsecT Text st m [Char]
    -> ParserT Text st m Char -> ParserT Text st m Char
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> ParserT Text st m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    blankline ParserT Text st m Char
    -> ParserT Text st m Char -> ParserT Text st m Char
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> ParserT Text st m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    blankline

    codeBlock :: Monad m => ParserT Text ParserState m Blocks
    codeBlock :: ParserT Text ParserState m Blocks
    codeBlock = ParserT Text ParserState m Blocks
    -> ParserT Text ParserState m Blocks
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParserT Text ParserState m Blocks
     -> ParserT Text ParserState m Blocks)
    -> ParserT Text ParserState m Blocks
    -> ParserT Text ParserState m Blocks
    forall a b. (a -> b) -> a -> b
    $ ParserT Text ParserState m Char
    forall (m :: * -> *) st. Monad m => ParserT Text st m Char
    codeBlockStart ParserT Text ParserState m Char
    -> ParserT Text ParserState m Blocks
    -> ParserT Text ParserState m Blocks
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> ParserT Text ParserState m Blocks
    forall (m :: * -> *). Monad m => RSTParser m Blocks
    codeBlockBody

    codeBlockBody :: Monad m => ParserT Text ParserState m Blocks
    codeBlockBody :: ParserT Text ParserState m Blocks
    codeBlockBody = do
      Maybe Text
    lang <- ParserState -> Maybe Text
    stateRstHighlight (ParserState -> Maybe Text)
    -> ParsecT Text ParserState m ParserState
    -> ParsecT Text ParserState m (Maybe Text)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Text ParserState m ParserState
    forall (m :: * -> *) s u. Monad m => ParsecT s u m u
    getState
      ParserT Text ParserState m Blocks
    -> ParserT Text ParserState m Blocks
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParserT Text ParserState m Blocks
     -> ParserT Text ParserState m Blocks)
    -> ParserT Text ParserState m Blocks
    -> ParserT Text ParserState m Blocks
    forall a b. (a -> b) -> a -> b
    $ Attr -> Text -> Blocks
    B.codeBlockWith ("", Maybe Text -> [Text]
    forall a. Maybe a -> [a]
    maybeToList Maybe Text
    lang, []) (Text -> Blocks) -> (Text -> Text) -> Text -> Blocks
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Text
    stripTrailingNewlines (Text -> Blocks)
    -> ParsecT Text ParserState m Text
    -> ParserT Text ParserState m Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$>
                    (ParsecT Text ParserState m Text
    forall st (m :: * -> *).
    (HasReaderOptions st, Monad m) =>
    ParserT Text st m Text
    indentedBlock ParsecT Text ParserState m Text
    -> ParsecT Text ParserState m Text
    -> ParsecT Text ParserState m Text
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT Text ParserState m Text
    forall (m :: * -> *) st. Monad m => ParserT Text st m Text
    quotedBlock)

    lhsCodeBlock :: Monad m => RSTParser m Blocks
    lhsCodeBlock :: RSTParser m Blocks
    lhsCodeBlock = RSTParser m Blocks -> RSTParser m Blocks
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m Blocks -> RSTParser m Blocks)
    -> RSTParser m Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ do
      ParsecT Text ParserState m SourcePos
    forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
    getPosition ParsecT Text ParserState m SourcePos
    -> (SourcePos -> ParsecT Text ParserState m ())
    -> ParsecT Text ParserState m ()
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= Bool -> ParsecT Text ParserState m ()
    forall (f :: * -> *). Alternative f => Bool -> f ()
    guard (Bool -> ParsecT Text ParserState m ())
    -> (SourcePos -> Bool)
    -> SourcePos
    -> ParsecT Text ParserState m ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Int -> Int -> Bool
    forall a. Eq a => a -> a -> Bool
    ==1) (Int -> Bool) -> (SourcePos -> Int) -> SourcePos -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . SourcePos -> Int
    sourceColumn
      Extension -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) a st.
    (Stream s m a, HasReaderOptions st) =>
    Extension -> ParserT s st m ()
    guardEnabled Extension
    Ext_literate_haskell
      ParsecT Text ParserState m Char -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m ()
    optional ParsecT Text ParserState m Char
    forall (m :: * -> *) st. Monad m => ParserT Text st m Char
    codeBlockStart
      [Text]
    lns <- ParserT Text ParserState m [Text]
    forall (m :: * -> *) st. Monad m => ParserT Text st m [Text]
    latexCodeBlock ParserT Text ParserState m [Text]
    -> ParserT Text ParserState m [Text]
    -> ParserT Text ParserState m [Text]
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParserT Text ParserState m [Text]
    forall (m :: * -> *) st. Monad m => ParserT Text st m [Text]
    birdCodeBlock
      ParserT Text ParserState m Text
    forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Text
    blanklines
      Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> RSTParser m Blocks) -> Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ Attr -> Text -> Blocks
    B.codeBlockWith ("", ["haskell","literate"], [])
             (Text -> Blocks) -> Text -> Blocks
    forall a b. (a -> b) -> a -> b
    $ Text -> [Text] -> Text
    T.intercalate "\n" [Text]
    lns

    latexCodeBlock :: Monad m => ParserT Text st m [Text]
    latexCodeBlock :: ParserT Text st m [Text]
    latexCodeBlock = ParserT Text st m [Text] -> ParserT Text st m [Text]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParserT Text st m [Text] -> ParserT Text st m [Text])
    -> ParserT Text st m [Text] -> ParserT Text st m [Text]
    forall a b. (a -> b) -> a -> b
    $ do
      ParsecT Text st m Char -> ParsecT Text st m Char
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try ([Char] -> ParsecT Text st m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m Char
    latexBlockLine "\\begin{code}")
      ParserT Text st m Text
    -> ParsecT Text st m Char -> ParserT Text st m [Text]
    forall end s (m :: * -> *) t st a.
    (Show end, Stream s m t) =>
    ParserT s st m a -> ParserT s st m end -> ParserT s st m [a]
    many1Till ParserT Text st m Text
    forall (m :: * -> *) st. Monad m => ParserT Text st m Text
    anyLine (ParsecT Text st m Char -> ParsecT Text st m Char
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Text st m Char -> ParsecT Text st m Char)
    -> ParsecT Text st m Char -> ParsecT Text st m Char
    forall a b. (a -> b) -> a -> b
    $ [Char] -> ParsecT Text st m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m Char
    latexBlockLine "\\end{code}")
     where
      latexBlockLine :: [Char] -> ParsecT s u m Char
    latexBlockLine s :: [Char]
    s = ParsecT s u m Char -> ParsecT s u m ()
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
    skipMany ParsecT s u m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    spaceChar ParsecT s u m () -> ParsecT s u m [Char] -> ParsecT s u m [Char]
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> [Char] -> ParsecT s u m [Char]
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m [Char]
    string [Char]
    s ParsecT s u m [Char] -> ParsecT s u m Char -> ParsecT s u m Char
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> ParsecT s u m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    blankline

    birdCodeBlock :: Monad m => ParserT Text st m [Text]
    birdCodeBlock :: ParserT Text st m [Text]
    birdCodeBlock = [Text] -> [Text]
    filterSpace ([Text] -> [Text])
    -> ParserT Text st m [Text] -> ParserT Text st m [Text]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Text st m Text -> ParserT Text st m [Text]
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m [a]
    many1 ParsecT Text st m Text
    forall (m :: * -> *) st. Monad m => ParserT Text st m Text
    birdTrackLine
      where filterSpace :: [Text] -> [Text]
    filterSpace lns :: [Text]
    lns =
                -- if (as is normal) there is always a space after >, drop it
                if (Text -> Bool) -> [Text] -> Bool
    forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
    all (\ln :: Text
    ln -> Text -> Bool
    T.null Text
    ln Bool -> Bool -> Bool
    || Int -> Text -> Text
    T.take 1 Text
    ln Text -> Text -> Bool
    forall a. Eq a => a -> a -> Bool
    == " ") [Text]
    lns
                   then (Text -> Text) -> [Text] -> [Text]
    forall a b. (a -> b) -> [a] -> [b]
    map (Int -> Text -> Text
    T.drop 1) [Text]
    lns
                   else [Text]
    lns

    birdTrackLine :: Monad m => ParserT Text st m Text
    birdTrackLine :: ParserT Text st m Text
    birdTrackLine = Char -> ParsecT Text st m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '>' ParsecT Text st m Char
    -> ParserT Text st m Text -> ParserT Text st m Text
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> ParserT Text st m Text
    forall (m :: * -> *) st. Monad m => ParserT Text st m Text
    anyLine

    --
    -- block quotes
    --

    blockQuote :: PandocMonad m => RSTParser m Blocks
    blockQuote :: RSTParser m Blocks
    blockQuote = do
      Text
    raw <- ParserT Text ParserState m Text
    forall st (m :: * -> *).
    (HasReaderOptions st, Monad m) =>
    ParserT Text st m Text
    indentedBlock
      -- parse the extracted block, which may contain various block elements:
      Blocks
    contents <- RSTParser m Blocks -> Text -> RSTParser m Blocks
    forall s (m :: * -> *) u a.
    (Stream s m Char, IsString s, HasLastStrPosition u) =>
    ParserT s u m a -> Text -> ParserT s u m a
    parseFromString' RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    parseBlocks (Text -> RSTParser m Blocks) -> Text -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ Text
    raw Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> "\n\n"
      Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> RSTParser m Blocks) -> Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ Blocks -> Blocks
    B.blockQuote Blocks
    contents

    {-
    Unsupported options for include:
    tab-width
    encoding
    -}

    includeDirective :: PandocMonad m
                     => Text -> [(Text, Text)] -> Text
                     -> RSTParser m Blocks
    includeDirective :: Text -> NoteTable -> Text -> RSTParser m Blocks
    includeDirective top :: Text
    top fields :: NoteTable
    fields body :: Text
    body = do
      let f :: Text
    f = Text -> Text
    trim Text
    top
      Bool -> ParsecT Text ParserState m ()
    forall (f :: * -> *). Alternative f => Bool -> f ()
    guard (Bool -> ParsecT Text ParserState m ())
    -> Bool -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ Bool -> Bool
    not (Text -> Bool
    T.null Text
    f)
      Bool -> ParsecT Text ParserState m ()
    forall (f :: * -> *). Alternative f => Bool -> f ()
    guard (Bool -> ParsecT Text ParserState m ())
    -> Bool -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ Text -> Bool
    T.null (Text -> Text
    trim Text
    body)
      -- options
      let (Maybe Int
    startLine :: Maybe Int) = Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "start-line" NoteTable
    fields Maybe Text -> (Text -> Maybe Int) -> Maybe Int
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= Text -> Maybe Int
    forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
    safeRead
      let (Maybe Int
    endLine :: Maybe Int) = Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "end-line" NoteTable
    fields Maybe Text -> (Text -> Maybe Int) -> Maybe Int
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= Text -> Maybe Int
    forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
    safeRead
      SourcePos
    oldPos <- ParsecT Text ParserState m SourcePos
    forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
    getPosition
      Text
    oldInput <- ParsecT Text ParserState m Text
    forall (m :: * -> *) s u. Monad m => ParsecT s u m s
    getInput
      [Text]
    containers <- ParserState -> [Text]
    stateContainers (ParserState -> [Text])
    -> ParsecT Text ParserState m ParserState
    -> ParsecT Text ParserState m [Text]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Text ParserState m ParserState
    forall (m :: * -> *) s u. Monad m => ParsecT s u m u
    getState
      Bool
    -> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
    forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
    when (Text
    f Text -> [Text] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `elem` [Text]
    containers) (ParsecT Text ParserState m () -> ParsecT Text ParserState m ())
    -> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $
        PandocError -> ParsecT Text ParserState m ()
    forall e (m :: * -> *) a. MonadError e m => e -> m a
    throwError (PandocError -> ParsecT Text ParserState m ())
    -> PandocError -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ Text -> PandocError
    PandocParseError (Text -> PandocError) -> Text -> PandocError
    forall a b. (a -> b) -> a -> b
    $ "Include file loop at " Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> SourcePos -> Text
    forall a. Show a => a -> Text
    tshow SourcePos
    oldPos
      (ParserState -> ParserState) -> ParsecT Text ParserState m ()
    forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
    updateState ((ParserState -> ParserState) -> ParsecT Text ParserState m ())
    -> (ParserState -> ParserState) -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ \s :: ParserState
    s -> ParserState
    s{ stateContainers :: [Text]
    stateContainers = Text
    f Text -> [Text] -> [Text]
    forall a. a -> [a] -> [a]
    : ParserState -> [Text]
    stateContainers ParserState
    s }
      Maybe Text
    mbContents <- [[Char]] -> [Char] -> ParsecT Text ParserState m (Maybe Text)
    forall (m :: * -> *).
    PandocMonad m =>
    [[Char]] -> [Char] -> m (Maybe Text)
    readFileFromDirs ["."] ([Char] -> ParsecT Text ParserState m (Maybe Text))
    -> [Char] -> ParsecT Text ParserState m (Maybe Text)
    forall a b. (a -> b) -> a -> b
    $ Text -> [Char]
    T.unpack Text
    f
      [Text]
    contentLines <- case Maybe Text
    mbContents of
                           Just s :: Text
    s -> [Text] -> ParsecT Text ParserState m [Text]
    forall (m :: * -> *) a. Monad m => a -> m a
    return ([Text] -> ParsecT Text ParserState m [Text])
    -> [Text] -> ParsecT Text ParserState m [Text]
    forall a b. (a -> b) -> a -> b
    $ Text -> [Text]
    T.lines Text
    s
                           Nothing -> do
                             LogMessage -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) a st.
    (Stream s m a, HasLogMessages st) =>
    LogMessage -> ParserT s st m ()
    logMessage (LogMessage -> ParsecT Text ParserState m ())
    -> LogMessage -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ Text -> SourcePos -> LogMessage
    CouldNotLoadIncludeFile Text
    f SourcePos
    oldPos
                             [Text] -> ParsecT Text ParserState m [Text]
    forall (m :: * -> *) a. Monad m => a -> m a
    return []
      let numLines :: Int
    numLines = [Text] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length [Text]
    contentLines
      let startLine' :: Int
    startLine' = case Maybe Int
    startLine of
                            Nothing            -> 1
                            Just x :: Int
    x | Int
    x Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    >= 0    -> Int
    x
                                   | Bool
    otherwise -> Int
    numLines Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    x -- negative from end
      let endLine' :: Int
    endLine' = case Maybe Int
    endLine of
                            Nothing            -> Int
    numLines Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + 1
                            Just x :: Int
    x | Int
    x Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    >= 0    -> Int
    x
                                   | Bool
    otherwise -> Int
    numLines Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    x -- negative from end
      let contentLines' :: [Text]
    contentLines' =   Int -> [Text] -> [Text]
    forall a. Int -> [a] -> [a]
    drop (Int
    startLine' Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - 1)
                          ([Text] -> [Text]) -> [Text] -> [Text]
    forall a b. (a -> b) -> a -> b
    $ Int -> [Text] -> [Text]
    forall a. Int -> [a] -> [a]
    take (Int
    endLine' Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - 1) [Text]
    contentLines
      let contentLines'' :: [Text]
    contentLines'' = (case Text -> Text
    trim (Text -> Text) -> Maybe Text -> Maybe Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "end-before" NoteTable
    fields of
                                 Just patt :: Text
    patt -> (Text -> Bool) -> [Text] -> [Text]
    forall a. (a -> Bool) -> [a] -> [a]
    takeWhile (Bool -> Bool
    not (Bool -> Bool) -> (Text -> Bool) -> Text -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Text
    patt Text -> Text -> Bool
    `T.isInfixOf`))
                                 Nothing   -> [Text] -> [Text]
    forall a. a -> a
    id) ([Text] -> [Text]) -> ([Text] -> [Text]) -> [Text] -> [Text]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                           (case Text -> Text
    trim (Text -> Text) -> Maybe Text -> Maybe Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "start-after" NoteTable
    fields of
                                 Just patt :: Text
    patt -> Int -> [Text] -> [Text]
    forall a. Int -> [a] -> [a]
    drop 1 ([Text] -> [Text]) -> ([Text] -> [Text]) -> [Text] -> [Text]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
                                                (Text -> Bool) -> [Text] -> [Text]
    forall a. (a -> Bool) -> [a] -> [a]
    dropWhile (Bool -> Bool
    not (Bool -> Bool) -> (Text -> Bool) -> Text -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Text
    patt Text -> Text -> Bool
    `T.isInfixOf`))
                                 Nothing   -> [Text] -> [Text]
    forall a. a -> a
    id) ([Text] -> [Text]) -> [Text] -> [Text]
    forall a b. (a -> b) -> a -> b
    $ [Text]
    contentLines'
      let contents' :: Text
    contents' = [Text] -> Text
    T.unlines [Text]
    contentLines'' Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> "\n"
      case Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "code" NoteTable
    fields of
           Just lang :: Text
    lang -> do
             let numberLines :: Maybe Text
    numberLines = Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "number-lines" NoteTable
    fields
             let classes :: [Text]
    classes =  [Text] -> (Text -> [Text]) -> Maybe Text -> [Text]
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe [] Text -> [Text]
    T.words (Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "class" NoteTable
    fields)
             let ident :: Text
    ident = Text -> (Text -> Text) -> Maybe Text -> Text
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe "" Text -> Text
    trimr (Maybe Text -> Text) -> Maybe Text -> Text
    forall a b. (a -> b) -> a -> b
    $ Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "name" NoteTable
    fields
             Text
    -> [Text]
    -> Maybe Text
    -> Text
    -> Text
    -> Bool
    -> RSTParser m Blocks
    forall (m :: * -> *).
    Text
    -> [Text]
    -> Maybe Text
    -> Text
    -> Text
    -> Bool
    -> RSTParser m Blocks
    codeblock Text
    ident [Text]
    classes Maybe Text
    numberLines (Text -> Text
    trimr Text
    lang) Text
    contents' Bool
    False
           Nothing   -> case Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "literal" NoteTable
    fields of
                             Just _  -> Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> RSTParser m Blocks) -> Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ Text -> Text -> Blocks
    B.rawBlock "rst" Text
    contents'
                             Nothing -> do
                               SourcePos -> ParsecT Text ParserState m ()
    forall (m :: * -> *) s u. Monad m => SourcePos -> ParsecT s u m ()
    setPosition (SourcePos -> ParsecT Text ParserState m ())
    -> SourcePos -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ [Char] -> Int -> Int -> SourcePos
    newPos (Text -> [Char]
    T.unpack Text
    f) 1 1
                               Text -> ParsecT Text ParserState m ()
    forall (m :: * -> *) s u. Monad m => s -> ParsecT s u m ()
    setInput Text
    contents'
                               Blocks
    bs <- ParsecT Text ParserState m Text -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m ()
    optional ParsecT Text ParserState m Text
    forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Text
    blanklines ParsecT Text ParserState m ()
    -> RSTParser m Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >>
                                      ([Blocks] -> Blocks
    forall a. Monoid a => [a] -> a
    mconcat ([Blocks] -> Blocks)
    -> ParsecT Text ParserState m [Blocks] -> RSTParser m Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> RSTParser m Blocks -> ParsecT Text ParserState m [Blocks]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    block)
                               Text -> ParsecT Text ParserState m ()
    forall (m :: * -> *) s u. Monad m => s -> ParsecT s u m ()
    setInput Text
    oldInput
                               SourcePos -> ParsecT Text ParserState m ()
    forall (m :: * -> *) s u. Monad m => SourcePos -> ParsecT s u m ()
    setPosition SourcePos
    oldPos
                               (ParserState -> ParserState) -> ParsecT Text ParserState m ()
    forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
    updateState ((ParserState -> ParserState) -> ParsecT Text ParserState m ())
    -> (ParserState -> ParserState) -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ \s :: ParserState
    s -> ParserState
    s{ stateContainers :: [Text]
    stateContainers =
                                             [Text] -> [Text]
    forall a. [a] -> [a]
    tail ([Text] -> [Text]) -> [Text] -> [Text]
    forall a b. (a -> b) -> a -> b
    $ ParserState -> [Text]
    stateContainers ParserState
    s }
                               Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return Blocks
    bs

    --
    -- list blocks
    --

    list :: PandocMonad m => RSTParser m Blocks
    list :: RSTParser m Blocks
    list = [RSTParser m Blocks] -> RSTParser m Blocks
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    [ParsecT s u m a] -> ParsecT s u m a
    choice [ RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    bulletList, RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    orderedList, RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    definitionList ] RSTParser m Blocks -> [Char] -> RSTParser m Blocks
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> [Char] -> ParsecT s u m a
    <?> "list"

    definitionListItem :: PandocMonad m => RSTParser m (Inlines, [Blocks])
    definitionListItem :: RSTParser m (Many Inline, [Blocks])
    definitionListItem = RSTParser m (Many Inline, [Blocks])
    -> RSTParser m (Many Inline, [Blocks])
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m (Many Inline, [Blocks])
     -> RSTParser m (Many Inline, [Blocks]))
    -> RSTParser m (Many Inline, [Blocks])
    -> RSTParser m (Many Inline, [Blocks])
    forall a b. (a -> b) -> a -> b
    $ do
      -- avoid capturing a directive or comment
      ParsecT Text ParserState m Char -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) t a u.
    (Stream s m t, Show a) =>
    ParsecT s u m a -> ParsecT s u m ()
    notFollowedBy (ParsecT Text ParserState m Char -> ParsecT Text ParserState m Char
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Text ParserState m Char
     -> ParsecT Text ParserState m Char)
    -> ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m Char
    forall a b. (a -> b) -> a -> b
    $ Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '.' ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m Char
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '.')
      Many Inline
    term <- Many Inline -> Many Inline
    trimInlines (Many Inline -> Many Inline)
    -> ([Many Inline] -> Many Inline) -> [Many Inline] -> Many Inline
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Many Inline] -> Many Inline
    forall a. Monoid a => [a] -> a
    mconcat ([Many Inline] -> Many Inline)
    -> ParsecT Text ParserState m [Many Inline]
    -> ParsecT Text ParserState m (Many Inline)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Text ParserState m (Many Inline)
    -> ParsecT Text ParserState m (Many Inline)
    -> ParsecT Text ParserState m [Many Inline]
    forall end s (m :: * -> *) t st a.
    (Show end, Stream s m t) =>
    ParserT s st m a -> ParserT s st m end -> ParserT s st m [a]
    many1Till ParsecT Text ParserState m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    inline ParsecT Text ParserState m (Many Inline)
    forall (m :: * -> *). Monad m => RSTParser m (Many Inline)
    endline
      Text
    raw <- ParserT Text ParserState m Text
    forall st (m :: * -> *).
    (HasReaderOptions st, Monad m) =>
    ParserT Text st m Text
    indentedBlock
      -- parse the extracted block, which may contain various block elements:
      Blocks
    contents <- ParserT Text ParserState m Blocks
    -> Text -> ParserT Text ParserState m Blocks
    forall s (m :: * -> *) u a.
    (Stream s m Char, IsString s, HasLastStrPosition u) =>
    ParserT s u m a -> Text -> ParserT s u m a
    parseFromString' ParserT Text ParserState m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    parseBlocks (Text -> ParserT Text ParserState m Blocks)
    -> Text -> ParserT Text ParserState m Blocks
    forall a b. (a -> b) -> a -> b
    $ Text
    raw Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> "\n"
      (Many Inline, [Blocks]) -> RSTParser m (Many Inline, [Blocks])
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline
    term, [Blocks
    contents])

    definitionList :: PandocMonad m => RSTParser m Blocks
    definitionList :: RSTParser m Blocks
    definitionList = [(Many Inline, [Blocks])] -> Blocks
    B.definitionList ([(Many Inline, [Blocks])] -> Blocks)
    -> ParsecT Text ParserState m [(Many Inline, [Blocks])]
    -> RSTParser m Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Text ParserState m (Many Inline, [Blocks])
    -> ParsecT Text ParserState m [(Many Inline, [Blocks])]
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m [a]
    many1 ParsecT Text ParserState m (Many Inline, [Blocks])
    forall (m :: * -> *).
    PandocMonad m =>
    RSTParser m (Many Inline, [Blocks])
    definitionListItem

    -- parses bullet list start and returns its length (inc. following whitespace)
    bulletListStart :: Monad m => ParserT Text st m Int
    bulletListStart :: ParserT Text st m Int
    bulletListStart = ParserT Text st m Int -> ParserT Text st m Int
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParserT Text st m Int -> ParserT Text st m Int)
    -> ParserT Text st m Int -> ParserT Text st m Int
    forall a b. (a -> b) -> a -> b
    $ do
      ParserT Text st m Blocks -> ParserT Text st m ()
    forall b s (m :: * -> *) a st.
    (Show b, Stream s m a) =>
    ParserT s st m b -> ParserT s st m ()
    notFollowedBy' ParserT Text st m Blocks
    forall (m :: * -> *) st. Monad m => ParserT Text st m Blocks
    hrule  -- because hrules start out just like lists
      Char
    marker <- [Char] -> ParsecT Text st m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m Char
    oneOf [Char]
    bulletListMarkers
      [Char]
    white <- ParsecT Text st m Char -> ParsecT Text st m [Char]
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m [a]
    many1 ParsecT Text st m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    spaceChar ParsecT Text st m [Char]
    -> ParsecT Text st m [Char] -> ParsecT Text st m [Char]
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> "" [Char] -> ParsecT Text st m Char -> ParsecT Text st m [Char]
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ ParsecT Text st m Char -> ParsecT Text st m Char
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m a
    lookAhead (Char -> ParsecT Text st m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '\n')
      Int -> ParserT Text st m Int
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Int -> ParserT Text st m Int) -> Int -> ParserT Text st m Int
    forall a b. (a -> b) -> a -> b
    $ [Char] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length (Char
    markerChar -> [Char] -> [Char]
    forall a. a -> [a] -> [a]
    :[Char]
    white)

    -- parses ordered list start and returns its length (inc following whitespace)
    orderedListStart :: Monad m => ListNumberStyle
                     -> ListNumberDelim
                     -> RSTParser m Int
    orderedListStart :: ListNumberStyle -> ListNumberDelim -> RSTParser m Int
    orderedListStart style :: ListNumberStyle
    style delim :: ListNumberDelim
    delim = RSTParser m Int -> RSTParser m Int
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m Int -> RSTParser m Int)
    -> RSTParser m Int -> RSTParser m Int
    forall a b. (a -> b) -> a -> b
    $ do
      (_, markerLen :: Int
    markerLen) <- RSTParser m Int -> ParserT Text ParserState m (Int, Int)
    forall s (m :: * -> *) st a.
    Stream s m Char =>
    ParserT s st m a -> ParserT s st m (a, Int)
    withHorizDisplacement (ListNumberStyle -> ListNumberDelim -> RSTParser m Int
    forall s (m :: * -> *).
    Stream s m Char =>
    ListNumberStyle -> ListNumberDelim -> ParserT s ParserState m Int
    orderedListMarker ListNumberStyle
    style ListNumberDelim
    delim)
      [Char]
    white <- ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m [Char]
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m [a]
    many1 ParsecT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    spaceChar ParsecT Text ParserState m [Char]
    -> ParsecT Text ParserState m [Char]
    -> ParsecT Text ParserState m [Char]
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> "" [Char]
    -> ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m [Char]
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ ParsecT Text ParserState m Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m a
    lookAhead (Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '\n')
      Int -> RSTParser m Int
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Int -> RSTParser m Int) -> Int -> RSTParser m Int
    forall a b. (a -> b) -> a -> b
    $ Int
    markerLen Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + [Char] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length [Char]
    white

    -- parse a line of a list item
    listLine :: Monad m => Int -> RSTParser m Text
    listLine :: Int -> RSTParser m Text
    listLine markerLength :: Int
    markerLength = RSTParser m Text -> RSTParser m Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m Text -> RSTParser m Text)
    -> RSTParser m Text -> RSTParser m Text
    forall a b. (a -> b) -> a -> b
    $ do
      ParsecT Text ParserState m Char -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) t a u.
    (Stream s m t, Show a) =>
    ParsecT s u m a -> ParsecT s u m ()
    notFollowedBy ParsecT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    blankline
      Int -> RSTParser m Text
    forall s (m :: * -> *) st.
    (Stream s m Char, HasReaderOptions st) =>
    Int -> ParserT s st m Text
    indentWith Int
    markerLength
      RSTParser m Text
    forall (m :: * -> *) st. Monad m => ParserT Text st m Text
    anyLineNewline

    -- parse raw text for one list item, excluding start marker and continuations
    rawListItem :: Monad m => RSTParser m Int
                -> RSTParser m (Int, Text)
    rawListItem :: RSTParser m Int -> RSTParser m (Int, Text)
    rawListItem start :: RSTParser m Int
    start = RSTParser m (Int, Text) -> RSTParser m (Int, Text)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m (Int, Text) -> RSTParser m (Int, Text))
    -> RSTParser m (Int, Text) -> RSTParser m (Int, Text)
    forall a b. (a -> b) -> a -> b
    $ do
      Int
    markerLength <- RSTParser m Int
    start
      Text
    firstLine <- ParserT Text ParserState m Text
    forall (m :: * -> *) st. Monad m => ParserT Text st m Text
    anyLineNewline
      [Text]
    restLines <- ParserT Text ParserState m Text
    -> ParsecT Text ParserState m [Text]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many (Int -> ParserT Text ParserState m Text
    forall (m :: * -> *). Monad m => Int -> RSTParser m Text
    listLine Int
    markerLength)
      (Int, Text) -> RSTParser m (Int, Text)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Int
    markerLength, Text
    firstLine Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> [Text] -> Text
    T.concat [Text]
    restLines)

    -- continuation of a list item - indented and separated by blankline or
    -- (in compact lists) endline.
    -- Note: nested lists are parsed as continuations.
    listContinuation :: Monad m => Int -> RSTParser m Text
    listContinuation :: Int -> RSTParser m Text
    listContinuation markerLength :: Int
    markerLength = RSTParser m Text -> RSTParser m Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m Text -> RSTParser m Text)
    -> RSTParser m Text -> RSTParser m Text
    forall a b. (a -> b) -> a -> b
    $ do
      Text
    blanks <- ParserT Text ParserState m Char -> RSTParser m Text
    forall s (m :: * -> *) t st.
    Stream s m t =>
    ParserT s st m Char -> ParserT s st m Text
    many1Char ParserT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    blankline
      [Text]
    result <- RSTParser m Text -> ParsecT Text ParserState m [Text]
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m [a]
    many1 (Int -> RSTParser m Text
    forall (m :: * -> *). Monad m => Int -> RSTParser m Text
    listLine Int
    markerLength)
      Text -> RSTParser m Text
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Text -> RSTParser m Text) -> Text -> RSTParser m Text
    forall a b. (a -> b) -> a -> b
    $ Text
    blanks Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> [Text] -> Text
    T.concat [Text]
    result

    listItem :: PandocMonad m
             => RSTParser m Int
             -> RSTParser m Blocks
    listItem :: RSTParser m Int -> RSTParser m Blocks
    listItem start :: RSTParser m Int
    start = RSTParser m Blocks -> RSTParser m Blocks
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m Blocks -> RSTParser m Blocks)
    -> RSTParser m Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ do
      (markerLength :: Int
    markerLength, first :: Text
    first) <- RSTParser m Int -> RSTParser m (Int, Text)
    forall (m :: * -> *).
    Monad m =>
    RSTParser m Int -> RSTParser m (Int, Text)
    rawListItem RSTParser m Int
    start
      [Text]
    rest <- ParsecT Text ParserState m Text
    -> ParsecT Text ParserState m [Text]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many (Int -> ParsecT Text ParserState m Text
    forall (m :: * -> *). Monad m => Int -> RSTParser m Text
    listContinuation Int
    markerLength)
      ParsecT Text ParserState m Char -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m ()
    skipMany1 ParsecT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    blankline ParsecT Text ParserState m ()
    -> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> () () -> RSTParser m Int -> ParsecT Text ParserState m ()
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ RSTParser m Int -> RSTParser m Int
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m a
    lookAhead RSTParser m Int
    start
      -- parsing with ListItemState forces markers at beginning of lines to
      -- count as list item markers, even if not separated by blank space.
      -- see definition of "endline"
      ParserState
    state <- ParsecT Text ParserState m ParserState
    forall (m :: * -> *) s u. Monad m => ParsecT s u m u
    getState
      let oldContext :: ParserContext
    oldContext = ParserState -> ParserContext
    stateParserContext ParserState
    state
      ParserState -> ParsecT Text ParserState m ()
    forall (m :: * -> *) u s. Monad m => u -> ParsecT s u m ()
    setState (ParserState -> ParsecT Text ParserState m ())
    -> ParserState -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ ParserState
    state {stateParserContext :: ParserContext
    stateParserContext = ParserContext
    ListItemState}
      -- parse the extracted block, which may itself contain block elements
      Blocks
    parsed <- RSTParser m Blocks -> Text -> RSTParser m Blocks
    forall s (m :: * -> *) u a.
    (Stream s m Char, IsString s, HasLastStrPosition u) =>
    ParserT s u m a -> Text -> ParserT s u m a
    parseFromString' RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    parseBlocks (Text -> RSTParser m Blocks) -> Text -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ [Text] -> Text
    T.concat (Text
    firstText -> [Text] -> [Text]
    forall a. a -> [a] -> [a]
    :[Text]
    rest) Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> "\n"
      (ParserState -> ParserState) -> ParsecT Text ParserState m ()
    forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
    updateState (\st :: ParserState
    st -> ParserState
    st {stateParserContext :: ParserContext
    stateParserContext = ParserContext
    oldContext})
      Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> RSTParser m Blocks) -> Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ case Blocks -> [Block]
    forall a. Many a -> [a]
    B.toList Blocks
    parsed of
                    [Para xs :: [Inline]
    xs] ->
                       Block -> Blocks
    forall a. a -> Many a
    B.singleton (Block -> Blocks) -> Block -> Blocks
    forall a b. (a -> b) -> a -> b
    $ [Inline] -> Block
    Plain [Inline]
    xs
                    [Para xs :: [Inline]
    xs, BulletList ys :: [[Block]]
    ys] ->
                       [Block] -> Blocks
    forall a. [a] -> Many a
    B.fromList [[Inline] -> Block
    Plain [Inline]
    xs, [[Block]] -> Block
    BulletList [[Block]]
    ys]
                    [Para xs :: [Inline]
    xs, OrderedList s :: ListAttributes
    s ys :: [[Block]]
    ys] ->
                       [Block] -> Blocks
    forall a. [a] -> Many a
    B.fromList [[Inline] -> Block
    Plain [Inline]
    xs, ListAttributes -> [[Block]] -> Block
    OrderedList ListAttributes
    s [[Block]]
    ys]
                    [Para xs :: [Inline]
    xs, DefinitionList ys :: [([Inline], [[Block]])]
    ys] ->
                       [Block] -> Blocks
    forall a. [a] -> Many a
    B.fromList [[Inline] -> Block
    Plain [Inline]
    xs, [([Inline], [[Block]])] -> Block
    DefinitionList [([Inline], [[Block]])]
    ys]
                    _         -> Blocks
    parsed

    orderedList :: PandocMonad m => RSTParser m Blocks
    orderedList :: RSTParser m Blocks
    orderedList = RSTParser m Blocks -> RSTParser m Blocks
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m Blocks -> RSTParser m Blocks)
    -> RSTParser m Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ do
      (start :: Int
    start, style :: ListNumberStyle
    style, delim :: ListNumberDelim
    delim) <- ParsecT Text ParserState m ListAttributes
    -> ParsecT Text ParserState m ListAttributes
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m a
    lookAhead (ParsecT Text ParserState m ListAttributes
    forall s (m :: * -> *).
    Stream s m Char =>
    ParserT s ParserState m ListAttributes
    anyOrderedListMarker ParsecT Text ParserState m ListAttributes
    -> ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m ListAttributes
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <* ParsecT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    spaceChar)
      [Blocks]
    items <- RSTParser m Blocks -> ParsecT Text ParserState m [Blocks]
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m [a]
    many1 (RSTParser m Int -> RSTParser m Blocks
    forall (m :: * -> *).
    PandocMonad m =>
    RSTParser m Int -> RSTParser m Blocks
    listItem (ListNumberStyle -> ListNumberDelim -> RSTParser m Int
    forall (m :: * -> *).
    Monad m =>
    ListNumberStyle -> ListNumberDelim -> RSTParser m Int
    orderedListStart ListNumberStyle
    style ListNumberDelim
    delim))
      let items' :: [Blocks]
    items' = [Blocks] -> [Blocks]
    compactify [Blocks]
    items
      Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> RSTParser m Blocks) -> Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ ListAttributes -> [Blocks] -> Blocks
    B.orderedListWith (Int
    start, ListNumberStyle
    style, ListNumberDelim
    delim) [Blocks]
    items'

    bulletList :: PandocMonad m => RSTParser m Blocks
    bulletList :: RSTParser m Blocks
    bulletList = [Blocks] -> Blocks
    B.bulletList ([Blocks] -> Blocks)
    -> ([Blocks] -> [Blocks]) -> [Blocks] -> Blocks
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Blocks] -> [Blocks]
    compactify ([Blocks] -> Blocks)
    -> ParsecT Text ParserState m [Blocks] -> RSTParser m Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> RSTParser m Blocks -> ParsecT Text ParserState m [Blocks]
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m [a]
    many1 (RSTParser m Int -> RSTParser m Blocks
    forall (m :: * -> *).
    PandocMonad m =>
    RSTParser m Int -> RSTParser m Blocks
    listItem RSTParser m Int
    forall (m :: * -> *) st. Monad m => ParserT Text st m Int
    bulletListStart)

    --
    -- directive (e.g. comment, container, compound-paragraph)
    --

    comment :: Monad m => RSTParser m Blocks
    comment :: RSTParser m Blocks
    comment = RSTParser m Blocks -> RSTParser m Blocks
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m Blocks -> RSTParser m Blocks)
    -> RSTParser m Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ do
      [Char] -> ParsecT Text ParserState m [Char]
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m [Char]
    string ".."
      ParsecT Text ParserState m Char -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m ()
    skipMany1 ParsecT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    spaceChar ParsecT Text ParserState m ()
    -> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> (() ()
    -> ParsecT Text ParserState m Char -> ParsecT Text ParserState m ()
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ ParsecT Text ParserState m Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m a
    lookAhead ParsecT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    newline)
      -- notFollowedBy' directiveLabel -- comment comes after directive so unnec.
      ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m Text
    -> ParsecT Text ParserState 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 Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    anyChar ParsecT Text ParserState m Text
    forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Text
    blanklines
      ParsecT Text ParserState m Text -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m ()
    optional ParsecT Text ParserState m Text
    forall st (m :: * -> *).
    (HasReaderOptions st, Monad m) =>
    ParserT Text st m Text
    indentedBlock
      Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return Blocks
    forall a. Monoid a => a
    mempty

    directiveLabel :: Monad m => RSTParser m Text
    directiveLabel :: RSTParser m Text
    directiveLabel = Text -> Text
    T.toLower
      (Text -> Text) -> RSTParser m Text -> RSTParser m Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParserT Text ParserState m Char
    -> ParserT Text ParserState m [Char] -> RSTParser m Text
    forall end s (m :: * -> *) t st.
    (Show end, Stream s m t) =>
    ParserT s st m Char -> ParserT s st m end -> ParserT s st m Text
    many1TillChar (ParserT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    letter ParserT Text ParserState m Char
    -> ParserT Text ParserState m Char
    -> ParserT Text ParserState m Char
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> Char -> ParserT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '-') (ParserT Text ParserState m [Char]
    -> ParserT Text ParserState m [Char]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParserT Text ParserState m [Char]
     -> ParserT Text ParserState m [Char])
    -> ParserT Text ParserState m [Char]
    -> ParserT Text ParserState m [Char]
    forall a b. (a -> b) -> a -> b
    $ [Char] -> ParserT Text ParserState m [Char]
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m [Char]
    string "::")

    directive :: PandocMonad m => RSTParser m Blocks
    directive :: RSTParser m Blocks
    directive = RSTParser m Blocks -> RSTParser m Blocks
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m Blocks -> RSTParser m Blocks)
    -> RSTParser m Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ do
      [Char] -> ParsecT Text ParserState m [Char]
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m [Char]
    string ".."
      RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    directive'

    directive' :: PandocMonad m => RSTParser m Blocks
    directive' :: RSTParser m Blocks
    directive' = do
      ParsecT Text ParserState m Char -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m ()
    skipMany1 ParsecT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    spaceChar
      Text
    label <- RSTParser m Text
    forall (m :: * -> *). Monad m => RSTParser m Text
    directiveLabel
      ParsecT Text ParserState m Char -> ParsecT Text ParserState m ()
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
    skipMany ParsecT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    spaceChar
      Text
    top <- ParsecT Text ParserState m Char -> RSTParser m Text
    forall s (m :: * -> *) t st.
    Stream s m t =>
    ParserT s st m Char -> ParserT s st m Text
    manyChar (ParsecT Text ParserState m Char -> RSTParser m Text)
    -> ParsecT Text ParserState m Char -> RSTParser m Text
    forall a b. (a -> b) -> a -> b
    $ (Char -> Bool) -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    (Char -> Bool) -> ParsecT s u m Char
    satisfy (Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    /='\n')
                 ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m Char
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT Text ParserState m Char -> ParsecT Text ParserState m Char
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '\n' ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m () -> ParsecT Text ParserState m Char
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <*
                          ParserT Text ParserState m (Text, Text)
    -> ParsecT Text ParserState m ()
    forall b s (m :: * -> *) a st.
    (Show b, Stream s m a) =>
    ParserT s st m b -> ParserT s st m ()
    notFollowedBy' (Int -> ParserT Text ParserState m (Text, Text)
    forall (m :: * -> *). Monad m => Int -> RSTParser m (Text, Text)
    rawFieldListItem 1) ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m [Char]
    -> ParsecT Text ParserState m Char
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <*
                          ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m [Char]
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m [a]
    many1 (Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char ' ') ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m () -> ParsecT Text ParserState m Char
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <*
                          ParsecT Text ParserState m Char -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) t a u.
    (Stream s m t, Show a) =>
    ParsecT s u m a -> ParsecT s u m ()
    notFollowedBy ParsecT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    blankline)
      ParsecT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    newline
      NoteTable
    fields <- do
        Int
    fieldIndent <- [Char] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length ([Char] -> Int)
    -> ParsecT Text ParserState m [Char]
    -> ParsecT Text ParserState m Int
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Text ParserState m [Char]
    -> ParsecT Text ParserState m [Char]
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m a
    lookAhead (ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m [Char]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many (Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char ' '))
        if Int
    fieldIndent Int -> Int -> Bool
    forall a. Eq a => a -> a -> Bool
    == 0
           then NoteTable -> ParsecT Text ParserState m NoteTable
    forall (m :: * -> *) a. Monad m => a -> m a
    return []
           else ParserT Text ParserState m (Text, Text)
    -> ParsecT Text ParserState m NoteTable
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many (ParserT Text ParserState m (Text, Text)
     -> ParsecT Text ParserState m NoteTable)
    -> ParserT Text ParserState m (Text, Text)
    -> ParsecT Text ParserState m NoteTable
    forall a b. (a -> b) -> a -> b
    $ Int -> ParserT Text ParserState m (Text, Text)
    forall (m :: * -> *). Monad m => Int -> RSTParser m (Text, Text)
    rawFieldListItem Int
    fieldIndent
      Text
    body <- Text -> RSTParser m Text -> RSTParser m Text
    forall s (m :: * -> *) t a u.
    Stream s m t =>
    a -> ParsecT s u m a -> ParsecT s u m a
    option "" (RSTParser m Text -> RSTParser m Text)
    -> RSTParser m Text -> RSTParser m Text
    forall a b. (a -> b) -> a -> b
    $ RSTParser m Text -> RSTParser m Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m Text -> RSTParser m Text)
    -> RSTParser m Text -> RSTParser m Text
    forall a b. (a -> b) -> a -> b
    $ RSTParser m Text
    forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Text
    blanklines RSTParser m Text -> RSTParser m Text -> RSTParser m Text
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> RSTParser m Text
    forall st (m :: * -> *).
    (HasReaderOptions st, Monad m) =>
    ParserT Text st m Text
    indentedBlock
      RSTParser m Text -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m ()
    optional RSTParser m Text
    forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Text
    blanklines
      let body' :: Text
    body' = Text
    body Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> "\n\n"
          name :: Text
    name = Text -> Text
    trim (Text -> Text) -> Text -> Text
    forall a b. (a -> b) -> a -> b
    $ Text -> Maybe Text -> Text
    forall a. a -> Maybe a -> a
    fromMaybe "" (Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "name" NoteTable
    fields)
          classes :: [Text]
    classes = Text -> [Text]
    T.words (Text -> [Text]) -> Text -> [Text]
    forall a b. (a -> b) -> a -> b
    $ Text -> (Text -> Text) -> Maybe Text -> Text
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe "" Text -> Text
    trim (Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "class" NoteTable
    fields)
          keyvals :: NoteTable
    keyvals = [(Text
    k, Text -> Text
    trim Text
    v) | (k :: Text
    k, v :: Text
    v) <- NoteTable
    fields, Text
    k Text -> Text -> Bool
    forall a. Eq a => a -> a -> Bool
    /= "name", Text
    k Text -> Text -> Bool
    forall a. Eq a => a -> a -> Bool
    /= "class"]
          imgAttr :: Text -> (Text, [Text], [(a, Text)])
    imgAttr cl :: Text
    cl = (Text
    name, [Text]
    classes [Text] -> [Text] -> [Text]
    forall a. [a] -> [a] -> [a]
    ++ [Text]
    alignClasses, [(a, Text)]
    widthAttr [(a, Text)] -> [(a, Text)] -> [(a, Text)]
    forall a. [a] -> [a] -> [a]
    ++ [(a, Text)]
    heightAttr)
            where
              alignClasses :: [Text]
    alignClasses = Text -> [Text]
    T.words (Text -> [Text]) -> Text -> [Text]
    forall a b. (a -> b) -> a -> b
    $ Text -> (Text -> Text) -> Maybe Text -> Text
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe "" Text -> Text
    trim (Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup Text
    cl NoteTable
    fields) Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <>
                              Text -> (Text -> Text) -> Maybe Text -> Text
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe "" (\x :: Text
    x -> "align-" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text -> Text
    trim Text
    x)
                              (Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "align" NoteTable
    fields)
              scale :: Double
    scale = case Text -> Text
    trim (Text -> Text) -> Maybe Text -> Maybe Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "scale" NoteTable
    fields of
                        Just v :: Text
    v -> case Text -> Maybe (Text, Char)
    T.unsnoc Text
    v of
                          Just (vv :: Text
    vv, '%') -> case Text -> Maybe Double
    forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
    safeRead Text
    vv of
                                              Just (Double
    percent :: Double)
                                                -> Double
    percent Double -> Double -> Double
    forall a. Fractional a => a -> a -> a
    / 100.0
                                              Nothing -> 1.0
                          _ -> case Text -> Maybe Double
    forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
    safeRead Text
    v of
                                 Just (Double
    s :: Double) -> Double
    s
                                 Nothing            -> 1.0
                        Nothing -> 1.0
              widthAttr :: [(a, Text)]
    widthAttr = [(a, Text)]
    -> (Dimension -> [(a, Text)]) -> Maybe Dimension -> [(a, Text)]
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe [] (\x :: Dimension
    x -> [("width",
                                            Dimension -> Text
    forall a. Show a => a -> Text
    tshow (Dimension -> Text) -> Dimension -> Text
    forall a b. (a -> b) -> a -> b
    $ Double -> Dimension -> Dimension
    scaleDimension Double
    scale Dimension
    x)])
                            (Maybe Dimension -> [(a, Text)]) -> Maybe Dimension -> [(a, Text)]
    forall a b. (a -> b) -> a -> b
    $ Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "width" NoteTable
    fields Maybe Text -> (Text -> Maybe Dimension) -> Maybe Dimension
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>=
                              (Text -> Maybe Dimension
    lengthToDim (Text -> Maybe Dimension)
    -> (Text -> Text) -> Text -> Maybe Dimension
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Char -> Bool) -> Text -> Text
    T.filter (Bool -> Bool
    not (Bool -> Bool) -> (Char -> Bool) -> Char -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Char -> Bool
    isSpace))
              heightAttr :: [(a, Text)]
    heightAttr = [(a, Text)]
    -> (Dimension -> [(a, Text)]) -> Maybe Dimension -> [(a, Text)]
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe [] (\x :: Dimension
    x -> [("height",
                                             Dimension -> Text
    forall a. Show a => a -> Text
    tshow (Dimension -> Text) -> Dimension -> Text
    forall a b. (a -> b) -> a -> b
    $ Double -> Dimension -> Dimension
    scaleDimension Double
    scale Dimension
    x)])
                            (Maybe Dimension -> [(a, Text)]) -> Maybe Dimension -> [(a, Text)]
    forall a b. (a -> b) -> a -> b
    $ Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "height" NoteTable
    fields Maybe Text -> (Text -> Maybe Dimension) -> Maybe Dimension
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>=
                              (Text -> Maybe Dimension
    lengthToDim (Text -> Maybe Dimension)
    -> (Text -> Text) -> Text -> Maybe Dimension
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Char -> Bool) -> Text -> Text
    T.filter (Bool -> Bool
    not (Bool -> Bool) -> (Char -> Bool) -> Char -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Char -> Bool
    isSpace))
      case Text
    label of
            "include" -> Text -> NoteTable -> Text -> RSTParser m Blocks
    forall (m :: * -> *).
    PandocMonad m =>
    Text -> NoteTable -> Text -> RSTParser m Blocks
    includeDirective Text
    top NoteTable
    fields Text
    body'
            "table" -> Text -> NoteTable -> Text -> RSTParser m Blocks
    forall (m :: * -> *).
    PandocMonad m =>
    Text -> NoteTable -> Text -> RSTParser m Blocks
    tableDirective Text
    top NoteTable
    fields Text
    body'
            "list-table" -> Text -> NoteTable -> Text -> RSTParser m Blocks
    forall (m :: * -> *).
    PandocMonad m =>
    Text -> NoteTable -> Text -> RSTParser m Blocks
    listTableDirective Text
    top NoteTable
    fields Text
    body'
            "csv-table" -> Text -> NoteTable -> Text -> RSTParser m Blocks
    forall (m :: * -> *).
    PandocMonad m =>
    Text -> NoteTable -> Text -> RSTParser m Blocks
    csvTableDirective Text
    top NoteTable
    fields Text
    body'
            "line-block" -> Text -> RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => Text -> RSTParser m Blocks
    lineBlockDirective Text
    body'
            "raw" -> Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> RSTParser m Blocks) -> Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ Text -> Text -> Blocks
    B.rawBlock (Text -> Text
    trim Text
    top) (Text -> Text
    stripTrailingNewlines Text
    body)
            "role" -> Text -> NoteTable -> RSTParser m Blocks
    forall (m :: * -> *).
    PandocMonad m =>
    Text -> NoteTable -> RSTParser m Blocks
    addNewRole Text
    top (NoteTable -> RSTParser m Blocks)
    -> NoteTable -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ ((Text, Text) -> (Text, Text)) -> NoteTable -> NoteTable
    forall a b. (a -> b) -> [a] -> [b]
    map ((Text -> Text) -> (Text, Text) -> (Text, Text)
    forall (a :: * -> * -> *) b c d.
    Arrow a =>
    a b c -> a (d, b) (d, c)
    second Text -> Text
    trim) NoteTable
    fields
            "container" -> Attr -> Blocks -> Blocks
    B.divWith
                             (Text
    name, "container" Text -> [Text] -> [Text]
    forall a. a -> [a] -> [a]
    : Text -> [Text]
    T.words Text
    top [Text] -> [Text] -> [Text]
    forall a. [a] -> [a] -> [a]
    ++ [Text]
    classes, []) (Blocks -> Blocks) -> RSTParser m Blocks -> RSTParser m Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$>
                              RSTParser m Blocks -> Text -> RSTParser m Blocks
    forall s (m :: * -> *) u a.
    (Stream s m Char, IsString s, HasLastStrPosition u) =>
    ParserT s u m a -> Text -> ParserT s u m a
    parseFromString' RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    parseBlocks Text
    body'
            "replace" -> Many Inline -> Blocks
    B.para (Many Inline -> Blocks)
    -> ParsecT Text ParserState m (Many Inline) -> RSTParser m Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$>  -- consumed by substKey
                       Text -> ParsecT Text ParserState m (Many Inline)
    forall (m :: * -> *).
    PandocMonad m =>
    Text -> RSTParser m (Many Inline)
    parseInlineFromText (Text -> Text
    trim Text
    top)
            "unicode" -> Many Inline -> Blocks
    B.para (Many Inline -> Blocks)
    -> ParsecT Text ParserState m (Many Inline) -> RSTParser m Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$>  -- consumed by substKey
                       Text -> ParsecT Text ParserState m (Many Inline)
    forall (m :: * -> *).
    PandocMonad m =>
    Text -> RSTParser m (Many Inline)
    parseInlineFromText (Text -> Text
    trim (Text -> Text) -> Text -> Text
    forall a b. (a -> b) -> a -> b
    $ Text -> Text
    unicodeTransform Text
    top)
            "compound" -> RSTParser m Blocks -> Text -> RSTParser m Blocks
    forall s (m :: * -> *) u a.
    (Stream s m Char, IsString s, HasLastStrPosition u) =>
    ParserT s u m a -> Text -> ParserT s u m a
    parseFromString' RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    parseBlocks Text
    body'
            "pull-quote" -> Blocks -> Blocks
    B.blockQuote (Blocks -> Blocks) -> RSTParser m Blocks -> RSTParser m Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> RSTParser m Blocks -> Text -> RSTParser m Blocks
    forall s (m :: * -> *) u a.
    (Stream s m Char, IsString s, HasLastStrPosition u) =>
    ParserT s u m a -> Text -> ParserT s u m a
    parseFromString' RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    parseBlocks Text
    body'
            "epigraph" -> Blocks -> Blocks
    B.blockQuote (Blocks -> Blocks) -> RSTParser m Blocks -> RSTParser m Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> RSTParser m Blocks -> Text -> RSTParser m Blocks
    forall s (m :: * -> *) u a.
    (Stream s m Char, IsString s, HasLastStrPosition u) =>
    ParserT s u m a -> Text -> ParserT s u m a
    parseFromString' RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    parseBlocks Text
    body'
            "highlights" -> Blocks -> Blocks
    B.blockQuote (Blocks -> Blocks) -> RSTParser m Blocks -> RSTParser m Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> RSTParser m Blocks -> Text -> RSTParser m Blocks
    forall s (m :: * -> *) u a.
    (Stream s m Char, IsString s, HasLastStrPosition u) =>
    ParserT s u m a -> Text -> ParserT s u m a
    parseFromString' RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    parseBlocks Text
    body'
            "rubric" -> Many Inline -> Blocks
    B.para (Many Inline -> Blocks)
    -> (Many Inline -> Many Inline) -> Many Inline -> Blocks
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Many Inline -> Many Inline
    B.strong (Many Inline -> Blocks)
    -> ParsecT Text ParserState m (Many Inline) -> RSTParser m Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Text -> ParsecT Text ParserState m (Many Inline)
    forall (m :: * -> *).
    PandocMonad m =>
    Text -> RSTParser m (Many Inline)
    parseInlineFromText Text
    top
            _ | Text
    label Text -> [Text] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `elem` ["attention","caution","danger","error","hint",
                              "important","note","tip","warning","admonition"] ->
               do Blocks
    bod <- RSTParser m Blocks -> Text -> RSTParser m Blocks
    forall s (m :: * -> *) u a.
    (Stream s m Char, IsString s, HasLastStrPosition u) =>
    ParserT s u m a -> Text -> ParserT s u m a
    parseFromString' RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    parseBlocks (Text -> RSTParser m Blocks) -> Text -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ Text
    top Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> "\n\n" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    body'
                  let lab :: Blocks
    lab = case Text
    label of
                              "admonition" -> Blocks
    forall a. Monoid a => a
    mempty
                              (Text -> Maybe (Char, Text)
    T.uncons -> Just (l :: Char
    l, ls :: Text
    ls))
                                -> Attr -> Blocks -> Blocks
    B.divWith ("",["title"],[])
                                              (Many Inline -> Blocks
    B.para (Text -> Many Inline
    B.str (Text -> Many Inline) -> Text -> Many Inline
    forall a b. (a -> b) -> a -> b
    $ Char -> Text -> Text
    T.cons (Char -> Char
    toUpper Char
    l)  Text
    ls))
                              _ -> Blocks
    forall a. Monoid a => a
    mempty
                  Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> RSTParser m Blocks) -> Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ Attr -> Blocks -> Blocks
    B.divWith (Text
    name,Text
    labelText -> [Text] -> [Text]
    forall a. a -> [a] -> [a]
    :[Text]
    classes,NoteTable
    keyvals) (Blocks
    lab Blocks -> Blocks -> Blocks
    forall a. Semigroup a => a -> a -> a
    <> Blocks
    bod)
            "sidebar" ->
               do let subtit :: Text
    subtit = Text -> (Text -> Text) -> Maybe Text -> Text
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe "" Text -> Text
    trim (Maybe Text -> Text) -> Maybe Text -> Text
    forall a b. (a -> b) -> a -> b
    $ Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "subtitle" NoteTable
    fields
                  Blocks
    tit <- Many Inline -> Blocks
    B.para (Many Inline -> Blocks)
    -> (Many Inline -> Many Inline) -> Many Inline -> Blocks
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Many Inline -> Many Inline
    B.strong (Many Inline -> Blocks)
    -> ParsecT Text ParserState m (Many Inline) -> RSTParser m Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Text -> ParsecT Text ParserState m (Many Inline)
    forall (m :: * -> *).
    PandocMonad m =>
    Text -> RSTParser m (Many Inline)
    parseInlineFromText
                              (Text -> Text
    trim Text
    top Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> if Text -> Bool
    T.null Text
    subtit
                                              then ""
                                              else ":  " Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    subtit)
                  Blocks
    bod <- RSTParser m Blocks -> Text -> RSTParser m Blocks
    forall s (m :: * -> *) u a.
    (Stream s m Char, IsString s, HasLastStrPosition u) =>
    ParserT s u m a -> Text -> ParserT s u m a
    parseFromString' RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    parseBlocks Text
    body'
                  Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> RSTParser m Blocks) -> Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ Attr -> Blocks -> Blocks
    B.divWith (Text
    name,"sidebar"Text -> [Text] -> [Text]
    forall a. a -> [a] -> [a]
    :[Text]
    classes,NoteTable
    keyvals) (Blocks -> Blocks) -> Blocks -> Blocks
    forall a b. (a -> b) -> a -> b
    $ Blocks
    tit Blocks -> Blocks -> Blocks
    forall a. Semigroup a => a -> a -> a
    <> Blocks
    bod
            "topic" ->
               do Blocks
    tit <- Many Inline -> Blocks
    B.para (Many Inline -> Blocks)
    -> (Many Inline -> Many Inline) -> Many Inline -> Blocks
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Many Inline -> Many Inline
    B.strong (Many Inline -> Blocks)
    -> ParsecT Text ParserState m (Many Inline) -> RSTParser m Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Text -> ParsecT Text ParserState m (Many Inline)
    forall (m :: * -> *).
    PandocMonad m =>
    Text -> RSTParser m (Many Inline)
    parseInlineFromText Text
    top
                  Blocks
    bod <- RSTParser m Blocks -> Text -> RSTParser m Blocks
    forall s (m :: * -> *) u a.
    (Stream s m Char, IsString s, HasLastStrPosition u) =>
    ParserT s u m a -> Text -> ParserT s u m a
    parseFromString' RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    parseBlocks Text
    body'
                  Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> RSTParser m Blocks) -> Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ Attr -> Blocks -> Blocks
    B.divWith (Text
    name,"topic"Text -> [Text] -> [Text]
    forall a. a -> [a] -> [a]
    :[Text]
    classes,NoteTable
    keyvals) (Blocks -> Blocks) -> Blocks -> Blocks
    forall a b. (a -> b) -> a -> b
    $ Blocks
    tit Blocks -> Blocks -> Blocks
    forall a. Semigroup a => a -> a -> a
    <> Blocks
    bod
            "default-role" -> Blocks
    forall a. Monoid a => a
    mempty Blocks -> ParsecT Text ParserState m () -> RSTParser m Blocks
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ (ParserState -> ParserState) -> ParsecT Text ParserState m ()
    forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
    updateState (\s :: ParserState
    s ->
                                  ParserState
    s { stateRstDefaultRole :: Text
    stateRstDefaultRole =
                                      case Text -> Text
    trim Text
    top of
                                         ""   -> ParserState -> Text
    stateRstDefaultRole ParserState
    forall a. Default a => a
    def
                                         role :: Text
    role -> Text
    role })
            "highlight" -> Blocks
    forall a. Monoid a => a
    mempty Blocks -> ParsecT Text ParserState m () -> RSTParser m Blocks
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ (ParserState -> ParserState) -> ParsecT Text ParserState m ()
    forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
    updateState (\s :: ParserState
    s ->
                                  ParserState
    s { stateRstHighlight :: Maybe Text
    stateRstHighlight =
                                      case Text -> Text
    trim Text
    top of
                                         ""   -> ParserState -> Maybe Text
    stateRstHighlight ParserState
    forall a. Default a => a
    def
                                         lang :: Text
    lang -> Text -> Maybe Text
    forall a. a -> Maybe a
    Just Text
    lang })
            x :: Text
    x | Text
    x Text -> Text -> Bool
    forall a. Eq a => a -> a -> Bool
    == "code" Bool -> Bool -> Bool
    || Text
    x Text -> Text -> Bool
    forall a. Eq a => a -> a -> Bool
    == "code-block" Bool -> Bool -> Bool
    || Text
    x Text -> Text -> Bool
    forall a. Eq a => a -> a -> Bool
    == "sourcecode" ->
              Text
    -> [Text]
    -> Maybe Text
    -> Text
    -> Text
    -> Bool
    -> RSTParser m Blocks
    forall (m :: * -> *).
    Text
    -> [Text]
    -> Maybe Text
    -> Text
    -> Text
    -> Bool
    -> RSTParser m Blocks
    codeblock Text
    name [Text]
    classes
                        (Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "number-lines" NoteTable
    fields) (Text -> Text
    trim Text
    top) Text
    body Bool
    True
            "aafig" -> do
              let attribs :: Attr
    attribs = (Text
    name, ["aafig"], ((Text, Text) -> (Text, Text)) -> NoteTable -> NoteTable
    forall a b. (a -> b) -> [a] -> [b]
    map ((Text -> Text) -> (Text, Text) -> (Text, Text)
    forall (a :: * -> * -> *) b c d.
    Arrow a =>
    a b c -> a (d, b) (d, c)
    second Text -> Text
    trimr) NoteTable
    fields)
              Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> RSTParser m Blocks) -> Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ Attr -> Text -> Blocks
    B.codeBlockWith Attr
    attribs (Text -> Blocks) -> Text -> Blocks
    forall a b. (a -> b) -> a -> b
    $ Text -> Text
    stripTrailingNewlines Text
    body
            "math" -> Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> RSTParser m Blocks) -> Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ Many Inline -> Blocks
    B.para (Many Inline -> Blocks) -> Many Inline -> Blocks
    forall a b. (a -> b) -> a -> b
    $ [Many Inline] -> Many Inline
    forall a. Monoid a => [a] -> a
    mconcat ([Many Inline] -> Many Inline) -> [Many Inline] -> Many Inline
    forall a b. (a -> b) -> a -> b
    $ (Text -> Many Inline) -> [Text] -> [Many Inline]
    forall a b. (a -> b) -> [a] -> [b]
    map Text -> Many Inline
    B.displayMath
                             ([Text] -> [Many Inline]) -> [Text] -> [Many Inline]
    forall a b. (a -> b) -> a -> b
    $ Text -> [Text]
    toChunks (Text -> [Text]) -> Text -> [Text]
    forall a b. (a -> b) -> a -> b
    $ Text
    top Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> "\n\n" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    body
            "figure" -> do
               (caption :: Many Inline
    caption, legend :: Blocks
    legend) <- ParserT Text ParserState m (Many Inline, Blocks)
    -> Text -> ParserT Text ParserState m (Many Inline, Blocks)
    forall s (m :: * -> *) u a.
    (Stream s m Char, IsString s, HasLastStrPosition u) =>
    ParserT s u m a -> Text -> ParserT s u m a
    parseFromString' ParserT Text ParserState m (Many Inline, Blocks)
    forall (m :: * -> *).
    PandocMonad m =>
    RSTParser m (Many Inline, Blocks)
    extractCaption Text
    body'
               let src :: Text
    src = Text -> Text
    escapeURI (Text -> Text) -> Text -> Text
    forall a b. (a -> b) -> a -> b
    $ Text -> Text
    trim Text
    top
               Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> RSTParser m Blocks) -> Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ Many Inline -> Blocks
    B.para (Attr -> Text -> Text -> Many Inline -> Many Inline
    B.imageWith (Text -> Attr
    forall a. IsString a => Text -> (Text, [Text], [(a, Text)])
    imgAttr "figclass") Text
    src "fig:"
                           Many Inline
    caption) Blocks -> Blocks -> Blocks
    forall a. Semigroup a => a -> a -> a
    <> Blocks
    legend
            "image" -> do
               let src :: Text
    src = Text -> Text
    escapeURI (Text -> Text) -> Text -> Text
    forall a b. (a -> b) -> a -> b
    $ Text -> Text
    trim Text
    top
               let alt :: Many Inline
    alt = Text -> Many Inline
    B.str (Text -> Many Inline) -> Text -> Many Inline
    forall a b. (a -> b) -> a -> b
    $ Text -> (Text -> Text) -> Maybe Text -> Text
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe "image" Text -> Text
    trim (Maybe Text -> Text) -> Maybe Text -> Text
    forall a b. (a -> b) -> a -> b
    $ Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "alt" NoteTable
    fields
               let attr :: Attr
    attr = Text -> Attr
    forall a. IsString a => Text -> (Text, [Text], [(a, Text)])
    imgAttr "class"
               Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> RSTParser m Blocks) -> Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ Many Inline -> Blocks
    B.para
                      (Many Inline -> Blocks) -> Many Inline -> Blocks
    forall a b. (a -> b) -> a -> b
    $ case Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "target" NoteTable
    fields of
                              Just t :: Text
    t  -> Text -> Text -> Many Inline -> Many Inline
    B.link (Text -> Text
    escapeURI (Text -> Text) -> Text -> Text
    forall a b. (a -> b) -> a -> b
    $ Text -> Text
    trim Text
    t) ""
                                         (Many Inline -> Many Inline) -> Many Inline -> Many Inline
    forall a b. (a -> b) -> a -> b
    $ Attr -> Text -> Text -> Many Inline -> Many Inline
    B.imageWith Attr
    attr Text
    src "" Many Inline
    alt
                              Nothing -> Attr -> Text -> Text -> Many Inline -> Many Inline
    B.imageWith Attr
    attr Text
    src "" Many Inline
    alt
            "class" -> do
                let attrs :: Attr
    attrs = (Text
    name, Text -> [Text]
    T.words (Text -> Text
    trim Text
    top), ((Text, Text) -> (Text, Text)) -> NoteTable -> NoteTable
    forall a b. (a -> b) -> [a] -> [b]
    map ((Text -> Text) -> (Text, Text) -> (Text, Text)
    forall (a :: * -> * -> *) b c d.
    Arrow a =>
    a b c -> a (d, b) (d, c)
    second Text -> Text
    trimr) NoteTable
    fields)
                --  directive content or the first immediately following element
                Blocks
    children <- case Text
    body of
                    "" -> RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    block
                    _  -> RSTParser m Blocks -> Text -> RSTParser m Blocks
    forall s (m :: * -> *) u a.
    (Stream s m Char, IsString s, HasLastStrPosition u) =>
    ParserT s u m a -> Text -> ParserT s u m a
    parseFromString' RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    parseBlocks  Text
    body'
                Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> RSTParser m Blocks) -> Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ Attr -> Blocks -> Blocks
    B.divWith Attr
    attrs Blocks
    children
            other :: Text
    other     -> do
                SourcePos
    pos <- ParsecT Text ParserState m SourcePos
    forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
    getPosition
                LogMessage -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) a st.
    (Stream s m a, HasLogMessages st) =>
    LogMessage -> ParserT s st m ()
    logMessage (LogMessage -> ParsecT Text ParserState m ())
    -> LogMessage -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ Text -> SourcePos -> LogMessage
    SkippedContent (".. " Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    other) SourcePos
    pos
                Blocks
    bod <- RSTParser m Blocks -> Text -> RSTParser m Blocks
    forall s (m :: * -> *) u a.
    (Stream s m Char, IsString s, HasLastStrPosition u) =>
    ParserT s u m a -> Text -> ParserT s u m a
    parseFromString' RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    parseBlocks (Text -> RSTParser m Blocks) -> Text -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ Text
    top Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> "\n\n" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    body'
                Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> RSTParser m Blocks) -> Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ Attr -> Blocks -> Blocks
    B.divWith (Text
    name, Text
    otherText -> [Text] -> [Text]
    forall a. a -> [a] -> [a]
    :[Text]
    classes, NoteTable
    keyvals) Blocks
    bod

    tableDirective :: PandocMonad m
                   => Text -> [(Text, Text)] -> Text -> RSTParser m Blocks
    tableDirective :: Text -> NoteTable -> Text -> RSTParser m Blocks
    tableDirective top :: Text
    top fields :: NoteTable
    fields body :: Text
    body = do
      Blocks
    bs <- RSTParser m Blocks -> Text -> RSTParser m Blocks
    forall s (m :: * -> *) u a.
    (Stream s m Char, IsString s, HasLastStrPosition u) =>
    ParserT s u m a -> Text -> ParserT s u m a
    parseFromString' RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    parseBlocks Text
    body
      case Blocks -> [Block]
    forall a. Many a -> [a]
    B.toList Blocks
    bs of
           [Table _ aligns' :: [Alignment]
    aligns' widths' :: [Double]
    widths' header' :: [[Block]]
    header' rows' :: [[[Block]]]
    rows'] -> do
             Many Inline
    title <- ParserT Text ParserState m (Many Inline)
    -> Text -> ParserT Text ParserState m (Many Inline)
    forall s (m :: * -> *) u a.
    (Stream s m Char, IsString s, HasLastStrPosition u) =>
    ParserT s u m a -> Text -> ParserT s u m a
    parseFromString' (Many Inline -> Many Inline
    trimInlines (Many Inline -> Many Inline)
    -> ([Many Inline] -> Many Inline) -> [Many Inline] -> Many Inline
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Many Inline] -> Many Inline
    forall a. Monoid a => [a] -> a
    mconcat ([Many Inline] -> Many Inline)
    -> ParsecT Text ParserState m [Many Inline]
    -> ParserT Text ParserState m (Many Inline)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParserT Text ParserState m (Many Inline)
    -> ParsecT Text ParserState m [Many Inline]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many ParserT Text ParserState m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    inline) Text
    top
             Int
    columns <- (ReaderOptions -> Int) -> ParserT Text ParserState m Int
    forall st s (m :: * -> *) t b.
    (HasReaderOptions st, Stream s m t) =>
    (ReaderOptions -> b) -> ParserT s st m b
    getOption ReaderOptions -> Int
    readerColumns
             let numOfCols :: Int
    numOfCols = [[Block]] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length [[Block]]
    header'
             let normWidths :: [b] -> [b]
    normWidths ws :: [b]
    ws =
                    (b -> b) -> [b] -> [b]
    forall a b. (a -> b) -> [a] -> [b]
    map (b -> b -> b
    forall a. Fractional a => a -> a -> a
    / b -> b -> b
    forall a. Ord a => a -> a -> a
    max 1.0 (Int -> b
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (Int
    columns Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    numOfCols))) [b]
    ws
             let widths :: [Double]
    widths = case Text -> Text
    trim (Text -> Text) -> Maybe Text -> Maybe Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "widths" NoteTable
    fields of
                               Just "auto" -> Int -> Double -> [Double]
    forall a. Int -> a -> [a]
    replicate Int
    numOfCols 0.0
                               Just "grid" -> [Double]
    widths'
                               Just specs :: Text
    specs -> [Double] -> [Double]
    forall b. (Fractional b, Ord b) => [b] -> [b]
    normWidths
                                   ([Double] -> [Double]) -> [Double] -> [Double]
    forall a b. (a -> b) -> a -> b
    $ (Text -> Double) -> [Text] -> [Double]
    forall a b. (a -> b) -> [a] -> [b]
    map (Double -> Maybe Double -> Double
    forall a. a -> Maybe a -> a
    fromMaybe (0 :: Double) (Maybe Double -> Double)
    -> (Text -> Maybe Double) -> Text -> Double
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Maybe Double
    forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
    safeRead)
                                   ([Text] -> [Double]) -> [Text] -> [Double]
    forall a b. (a -> b) -> a -> b
    $ (Char -> Bool) -> Text -> [Text]
    splitTextBy (Char -> [Char] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `elem` (" ," :: String)) Text
    specs
                               Nothing -> [Double]
    widths'
             -- align is not applicable since we can't represent whole table align
             Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> RSTParser m Blocks) -> Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ Block -> Blocks
    forall a. a -> Many a
    B.singleton (Block -> Blocks) -> Block -> Blocks
    forall a b. (a -> b) -> a -> b
    $ [Inline]
    -> [Alignment] -> [Double] -> [[Block]] -> [[[Block]]] -> Block
    Table (Many Inline -> [Inline]
    forall a. Many a -> [a]
    B.toList Many Inline
    title)
                                      [Alignment]
    aligns' [Double]
    widths [[Block]]
    header' [[[Block]]]
    rows'
           _ -> Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return Blocks
    forall a. Monoid a => a
    mempty

    -- TODO: :stub-columns:.
    -- Only the first row becomes the header even if header-rows: > 1,
    -- since Pandoc doesn't support a table with multiple header rows.
    -- We don't need to parse :align: as it represents the whole table align.
    listTableDirective :: PandocMonad m
                       => Text -> [(Text, Text)] -> Text
                       -> RSTParser m Blocks
    listTableDirective :: Text -> NoteTable -> Text -> RSTParser m Blocks
    listTableDirective top :: Text
    top fields :: NoteTable
    fields body :: Text
    body = do
      Blocks
    bs <- RSTParser m Blocks -> Text -> RSTParser m Blocks
    forall s (m :: * -> *) u a.
    (Stream s m Char, IsString s, HasLastStrPosition u) =>
    ParserT s u m a -> Text -> ParserT s u m a
    parseFromString' RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    parseBlocks Text
    body
      Many Inline
    title <- ParserT Text ParserState m (Many Inline)
    -> Text -> ParserT Text ParserState m (Many Inline)
    forall s (m :: * -> *) u a.
    (Stream s m Char, IsString s, HasLastStrPosition u) =>
    ParserT s u m a -> Text -> ParserT s u m a
    parseFromString' (Many Inline -> Many Inline
    trimInlines (Many Inline -> Many Inline)
    -> ([Many Inline] -> Many Inline) -> [Many Inline] -> Many Inline
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Many Inline] -> Many Inline
    forall a. Monoid a => [a] -> a
    mconcat ([Many Inline] -> Many Inline)
    -> ParsecT Text ParserState m [Many Inline]
    -> ParserT Text ParserState m (Many Inline)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParserT Text ParserState m (Many Inline)
    -> ParsecT Text ParserState m [Many Inline]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many ParserT Text ParserState m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    inline) Text
    top
      let rows :: [[Blocks]]
    rows = [Block] -> [[Blocks]]
    takeRows ([Block] -> [[Blocks]]) -> [Block] -> [[Blocks]]
    forall a b. (a -> b) -> a -> b
    $ Blocks -> [Block]
    forall a. Many a -> [a]
    B.toList Blocks
    bs
          headerRowsNum :: Int
    headerRowsNum = Int -> Maybe Int -> Int
    forall a. a -> Maybe a -> a
    fromMaybe (0 :: Int) (Maybe Int -> Int) -> Maybe Int -> Int
    forall a b. (a -> b) -> a -> b
    $
             Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "header-rows" NoteTable
    fields Maybe Text -> (Text -> Maybe Int) -> Maybe Int
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= Text -> Maybe Int
    forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
    safeRead
          (headerRow :: [Blocks]
    headerRow,bodyRows :: [[Blocks]]
    bodyRows,numOfCols :: Int
    numOfCols) = case [[Blocks]]
    rows of
            x :: [Blocks]
    x:xs :: [[Blocks]]
    xs -> if Int
    headerRowsNum Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    > 0
                       then ([Blocks]
    x, [[Blocks]]
    xs, [Blocks] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length [Blocks]
    x)
                       else ([], [[Blocks]]
    rows, [Blocks] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length [Blocks]
    x)
            _ -> ([],[],0)
          widths :: [Double]
    widths = case Text -> Text
    trim (Text -> Text) -> Maybe Text -> Maybe Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "widths" NoteTable
    fields of
            Just "auto" -> Int -> Double -> [Double]
    forall a. Int -> a -> [a]
    replicate Int
    numOfCols 0
            Just specs :: Text
    specs -> [Double] -> [Double]
    forall b. (Fractional b, Ord b) => [b] -> [b]
    normWidths ([Double] -> [Double]) -> [Double] -> [Double]
    forall a b. (a -> b) -> a -> b
    $ (Text -> Double) -> [Text] -> [Double]
    forall a b. (a -> b) -> [a] -> [b]
    map (Double -> Maybe Double -> Double
    forall a. a -> Maybe a -> a
    fromMaybe (0 :: Double) (Maybe Double -> Double)
    -> (Text -> Maybe Double) -> Text -> Double
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Maybe Double
    forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
    safeRead) ([Text] -> [Double]) -> [Text] -> [Double]
    forall a b. (a -> b) -> a -> b
    $
                               (Char -> Bool) -> Text -> [Text]
    splitTextBy (Char -> [Char] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `elem` (" ," :: String)) Text
    specs
            _ -> Int -> Double -> [Double]
    forall a. Int -> a -> [a]
    replicate Int
    numOfCols 0
      Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> RSTParser m Blocks) -> Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ Many Inline
    -> [(Alignment, Double)] -> [Blocks] -> [[Blocks]] -> Blocks
    B.table Many Inline
    title
                 ([Alignment] -> [Double] -> [(Alignment, Double)]
    forall a b. [a] -> [b] -> [(a, b)]
    zip (Int -> Alignment -> [Alignment]
    forall a. Int -> a -> [a]
    replicate Int
    numOfCols Alignment
    AlignDefault) [Double]
    widths)
                 [Blocks]
    headerRow
                 [[Blocks]]
    bodyRows
        where takeRows :: [Block] -> [[Blocks]]
    takeRows [BulletList rows :: [[Block]]
    rows] = ([Block] -> [Blocks]) -> [[Block]] -> [[Blocks]]
    forall a b. (a -> b) -> [a] -> [b]
    map [Block] -> [Blocks]
    takeCells [[Block]]
    rows
              takeRows _                 = []
              takeCells :: [Block] -> [Blocks]
    takeCells [BulletList cells :: [[Block]]
    cells] = ([Block] -> Blocks) -> [[Block]] -> [Blocks]
    forall a b. (a -> b) -> [a] -> [b]
    map [Block] -> Blocks
    forall a. [a] -> Many a
    B.fromList [[Block]]
    cells
              takeCells _                  = []
              normWidths :: [b] -> [b]
    normWidths ws :: [b]
    ws = (b -> b) -> [b] -> [b]
    forall a b. (a -> b) -> [a] -> [b]
    map (b -> b -> b
    forall a. Fractional a => a -> a -> a
    / b -> b -> b
    forall a. Ord a => a -> a -> a
    max 1 ([b] -> b
    forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
    sum [b]
    ws)) [b]
    ws

    csvTableDirective :: PandocMonad m
                       => Text -> [(Text, Text)] -> Text
                       -> RSTParser m Blocks
    csvTableDirective :: Text -> NoteTable -> Text -> RSTParser m Blocks
    csvTableDirective top :: Text
    top fields :: NoteTable
    fields rawcsv :: Text
    rawcsv = do
      let explicitHeader :: Maybe Text
    explicitHeader = Text -> Text
    trim (Text -> Text) -> Maybe Text -> Maybe Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "header" NoteTable
    fields
      let opts :: CSVOptions
    opts = CSVOptions
    defaultCSVOptions{
                    csvDelim :: Char
    csvDelim = case Text -> Text
    trim (Text -> Text) -> Maybe Text -> Maybe Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "delim" NoteTable
    fields of
                                    Just "tab"   -> '\t'
                                    Just "space" -> ' '
                                    Just (Text -> [Char]
    T.unpack -> [c :: Char
    c])
                                                 -> Char
    c
                                    _            -> ','
                  , csvQuote :: Char
    csvQuote = case Text -> Text
    trim (Text -> Text) -> Maybe Text -> Maybe Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "quote" NoteTable
    fields of
                                    Just (Text -> [Char]
    T.unpack -> [c :: Char
    c])
                                      -> Char
    c
                                    _ -> '"'
                  , csvEscape :: Maybe Char
    csvEscape = case Text -> Text
    trim (Text -> Text) -> Maybe Text -> Maybe Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "escape" NoteTable
    fields of
                                    Just (Text -> [Char]
    T.unpack -> [c :: Char
    c])
                                      -> Char -> Maybe Char
    forall a. a -> Maybe a
    Just Char
    c
                                    _ -> Maybe Char
    forall a. Maybe a
    Nothing
                  , csvKeepSpace :: Bool
    csvKeepSpace = case Text -> Text
    trim (Text -> Text) -> Maybe Text -> Maybe Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "keepspace" NoteTable
    fields of
                                           Just "true" -> Bool
    True
                                           _           -> Bool
    False
                  }
      let headerRowsNum :: Int
    headerRowsNum = Int -> Maybe Int -> Int
    forall a. a -> Maybe a -> a
    fromMaybe (case Maybe Text
    explicitHeader of
                                           Just _  -> 1 :: Int
                                           Nothing -> 0 :: Int) (Maybe Int -> Int) -> Maybe Int -> Int
    forall a b. (a -> b) -> a -> b
    $
               Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "header-rows" NoteTable
    fields Maybe Text -> (Text -> Maybe Int) -> Maybe Int
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= Text -> Maybe Int
    forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
    safeRead
      Text
    rawcsv' <- case Text -> Text
    trim (Text -> Text) -> Maybe Text -> Maybe Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$>
                        Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "file" NoteTable
    fields Maybe Text -> Maybe Text -> Maybe Text
    forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
    `mplus` Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "url" NoteTable
    fields of
                      Just u :: Text
    u  -> do
                        (bs :: ByteString
    bs, _) <- Text -> ParsecT Text ParserState m (ByteString, Maybe Text)
    forall (m :: * -> *).
    PandocMonad m =>
    Text -> m (ByteString, Maybe Text)
    fetchItem Text
    u
                        Text -> ParsecT Text ParserState m Text
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Text -> ParsecT Text ParserState m Text)
    -> Text -> ParsecT Text ParserState m Text
    forall a b. (a -> b) -> a -> b
    $ ByteString -> Text
    UTF8.toText ByteString
    bs
                      Nothing -> Text -> ParsecT Text ParserState m Text
    forall (m :: * -> *) a. Monad m => a -> m a
    return Text
    rawcsv
      let res :: Either ParseError [[Text]]
    res = CSVOptions -> Text -> Either ParseError [[Text]]
    parseCSV CSVOptions
    opts (case Maybe Text
    explicitHeader of
                                  Just h :: Text
    h  -> Text
    h Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> "\n" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    rawcsv'
                                  Nothing -> Text
    rawcsv')
      case Either ParseError [[Text]]
    res of
           Left e :: ParseError
    e  ->
             PandocError -> RSTParser m Blocks
    forall e (m :: * -> *) a. MonadError e m => e -> m a
    throwError (PandocError -> RSTParser m Blocks)
    -> PandocError -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ Text -> ParseError -> PandocError
    PandocParsecError "csv table" ParseError
    e
           Right rawrows :: [[Text]]
    rawrows -> do
             let parseCell :: Text -> RSTParser m Blocks
    parseCell = RSTParser m Blocks -> Text -> RSTParser m Blocks
    forall s (m :: * -> *) u a.
    (Stream s m Char, IsString s, HasLastStrPosition u) =>
    ParserT s u m a -> Text -> ParserT s u m a
    parseFromString' (RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    plain RSTParser m Blocks -> RSTParser m Blocks -> RSTParser m Blocks
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return Blocks
    forall a. Monoid a => a
    mempty)
             let parseRow :: [Text] -> ParsecT Text ParserState m [Blocks]
    parseRow = (Text -> RSTParser m Blocks)
    -> [Text] -> ParsecT Text ParserState m [Blocks]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    mapM Text -> RSTParser m Blocks
    parseCell
             [[Blocks]]
    rows <- ([Text] -> ParsecT Text ParserState m [Blocks])
    -> [[Text]] -> ParsecT Text ParserState m [[Blocks]]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    mapM [Text] -> ParsecT Text ParserState m [Blocks]
    parseRow [[Text]]
    rawrows
             let (headerRow :: [Blocks]
    headerRow,bodyRows :: [[Blocks]]
    bodyRows,numOfCols :: Int
    numOfCols) =
                  case [[Blocks]]
    rows of
                       x :: [Blocks]
    x:xs :: [[Blocks]]
    xs -> if Int
    headerRowsNum Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    > 0
                              then ([Blocks]
    x, [[Blocks]]
    xs, [Blocks] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length [Blocks]
    x)
                              else ([], [[Blocks]]
    rows, [Blocks] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length [Blocks]
    x)
                       _ -> ([],[],0)
             Many Inline
    title <- ParserT Text ParserState m (Many Inline)
    -> Text -> ParserT Text ParserState m (Many Inline)
    forall s (m :: * -> *) u a.
    (Stream s m Char, IsString s, HasLastStrPosition u) =>
    ParserT s u m a -> Text -> ParserT s u m a
    parseFromString' (Many Inline -> Many Inline
    trimInlines (Many Inline -> Many Inline)
    -> ([Many Inline] -> Many Inline) -> [Many Inline] -> Many Inline
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Many Inline] -> Many Inline
    forall a. Monoid a => [a] -> a
    mconcat ([Many Inline] -> Many Inline)
    -> ParsecT Text ParserState m [Many Inline]
    -> ParserT Text ParserState m (Many Inline)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParserT Text ParserState m (Many Inline)
    -> ParsecT Text ParserState m [Many Inline]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many ParserT Text ParserState m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    inline) Text
    top
             let normWidths :: [b] -> [b]
    normWidths ws :: [b]
    ws = (b -> b) -> [b] -> [b]
    forall a b. (a -> b) -> [a] -> [b]
    map (b -> b -> b
    forall a. Fractional a => a -> a -> a
    / b -> b -> b
    forall a. Ord a => a -> a -> a
    max 1 ([b] -> b
    forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
    sum [b]
    ws)) [b]
    ws
             let widths :: [Double]
    widths =
                   case Text -> Text
    trim (Text -> Text) -> Maybe Text -> Maybe Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "widths" NoteTable
    fields of
                     Just "auto" -> Int -> Double -> [Double]
    forall a. Int -> a -> [a]
    replicate Int
    numOfCols 0
                     Just specs :: Text
    specs -> [Double] -> [Double]
    forall b. (Fractional b, Ord b) => [b] -> [b]
    normWidths
                                   ([Double] -> [Double]) -> [Double] -> [Double]
    forall a b. (a -> b) -> a -> b
    $ (Text -> Double) -> [Text] -> [Double]
    forall a b. (a -> b) -> [a] -> [b]
    map (Double -> Maybe Double -> Double
    forall a. a -> Maybe a -> a
    fromMaybe (0 :: Double) (Maybe Double -> Double)
    -> (Text -> Maybe Double) -> Text -> Double
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Maybe Double
    forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
    safeRead)
                                   ([Text] -> [Double]) -> [Text] -> [Double]
    forall a b. (a -> b) -> a -> b
    $ (Char -> Bool) -> Text -> [Text]
    splitTextBy (Char -> [Char] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `elem` (" ," :: String)) Text
    specs
                     _ -> Int -> Double -> [Double]
    forall a. Int -> a -> [a]
    replicate Int
    numOfCols 0
             Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> RSTParser m Blocks) -> Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ Many Inline
    -> [(Alignment, Double)] -> [Blocks] -> [[Blocks]] -> Blocks
    B.table Many Inline
    title
                      ([Alignment] -> [Double] -> [(Alignment, Double)]
    forall a b. [a] -> [b] -> [(a, b)]
    zip (Int -> Alignment -> [Alignment]
    forall a. Int -> a -> [a]
    replicate Int
    numOfCols Alignment
    AlignDefault) [Double]
    widths)
                      [Blocks]
    headerRow
                      [[Blocks]]
    bodyRows

    -- TODO:
    --  - Only supports :format: fields with a single format for :raw: roles,
    --    change Text.Pandoc.Definition.Format to fix
    addNewRole :: PandocMonad m
               => Text -> [(Text, Text)] -> RSTParser m Blocks
    addNewRole :: Text -> NoteTable -> RSTParser m Blocks
    addNewRole roleText :: Text
    roleText fields :: NoteTable
    fields = do
        SourcePos
    pos <- ParsecT Text ParserState m SourcePos
    forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
    getPosition
        (role :: Text
    role, parentRole :: Text
    parentRole) <- ParserT Text ParserState m (Text, Text)
    -> Text -> ParserT Text ParserState m (Text, Text)
    forall s (m :: * -> *) u a.
    (Stream s m Char, IsString s, HasLastStrPosition u) =>
    ParserT s u m a -> Text -> ParserT s u m a
    parseFromString' ParserT Text ParserState m (Text, Text)
    inheritedRole Text
    roleText
        Map Text (Text, Maybe Text, Attr)
    customRoles <- ParserState -> Map Text (Text, Maybe Text, Attr)
    stateRstCustomRoles (ParserState -> Map Text (Text, Maybe Text, Attr))
    -> ParsecT Text ParserState m ParserState
    -> ParsecT Text ParserState m (Map Text (Text, Maybe Text, Attr))
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Text ParserState m ParserState
    forall (m :: * -> *) s u. Monad m => ParsecT s u m u
    getState
        let getBaseRole :: (a, b, c) -> Map a (a, b, c) -> (a, b, c)
    getBaseRole (r :: a
    r, f :: b
    f, a :: c
    a) roles :: Map a (a, b, c)
    roles =
                case a -> Map a (a, b, c) -> Maybe (a, b, c)
    forall k a. Ord k => k -> Map k a -> Maybe a
    M.lookup a
    r Map a (a, b, c)
    roles of
                     Just (r' :: a
    r', f' :: b
    f', a' :: c
    a') -> (a, b, c) -> Map a (a, b, c) -> (a, b, c)
    getBaseRole (a
    r', b
    f', c
    a') Map a (a, b, c)
    roles
                     Nothing           -> (a
    r, b
    f, c
    a)
            (baseRole :: Text
    baseRole, baseFmt :: Maybe Text
    baseFmt, baseAttr :: Attr
    baseAttr) =
                   (Text, Maybe Text, Attr)
    -> Map Text (Text, Maybe Text, Attr) -> (Text, Maybe Text, Attr)
    forall a b c. Ord a => (a, b, c) -> Map a (a, b, c) -> (a, b, c)
    getBaseRole (Text
    parentRole, Maybe Text
    forall a. Maybe a
    Nothing, Attr
    nullAttr) Map Text (Text, Maybe Text, Attr)
    customRoles
            fmt :: Maybe Text
    fmt = if Text
    parentRole Text -> Text -> Bool
    forall a. Eq a => a -> a -> Bool
    == "raw" then Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "format" NoteTable
    fields else Maybe Text
    baseFmt
            annotate :: [Text] -> [Text]
            annotate :: [Text] -> [Text]
    annotate = ([Text] -> [Text])
    -> (Text -> [Text] -> [Text]) -> Maybe Text -> [Text] -> [Text]
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe [Text] -> [Text]
    forall a. a -> a
    id (:) (Maybe Text -> [Text] -> [Text]) -> Maybe Text -> [Text] -> [Text]
    forall a b. (a -> b) -> a -> b
    $
                if Text
    baseRole Text -> Text -> Bool
    forall a. Eq a => a -> a -> Bool
    == "code"
                   then Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup "language" NoteTable
    fields
                   else Maybe Text
    forall a. Maybe a
    Nothing
            attr :: Attr
    attr = let (ident :: Text
    ident, classes :: [Text]
    classes, keyValues :: NoteTable
    keyValues) = Attr
    baseAttr
            -- nub in case role name & language class are the same
                   in (Text
    ident, [Text] -> [Text]
    forall a. Eq a => [a] -> [a]
    nub ([Text] -> [Text]) -> ([Text] -> [Text]) -> [Text] -> [Text]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Text
    role Text -> [Text] -> [Text]
    forall a. a -> [a] -> [a]
    :) ([Text] -> [Text]) -> ([Text] -> [Text]) -> [Text] -> [Text]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Text] -> [Text]
    annotate ([Text] -> [Text]) -> [Text] -> [Text]
    forall a b. (a -> b) -> a -> b
    $ [Text]
    classes, NoteTable
    keyValues)

        -- warn about syntax we ignore
        NoteTable
    -> ((Text, Text) -> ParsecT Text ParserState m ())
    -> ParsecT Text ParserState m ()
    forall (t :: * -> *) (m :: * -> *) a b.
    (Foldable t, Monad m) =>
    t a -> (a -> m b) -> m ()
    forM_ NoteTable
    fields (((Text, Text) -> ParsecT Text ParserState m ())
     -> ParsecT Text ParserState m ())
    -> ((Text, Text) -> ParsecT Text ParserState m ())
    -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ \(key :: Text
    key, _) -> case Text
    key of
                     "language" -> Bool
    -> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
    forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
    when (Text
    baseRole Text -> Text -> Bool
    forall a. Eq a => a -> a -> Bool
    /= "code") (ParsecT Text ParserState m () -> ParsecT Text ParserState m ())
    -> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ LogMessage -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) a st.
    (Stream s m a, HasLogMessages st) =>
    LogMessage -> ParserT s st m ()
    logMessage (LogMessage -> ParsecT Text ParserState m ())
    -> LogMessage -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $
                         Text -> SourcePos -> LogMessage
    SkippedContent ":language: [because parent of role is not :code:]"
                            SourcePos
    pos
                     "format" -> Bool
    -> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
    forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
    when (Text
    baseRole Text -> Text -> Bool
    forall a. Eq a => a -> a -> Bool
    /= "raw") (ParsecT Text ParserState m () -> ParsecT Text ParserState m ())
    -> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ LogMessage -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) a st.
    (Stream s m a, HasLogMessages st) =>
    LogMessage -> ParserT s st m ()
    logMessage (LogMessage -> ParsecT Text ParserState m ())
    -> LogMessage -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $
                         Text -> SourcePos -> LogMessage
    SkippedContent ":format: [because parent of role is not :raw:]" SourcePos
    pos
                     _ -> LogMessage -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) a st.
    (Stream s m a, HasLogMessages st) =>
    LogMessage -> ParserT s st m ()
    logMessage (LogMessage -> ParsecT Text ParserState m ())
    -> LogMessage -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ Text -> SourcePos -> LogMessage
    SkippedContent (":" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    key Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> ":") SourcePos
    pos
        Bool
    -> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
    forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
    when (Text
    parentRole Text -> Text -> Bool
    forall a. Eq a => a -> a -> Bool
    == "raw" Bool -> Bool -> Bool
    && Text -> Int
    countKeys "format" Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    > 1) (ParsecT Text ParserState m () -> ParsecT Text ParserState m ())
    -> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $
            LogMessage -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) a st.
    (Stream s m a, HasLogMessages st) =>
    LogMessage -> ParserT s st m ()
    logMessage (LogMessage -> ParsecT Text ParserState m ())
    -> LogMessage -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ Text -> SourcePos -> LogMessage
    SkippedContent
                      ":format: [after first in definition of role]"
                      SourcePos
    pos
        Bool
    -> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
    forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
    when (Text
    parentRole Text -> Text -> Bool
    forall a. Eq a => a -> a -> Bool
    == "code" Bool -> Bool -> Bool
    && Text -> Int
    countKeys "language" Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    > 1) (ParsecT Text ParserState m () -> ParsecT Text ParserState m ())
    -> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $
            LogMessage -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) a st.
    (Stream s m a, HasLogMessages st) =>
    LogMessage -> ParserT s st m ()
    logMessage (LogMessage -> ParsecT Text ParserState m ())
    -> LogMessage -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ Text -> SourcePos -> LogMessage
    SkippedContent
              ":language: [after first in definition of role]" SourcePos
    pos

        (ParserState -> ParserState) -> ParsecT Text ParserState m ()
    forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
    updateState ((ParserState -> ParserState) -> ParsecT Text ParserState m ())
    -> (ParserState -> ParserState) -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ \s :: ParserState
    s -> ParserState
    s {
            stateRstCustomRoles :: Map Text (Text, Maybe Text, Attr)
    stateRstCustomRoles =
              Text
    -> (Text, Maybe Text, Attr)
    -> Map Text (Text, Maybe Text, Attr)
    -> Map Text (Text, Maybe Text, Attr)
    forall k a. Ord k => k -> a -> Map k a -> Map k a
    M.insert Text
    role (Text
    baseRole, Maybe Text
    fmt, Attr
    attr) Map Text (Text, Maybe Text, Attr)
    customRoles
        }

        Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return Blocks
    forall a. Monoid a => a
    mempty
      where
        countKeys :: Text -> Int
    countKeys k :: Text
    k = [Text] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length ([Text] -> Int) -> (NoteTable -> [Text]) -> NoteTable -> Int
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Text -> Bool) -> [Text] -> [Text]
    forall a. (a -> Bool) -> [a] -> [a]
    filter (Text -> Text -> Bool
    forall a. Eq a => a -> a -> Bool
    == Text
    k) ([Text] -> [Text]) -> (NoteTable -> [Text]) -> NoteTable -> [Text]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ((Text, Text) -> Text) -> NoteTable -> [Text]
    forall a b. (a -> b) -> [a] -> [b]
    map (Text, Text) -> Text
    forall a b. (a, b) -> a
    fst (NoteTable -> Int) -> NoteTable -> Int
    forall a b. (a -> b) -> a -> b
    $ NoteTable
    fields
        inheritedRole :: ParserT Text ParserState m (Text, Text)
    inheritedRole =
            (,) (Text -> Text -> (Text, Text))
    -> ParsecT Text ParserState m Text
    -> ParsecT Text ParserState m (Text -> (Text, Text))
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Text ParserState m Text
    forall (m :: * -> *). PandocMonad m => RSTParser m Text
    roleName ParsecT Text ParserState m (Text -> (Text, Text))
    -> ParsecT Text ParserState m Text
    -> ParserT Text ParserState m (Text, Text)
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> ((Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '(' ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m Text
    -> ParsecT Text ParserState m Text
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> ParsecT Text ParserState m Text
    forall (m :: * -> *). PandocMonad m => RSTParser m Text
    roleName ParsecT Text ParserState m Text
    -> ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m Text
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <* Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char ')')
                                ParsecT Text ParserState m Text
    -> ParsecT Text ParserState m Text
    -> ParsecT Text ParserState m Text
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> Text -> ParsecT Text ParserState m Text
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure "span")

    -- Can contain character codes as decimal numbers or
    -- hexadecimal numbers, prefixed by 0x, x, \x, U+, u, or \u
    -- or as XML-style hexadecimal character entities, e.g. &#x1a2b;
    -- or text, which is used as-is.  Comments start with ..
    unicodeTransform :: Text -> Text
    unicodeTransform :: Text -> Text
    unicodeTransform t :: Text
    t
      | Just xs :: Text
    xs <- Text -> Text -> Maybe Text
    T.stripPrefix ".." Text
    t  = Text -> Text
    unicodeTransform (Text -> Text) -> Text -> Text
    forall a b. (a -> b) -> a -> b
    $ (Char -> Bool) -> Text -> Text
    T.dropWhile (Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    /= '\n') Text
    xs -- comment
      | Just xs :: Text
    xs <- Text -> Text -> Maybe Text
    T.stripPrefix "0x" Text
    t  = Text -> Text -> Text
    go "0x" Text
    xs
      | Just xs :: Text
    xs <- Text -> Text -> Maybe Text
    T.stripPrefix "x" Text
    t   = Text -> Text -> Text
    go "x" Text
    xs
      | Just xs :: Text
    xs <- Text -> Text -> Maybe Text
    T.stripPrefix "\\x" Text
    t = Text -> Text -> Text
    go "\\x" Text
    xs
      | Just xs :: Text
    xs <- Text -> Text -> Maybe Text
    T.stripPrefix "U+" Text
    t  = Text -> Text -> Text
    go "U+" Text
    xs
      | Just xs :: Text
    xs <- Text -> Text -> Maybe Text
    T.stripPrefix "u" Text
    t   = Text -> Text -> Text
    go "u" Text
    xs
      | Just xs :: Text
    xs <- Text -> Text -> Maybe Text
    T.stripPrefix "\\u" Text
    t = Text -> Text -> Text
    go "\\u" Text
    xs
      | Just xs :: Text
    xs <- Text -> Text -> Maybe Text
    T.stripPrefix "&#x" Text
    t = Text -> ((Char, Text) -> Text) -> Maybe (Char, Text) -> Text
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe ("&#x" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text -> Text
    unicodeTransform Text
    xs)
                                           -- drop semicolon
                                           (\(c :: Char
    c,s :: Text
    s) -> Char -> Text -> Text
    T.cons Char
    c (Text -> Text) -> Text -> Text
    forall a b. (a -> b) -> a -> b
    $ Text -> Text
    unicodeTransform (Text -> Text) -> Text -> Text
    forall a b. (a -> b) -> a -> b
    $ Int -> Text -> Text
    T.drop 1 Text
    s)
                                           (Maybe (Char, Text) -> Text) -> Maybe (Char, Text) -> Text
    forall a b. (a -> b) -> a -> b
    $ Text -> Maybe (Char, Text)
    extractUnicodeChar Text
    xs
      | Just (x :: Char
    x, xs :: Text
    xs) <- Text -> Maybe (Char, Text)
    T.uncons Text
    t       = Char -> Text -> Text
    T.cons Char
    x (Text -> Text) -> Text -> Text
    forall a b. (a -> b) -> a -> b
    $ Text -> Text
    unicodeTransform Text
    xs
      | Bool
    otherwise                        = ""
      where go :: Text -> Text -> Text
    go pref :: Text
    pref zs :: Text
    zs = Text -> ((Char, Text) -> Text) -> Maybe (Char, Text) -> Text
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe (Text
    pref Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text -> Text
    unicodeTransform Text
    zs)
                         (\(c :: Char
    c,s :: Text
    s) -> Char -> Text -> Text
    T.cons Char
    c (Text -> Text) -> Text -> Text
    forall a b. (a -> b) -> a -> b
    $ Text -> Text
    unicodeTransform Text
    s)
                         (Maybe (Char, Text) -> Text) -> Maybe (Char, Text) -> Text
    forall a b. (a -> b) -> a -> b
    $ Text -> Maybe (Char, Text)
    extractUnicodeChar Text
    zs

    extractUnicodeChar :: Text -> Maybe (Char, Text)
    extractUnicodeChar :: Text -> Maybe (Char, Text)
    extractUnicodeChar s :: Text
    s = (Char -> (Char, Text)) -> Maybe Char -> Maybe (Char, Text)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap (\c :: Char
    c -> (Char
    c,Text
    rest)) Maybe Char
    mbc
      where (ds :: Text
    ds,rest :: Text
    rest) = (Char -> Bool) -> Text -> (Text, Text)
    T.span Char -> Bool
    isHexDigit Text
    s
            mbc :: Maybe Char
    mbc = Text -> Maybe Char
    forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
    safeRead ("'\\x" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    ds Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> "'")

    extractCaption :: PandocMonad m => RSTParser m (Inlines, Blocks)
    extractCaption :: RSTParser m (Many Inline, Blocks)
    extractCaption = do
      Many Inline
    capt <- Many Inline -> Many Inline
    trimInlines (Many Inline -> Many Inline)
    -> ([Many Inline] -> Many Inline) -> [Many Inline] -> Many Inline
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Many Inline] -> Many Inline
    forall a. Monoid a => [a] -> a
    mconcat ([Many Inline] -> Many Inline)
    -> ParsecT Text ParserState m [Many Inline]
    -> ParsecT Text ParserState m (Many Inline)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Text ParserState m (Many Inline)
    -> ParsecT Text ParserState m [Many Inline]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many ParsecT Text ParserState m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    inline
      Blocks
    legend <- ParsecT Text ParserState m Text -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m ()
    optional ParsecT Text ParserState m Text
    forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Text
    blanklines ParsecT Text ParserState m ()
    -> ParsecT Text ParserState m Blocks
    -> ParsecT Text ParserState m Blocks
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> ([Blocks] -> Blocks
    forall a. Monoid a => [a] -> a
    mconcat ([Blocks] -> Blocks)
    -> ParsecT Text ParserState m [Blocks]
    -> ParsecT Text ParserState m Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Text ParserState m Blocks
    -> ParsecT Text ParserState m [Blocks]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many ParsecT Text ParserState m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    block)
      (Many Inline, Blocks) -> RSTParser m (Many Inline, Blocks)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline
    capt,Blocks
    legend)

    -- divide string by blanklines, and surround with
    -- \begin{aligned}...\end{aligned} if needed.
    toChunks :: Text -> [Text]
    toChunks :: Text -> [Text]
    toChunks = (Text -> Bool) -> [Text] -> [Text]
    forall a. (a -> Bool) -> [a] -> [a]
    dropWhile Text -> Bool
    T.null
               ([Text] -> [Text]) -> (Text -> [Text]) -> Text -> [Text]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ([Text] -> Text) -> [[Text]] -> [Text]
    forall a b. (a -> b) -> [a] -> [b]
    map (Text -> Text
    addAligned (Text -> Text) -> ([Text] -> Text) -> [Text] -> Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Text
    trim (Text -> Text) -> ([Text] -> Text) -> [Text] -> Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Text] -> Text
    T.unlines)
               ([[Text]] -> [Text]) -> (Text -> [[Text]]) -> Text -> [Text]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Text -> Bool) -> [Text] -> [[Text]]
    forall a. (a -> Bool) -> [a] -> [[a]]
    splitBy ((Char -> Bool) -> Text -> Bool
    T.all (Char -> [Char] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `elem` (" \t" :: String))) ([Text] -> [[Text]]) -> (Text -> [Text]) -> Text -> [[Text]]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> [Text]
    T.lines
      -- we put this in an aligned environment if it contains \\, see #4254
      where addAligned :: Text -> Text
    addAligned s :: Text
    s = if "\\\\" Text -> Text -> Bool
    `T.isInfixOf` Text
    s
                              then "\\begin{aligned}\n" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    s Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> "\n\\end{aligned}"
                              else Text
    s

    codeblock :: Text -> [Text] -> Maybe Text -> Text -> Text -> Bool
              -> RSTParser m Blocks
    codeblock :: Text
    -> [Text]
    -> Maybe Text
    -> Text
    -> Text
    -> Bool
    -> RSTParser m Blocks
    codeblock ident :: Text
    ident classes :: [Text]
    classes numberLines :: Maybe Text
    numberLines lang :: Text
    lang body :: Text
    body rmTrailingNewlines :: Bool
    rmTrailingNewlines =
      Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> RSTParser m Blocks) -> Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ Attr -> Text -> Blocks
    B.codeBlockWith Attr
    attribs (Text -> Blocks) -> Text -> Blocks
    forall a b. (a -> b) -> a -> b
    $ Text -> Text
    stripTrailingNewlines' Text
    body
        where stripTrailingNewlines' :: Text -> Text
    stripTrailingNewlines' = if Bool
    rmTrailingNewlines
                                         then Text -> Text
    stripTrailingNewlines
                                         else Text -> Text
    forall a. a -> a
    id
              attribs :: Attr
    attribs = (Text
    ident, [Text]
    classes', NoteTable
    kvs)
              classes' :: [Text]
    classes' = Text
    lang
                        Text -> [Text] -> [Text]
    forall a. a -> [a] -> [a]
    : [Text] -> (Text -> [Text]) -> Maybe Text -> [Text]
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe [] ([Text] -> Text -> [Text]
    forall a b. a -> b -> a
    const ["numberLines"]) Maybe Text
    numberLines
                        [Text] -> [Text] -> [Text]
    forall a. [a] -> [a] -> [a]
    ++ [Text]
    classes
              kvs :: NoteTable
    kvs = NoteTable -> (Text -> NoteTable) -> Maybe Text -> NoteTable
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe [] (\n :: Text
    n -> case Text -> Text
    trimr Text
    n of
                                       "" -> []
                                       xs :: Text
    xs -> [("startFrom", Text
    xs)])
                                Maybe Text
    numberLines

    ---
    --- note block
    ---

    noteBlock :: Monad m => RSTParser m Text
    noteBlock :: RSTParser m Text
    noteBlock = RSTParser m Text -> RSTParser m Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m Text -> RSTParser m Text)
    -> RSTParser m Text -> RSTParser m Text
    forall a b. (a -> b) -> a -> b
    $ do
      (ref :: Text
    ref, raw :: Text
    raw, replacement :: Text
    replacement) <- RSTParser m Text -> RSTParser m (Text, Text, Text)
    forall (m :: * -> *).
    Monad m =>
    RSTParser m Text -> RSTParser m (Text, Text, Text)
    noteBlock' RSTParser m Text
    forall (m :: * -> *). Monad m => RSTParser m Text
    noteMarker
      (ParserState -> ParserState) -> ParsecT Text ParserState m ()
    forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
    updateState ((ParserState -> ParserState) -> ParsecT Text ParserState m ())
    -> (ParserState -> ParserState) -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ \s :: ParserState
    s -> ParserState
    s { stateNotes :: NoteTable
    stateNotes = (Text
    ref, Text
    raw) (Text, Text) -> NoteTable -> NoteTable
    forall a. a -> [a] -> [a]
    : ParserState -> NoteTable
    stateNotes ParserState
    s }
      -- return blanks so line count isn't affected
      Text -> RSTParser m Text
    forall (m :: * -> *) a. Monad m => a -> m a
    return Text
    replacement

    citationBlock :: Monad m => RSTParser m Text
    citationBlock :: RSTParser m Text
    citationBlock = RSTParser m Text -> RSTParser m Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m Text -> RSTParser m Text)
    -> RSTParser m Text -> RSTParser m Text
    forall a b. (a -> b) -> a -> b
    $ do
      (ref :: Text
    ref, raw :: Text
    raw, replacement :: Text
    replacement) <- RSTParser m Text -> RSTParser m (Text, Text, Text)
    forall (m :: * -> *).
    Monad m =>
    RSTParser m Text -> RSTParser m (Text, Text, Text)
    noteBlock' RSTParser m Text
    forall (m :: * -> *). Monad m => RSTParser m Text
    citationMarker
      (ParserState -> ParserState) -> ParsecT Text ParserState m ()
    forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
    updateState ((ParserState -> ParserState) -> ParsecT Text ParserState m ())
    -> (ParserState -> ParserState) -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ \s :: ParserState
    s ->
         ParserState
    s { stateCitations :: Map Text Text
    stateCitations = Text -> Text -> Map Text Text -> Map Text Text
    forall k a. Ord k => k -> a -> Map k a -> Map k a
    M.insert Text
    ref Text
    raw (ParserState -> Map Text Text
    stateCitations ParserState
    s),
             stateKeys :: KeyTable
    stateKeys = Key -> ((Text, Text), Attr) -> KeyTable -> KeyTable
    forall k a. Ord k => k -> a -> Map k a -> Map k a
    M.insert (Text -> Key
    toKey Text
    ref) (("#" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    ref,""), ("",["citation"],[]))
                                   (ParserState -> KeyTable
    stateKeys ParserState
    s) }
      -- return blanks so line count isn't affected
      Text -> RSTParser m Text
    forall (m :: * -> *) a. Monad m => a -> m a
    return Text
    replacement

    noteBlock' :: Monad m
               => RSTParser m Text -> RSTParser m (Text, Text, Text)
    noteBlock' :: RSTParser m Text -> RSTParser m (Text, Text, Text)
    noteBlock' marker :: RSTParser m Text
    marker = RSTParser m (Text, Text, Text) -> RSTParser m (Text, Text, Text)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m (Text, Text, Text) -> RSTParser m (Text, Text, Text))
    -> RSTParser m (Text, Text, Text) -> RSTParser m (Text, Text, Text)
    forall a b. (a -> b) -> a -> b
    $ do
      SourcePos
    startPos <- ParsecT Text ParserState m SourcePos
    forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
    getPosition
      [Char] -> ParsecT Text ParserState m [Char]
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m [Char]
    string ".."
      ParserT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    spaceChar ParserT Text ParserState m Char
    -> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> ParserT Text ParserState m Char -> ParsecT Text ParserState m ()
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
    skipMany ParserT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    spaceChar
      Text
    ref <- RSTParser m Text
    marker
      Text
    first <- (ParserT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    spaceChar ParserT Text ParserState m Char
    -> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> ParserT Text ParserState m Char -> ParsecT Text ParserState m ()
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
    skipMany ParserT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    spaceChar ParsecT Text ParserState m ()
    -> RSTParser m Text -> RSTParser m Text
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> RSTParser m Text
    forall (m :: * -> *) st. Monad m => ParserT Text st m Text
    anyLine)
            RSTParser m Text -> RSTParser m Text -> RSTParser m Text
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> (ParserT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    newline ParserT Text ParserState m Char
    -> RSTParser m Text -> RSTParser m Text
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> Text -> RSTParser m Text
    forall (m :: * -> *) a. Monad m => a -> m a
    return "")
      Text
    blanks <- Text -> RSTParser m Text -> RSTParser m Text
    forall s (m :: * -> *) t a u.
    Stream s m t =>
    a -> ParsecT s u m a -> ParsecT s u m a
    option "" RSTParser m Text
    forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Text
    blanklines
      Text
    rest <- Text -> RSTParser m Text -> RSTParser m Text
    forall s (m :: * -> *) t a u.
    Stream s m t =>
    a -> ParsecT s u m a -> ParsecT s u m a
    option "" RSTParser m Text
    forall st (m :: * -> *).
    (HasReaderOptions st, Monad m) =>
    ParserT Text st m Text
    indentedBlock
      SourcePos
    endPos <- ParsecT Text ParserState m SourcePos
    forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
    getPosition
      let raw :: Text
    raw = Text
    first Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> "\n" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    blanks Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    rest Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> "\n"
      let replacement :: Text
    replacement = Int -> Text -> Text
    T.replicate (SourcePos -> Int
    sourceLine SourcePos
    endPos Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - SourcePos -> Int
    sourceLine SourcePos
    startPos) "\n"
      (Text, Text, Text) -> RSTParser m (Text, Text, Text)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Text
    ref, Text
    raw, Text
    replacement)

    citationMarker :: Monad m => RSTParser m Text
    citationMarker :: RSTParser m Text
    citationMarker = do
      Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '['
      Text
    res <- RSTParser m Text
    forall (m :: * -> *) st. Monad m => ParserT Text st m Text
    simpleReferenceName
      Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char ']'
      Text -> RSTParser m Text
    forall (m :: * -> *) a. Monad m => a -> m a
    return Text
    res

    noteMarker :: Monad m => RSTParser m Text
    noteMarker :: RSTParser m Text
    noteMarker = do
      Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '['
      Text
    res <- ParsecT Text ParserState m Char -> RSTParser m Text
    forall s (m :: * -> *) t st.
    Stream s m t =>
    ParserT s st m Char -> ParserT s st m Text
    many1Char ParsecT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    digit
          RSTParser m Text -> RSTParser m Text -> RSTParser m Text
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|>
                      RSTParser m Text -> RSTParser m Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '#' ParsecT Text ParserState m Char
    -> RSTParser m Text -> RSTParser m Text
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> (Text -> Text) -> RSTParser m Text -> RSTParser m Text
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM ("#" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <>) RSTParser m Text
    forall (m :: * -> *) st. Monad m => ParserT Text st m Text
    simpleReferenceName)
          RSTParser m Text -> RSTParser m Text -> RSTParser m Text
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> Int -> ParsecT Text ParserState m Char -> RSTParser m Text
    forall s (m :: * -> *) st.
    (Stream s m Char, Monad m) =>
    Int -> ParsecT s st m Char -> ParsecT s st m Text
    countChar 1 ([Char] -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m Char
    oneOf "#*")
      Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char ']'
      Text -> RSTParser m Text
    forall (m :: * -> *) a. Monad m => a -> m a
    return Text
    res

    --
    -- reference key
    --

    quotedReferenceName :: PandocMonad m => RSTParser m Text
    quotedReferenceName :: RSTParser m Text
    quotedReferenceName = RSTParser m Text -> RSTParser m Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m Text -> RSTParser m Text)
    -> RSTParser m Text -> RSTParser m Text
    forall a b. (a -> b) -> a -> b
    $ do
      Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '`' ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> ParsecT Text ParserState m Char -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) t a u.
    (Stream s m t, Show a) =>
    ParsecT s u m a -> ParsecT s u m ()
    notFollowedBy (Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '`') -- `` means inline code!
      ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m Char -> RSTParser m Text
    forall s (m :: * -> *) t st a.
    Stream s m t =>
    ParserT s st m Char -> ParserT s st m a -> ParserT s st m Text
    manyTillChar ParsecT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    anyChar (Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '`')

    -- Simple reference names are single words consisting of alphanumerics
    -- plus isolated (no two adjacent) internal hyphens, underscores,
    -- periods, colons and plus signs; no whitespace or other characters
    -- are allowed.
    simpleReferenceName :: Monad m => ParserT Text st m Text
    simpleReferenceName :: ParserT Text st m Text
    simpleReferenceName = do
      Char
    x <- ParsecT Text st m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    alphaNum
      [Char]
    xs <- ParsecT Text st m Char -> ParsecT Text st m [Char]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many (ParsecT Text st m Char -> ParsecT Text st m [Char])
    -> ParsecT Text st m Char -> ParsecT Text st m [Char]
    forall a b. (a -> b) -> a -> b
    $  ParsecT Text st m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    alphaNum
                ParsecT Text st m Char
    -> ParsecT Text st m Char -> ParsecT Text st m Char
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT Text st m Char -> ParsecT Text st m Char
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try ([Char] -> ParsecT Text st m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m Char
    oneOf "-_:+." ParsecT Text st m Char
    -> ParsecT Text st m Char -> ParsecT Text st m Char
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <* ParsecT Text st m Char -> ParsecT Text st m Char
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m a
    lookAhead ParsecT Text st m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    alphaNum)
      Text -> ParserT Text st m Text
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Text -> ParserT Text st m Text) -> Text -> ParserT Text st m Text
    forall a b. (a -> b) -> a -> b
    $ [Char] -> Text
    T.pack (Char
    xChar -> [Char] -> [Char]
    forall a. a -> [a] -> [a]
    :[Char]
    xs)

    referenceName :: PandocMonad m => RSTParser m Text
    referenceName :: RSTParser m Text
    referenceName = RSTParser m Text
    forall (m :: * -> *). PandocMonad m => RSTParser m Text
    quotedReferenceName RSTParser m Text -> RSTParser m Text -> RSTParser m Text
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> RSTParser m Text
    forall (m :: * -> *) st. Monad m => ParserT Text st m Text
    simpleReferenceName

    referenceKey :: PandocMonad m => RSTParser m Text
    referenceKey :: RSTParser m Text
    referenceKey = do
      SourcePos
    startPos <- ParsecT Text ParserState m SourcePos
    forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
    getPosition
      [ParsecT Text ParserState m ()] -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    [ParsecT s u m a] -> ParsecT s u m a
    choice [ParsecT Text ParserState m ()
    forall (m :: * -> *). PandocMonad m => RSTParser m ()
    substKey, ParsecT Text ParserState m ()
    forall (m :: * -> *). Monad m => RSTParser m ()
    anonymousKey, ParsecT Text ParserState m ()
    forall (m :: * -> *). PandocMonad m => RSTParser m ()
    regularKey]
      RSTParser m Text -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m ()
    optional RSTParser m Text
    forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Text
    blanklines
      SourcePos
    endPos <- ParsecT Text ParserState m SourcePos
    forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
    getPosition
      -- return enough blanks to replace key
      Text -> RSTParser m Text
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Text -> RSTParser m Text) -> Text -> RSTParser m Text
    forall a b. (a -> b) -> a -> b
    $ Int -> Text -> Text
    T.replicate (SourcePos -> Int
    sourceLine SourcePos
    endPos Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - SourcePos -> Int
    sourceLine SourcePos
    startPos) "\n"

    targetURI :: Monad m => ParserT Text st m Text
    targetURI :: ParserT Text st m Text
    targetURI = do
      ParserT Text st m ()
    forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
    skipSpaces
      ParserT Text st m () -> ParserT Text st m ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m ()
    optional (ParserT Text st m () -> ParserT Text st m ())
    -> ParserT Text st m () -> ParserT Text st m ()
    forall a b. (a -> b) -> a -> b
    $ ParserT Text st m () -> ParserT Text st m ()
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParserT Text st m () -> ParserT Text st m ())
    -> ParserT Text st m () -> ParserT Text st m ()
    forall a b. (a -> b) -> a -> b
    $ ParsecT Text st m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    newline ParsecT Text st m Char
    -> ParserT Text st m () -> ParserT Text st m ()
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> ParsecT Text st m Char -> ParserT Text st m ()
    forall s (m :: * -> *) t a u.
    (Stream s m t, Show a) =>
    ParsecT s u m a -> ParsecT s u m ()
    notFollowedBy ParsecT Text st m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    blankline
      Text
    contents <- Text -> Text
    trim (Text -> Text) -> ParserT Text st m Text -> ParserT Text st m Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$>
         ParsecT Text st m Char -> ParserT Text st m Text
    forall s (m :: * -> *) t st.
    Stream s m t =>
    ParserT s st m Char -> ParserT s st m Text
    many1Char ((Char -> Bool) -> ParsecT Text st m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    (Char -> Bool) -> ParsecT s u m Char
    satisfy (Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    /='\n')
         ParsecT Text st m Char
    -> ParsecT Text st m Char -> ParsecT Text st m Char
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT Text st m Char -> ParsecT Text st m Char
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Text st m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    newline ParsecT Text st m Char
    -> ParsecT Text st m [Char] -> ParsecT Text st m [Char]
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> ParsecT Text st m Char -> ParsecT Text st m [Char]
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m [a]
    many1 ParsecT Text st m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    spaceChar ParsecT Text st m [Char]
    -> ParsecT Text st m Char -> ParsecT Text st m Char
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> [Char] -> ParsecT Text st m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m Char
    noneOf " \t\n"))
      ParserT Text st m Text
    forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Text
    blanklines
      Text -> ParserT Text st m Text
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Text -> ParserT Text st m Text) -> Text -> ParserT Text st m Text
    forall a b. (a -> b) -> a -> b
    $ Text -> Text
    stripBackticks Text
    contents
      where
        stripBackticks :: Text -> Text
    stripBackticks t :: Text
    t
          | Just xs :: Text
    xs <- Text -> Text -> Maybe Text
    T.stripSuffix "`_" Text
    t = (Char -> Bool) -> Text -> Text
    T.dropWhile (Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    =='`') Text
    xs Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> "_"
          | Just _  <- Text -> Text -> Maybe Text
    T.stripSuffix "_"  Text
    t = Text
    t
          | Bool
    otherwise                       = Text -> Text
    escapeURI Text
    t

    substKey :: PandocMonad m => RSTParser m ()
    substKey :: RSTParser m ()
    substKey = RSTParser m () -> RSTParser m ()
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m () -> RSTParser m ())
    -> RSTParser m () -> RSTParser m ()
    forall a b. (a -> b) -> a -> b
    $ do
      [Char] -> ParsecT Text ParserState m [Char]
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m [Char]
    string ".."
      ParsecT Text ParserState m Char -> RSTParser m ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m ()
    skipMany1 ParsecT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    spaceChar
      (alt :: Many Inline
    alt,ref :: Text
    ref) <- ParsecT Text ParserState m (Many Inline)
    -> ParsecT Text ParserState m (Many Inline, Text)
    forall (m :: * -> *) st a.
    Monad m =>
    ParsecT Text st m a -> ParsecT Text st m (a, Text)
    withRaw (ParsecT Text ParserState m (Many Inline)
     -> ParsecT Text ParserState m (Many Inline, Text))
    -> ParsecT Text ParserState m (Many Inline)
    -> ParsecT Text ParserState m (Many Inline, Text)
    forall a b. (a -> b) -> a -> b
    $ Many Inline -> Many Inline
    trimInlines (Many Inline -> Many Inline)
    -> ([Many Inline] -> Many Inline) -> [Many Inline] -> Many Inline
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Many Inline] -> Many Inline
    forall a. Monoid a => [a] -> a
    mconcat
                          ([Many Inline] -> Many Inline)
    -> ParsecT Text ParserState m [Many Inline]
    -> ParsecT Text ParserState m (Many Inline)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m (Many Inline)
    -> ParsecT Text ParserState m [Many Inline]
    forall end s (m :: * -> *) st t a.
    (Show end, Stream s m Char) =>
    ParserT s st m t
    -> ParserT s st m end -> ParserT s st m a -> ParserT s st m [a]
    enclosed (Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '|') (Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '|') ParsecT Text ParserState m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    inline
      [Block]
    res <- Blocks -> [Block]
    forall a. Many a -> [a]
    B.toList (Blocks -> [Block])
    -> ParsecT Text ParserState m Blocks
    -> ParsecT Text ParserState m [Block]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Text ParserState m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    directive'
      Many Inline
    il <- case [Block]
    res of
                 -- use alt unless :alt: attribute on image:
                 [Para [Image attr :: Attr
    attr [Str "image"] (src :: Text
    src,tit :: Text
    tit)]] ->
                    Many Inline -> ParsecT Text ParserState m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline -> ParsecT Text ParserState m (Many Inline))
    -> Many Inline -> ParsecT Text ParserState m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ Attr -> Text -> Text -> Many Inline -> Many Inline
    B.imageWith Attr
    attr Text
    src Text
    tit Many Inline
    alt
                 [Para [Link _ [Image attr :: Attr
    attr [Str "image"] (src :: Text
    src,tit :: Text
    tit)] (src' :: Text
    src',tit' :: Text
    tit')]] ->
                    Many Inline -> ParsecT Text ParserState m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline -> ParsecT Text ParserState m (Many Inline))
    -> Many Inline -> ParsecT Text ParserState m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ Text -> Text -> Many Inline -> Many Inline
    B.link Text
    src' Text
    tit' (Attr -> Text -> Text -> Many Inline -> Many Inline
    B.imageWith Attr
    attr Text
    src Text
    tit Many Inline
    alt)
                 [Para ils :: [Inline]
    ils] -> Many Inline -> ParsecT Text ParserState m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline -> ParsecT Text ParserState m (Many Inline))
    -> Many Inline -> ParsecT Text ParserState m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ [Inline] -> Many Inline
    forall a. [a] -> Many a
    B.fromList [Inline]
    ils
                 _          -> ParsecT Text ParserState m (Many Inline)
    forall (m :: * -> *) a. MonadPlus m => m a
    mzero
      let key :: Key
    key = Text -> Key
    toKey (Text -> Key) -> Text -> Key
    forall a b. (a -> b) -> a -> b
    $ Text -> Text
    stripFirstAndLast Text
    ref
      (ParserState -> ParserState) -> RSTParser m ()
    forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
    updateState ((ParserState -> ParserState) -> RSTParser m ())
    -> (ParserState -> ParserState) -> RSTParser m ()
    forall a b. (a -> b) -> a -> b
    $ \s :: ParserState
    s -> ParserState
    s{ stateSubstitutions :: SubstTable
    stateSubstitutions =
                              Key -> Many Inline -> SubstTable -> SubstTable
    forall k a. Ord k => k -> a -> Map k a -> Map k a
    M.insert Key
    key Many Inline
    il (SubstTable -> SubstTable) -> SubstTable -> SubstTable
    forall a b. (a -> b) -> a -> b
    $ ParserState -> SubstTable
    stateSubstitutions ParserState
    s }

    anonymousKey :: Monad m => RSTParser m ()
    anonymousKey :: RSTParser m ()
    anonymousKey = RSTParser m () -> RSTParser m ()
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m () -> RSTParser m ())
    -> RSTParser m () -> RSTParser m ()
    forall a b. (a -> b) -> a -> b
    $ do
      [Text] -> ParserT Text ParserState m Text
    forall s (m :: * -> *) st.
    Stream s m Char =>
    [Text] -> ParserT s st m Text
    oneOfStrings [".. __:", "__"]
      Text
    src <- ParserT Text ParserState m Text
    forall (m :: * -> *) st. Monad m => ParserT Text st m Text
    targetURI
      SourcePos
    pos <- ParsecT Text ParserState m SourcePos
    forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
    getPosition
      let key :: Key
    key = Text -> Key
    toKey (Text -> Key) -> Text -> Key
    forall a b. (a -> b) -> a -> b
    $ "_" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> [Char] -> Text
    T.pack ([Char] -> Int -> [Char]
    forall r. PrintfType r => [Char] -> r
    printf "%09d" (SourcePos -> Int
    sourceLine SourcePos
    pos))
      (ParserState -> ParserState) -> RSTParser m ()
    forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
    updateState ((ParserState -> ParserState) -> RSTParser m ())
    -> (ParserState -> ParserState) -> RSTParser m ()
    forall a b. (a -> b) -> a -> b
    $ \s :: ParserState
    s -> ParserState
    s { stateKeys :: KeyTable
    stateKeys = Key -> ((Text, Text), Attr) -> KeyTable -> KeyTable
    forall k a. Ord k => k -> a -> Map k a -> Map k a
    M.insert Key
    key ((Text
    src,""), Attr
    nullAttr) (KeyTable -> KeyTable) -> KeyTable -> KeyTable
    forall a b. (a -> b) -> a -> b
    $
                              ParserState -> KeyTable
    stateKeys ParserState
    s }

    referenceNames :: PandocMonad m => RSTParser m [Text]
    referenceNames :: RSTParser m [Text]
    referenceNames = do
      let rn :: ParsecT Text ParserState m Text
    rn = ParsecT Text ParserState m Text -> ParsecT Text ParserState m Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Text ParserState m Text
     -> ParsecT Text ParserState m Text)
    -> ParsecT Text ParserState m Text
    -> ParsecT Text ParserState m Text
    forall a b. (a -> b) -> a -> b
    $ do
                 [Char] -> ParsecT Text ParserState m [Char]
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m [Char]
    string ".. _"
                 Text
    ref <- ParsecT Text ParserState m Text
    forall (m :: * -> *). PandocMonad m => RSTParser m Text
    quotedReferenceName
                      ParsecT Text ParserState m Text
    -> ParsecT Text ParserState m Text
    -> ParsecT Text ParserState m Text
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParserT Text ParserState m Char -> ParsecT Text ParserState m Text
    forall s (m :: * -> *) t st.
    Stream s m t =>
    ParserT s st m Char -> ParserT s st m Text
    manyChar (  [Char] -> ParserT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m Char
    noneOf ":\n"
                                  ParserT Text ParserState m Char
    -> ParserT Text ParserState m Char
    -> ParserT Text ParserState m Char
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParserT Text ParserState m Char -> ParserT Text ParserState m Char
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (Char -> ParserT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '\n' ParserT Text ParserState m Char
    -> ParsecT Text ParserState m [Char]
    -> ParserT Text ParserState m Char
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <*
                                           [Char] -> ParsecT Text ParserState m [Char]
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m [Char]
    string "   " ParserT Text ParserState m Char
    -> ParsecT Text ParserState m () -> ParserT Text ParserState m Char
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <*
                                           ParserT Text ParserState m Char -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) t a u.
    (Stream s m t, Show a) =>
    ParsecT s u m a -> ParsecT s u m ()
    notFollowedBy ParserT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    blankline)
                                  ParserT Text ParserState m Char
    -> ParserT Text ParserState m Char
    -> ParserT Text ParserState m Char
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParserT Text ParserState m Char -> ParserT Text ParserState m Char
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (Char -> ParserT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char ':' ParserT Text ParserState m Char
    -> ParserT Text ParserState m Char
    -> ParserT Text ParserState m Char
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <* ParserT Text ParserState m Char -> ParserT Text ParserState m Char
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m a
    lookAhead ParserT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    alphaNum)
                                   )
                 Char -> ParserT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char ':'
                 Text -> ParsecT Text ParserState m Text
    forall (m :: * -> *) a. Monad m => a -> m a
    return Text
    ref
      Text
    first <- ParsecT Text ParserState m Text
    rn
      [Text]
    rest  <- ParsecT Text ParserState m Text -> RSTParser m [Text]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many (ParsecT Text ParserState m Text -> ParsecT Text ParserState m Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Text ParserState m Text
    forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Text
    blanklines ParsecT Text ParserState m Text
    -> ParsecT Text ParserState m Text
    -> ParsecT Text ParserState m Text
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> ParsecT Text ParserState m Text
    rn))
      [Text] -> RSTParser m [Text]
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Text
    firstText -> [Text] -> [Text]
    forall a. a -> [a] -> [a]
    :[Text]
    rest)

    regularKey :: PandocMonad m => RSTParser m ()
    regularKey :: RSTParser m ()
    regularKey = RSTParser m () -> RSTParser m ()
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m () -> RSTParser m ())
    -> RSTParser m () -> RSTParser m ()
    forall a b. (a -> b) -> a -> b
    $ do
      -- we allow several references to the same URL, e.g.
      -- .. _hello:
      -- .. _goodbye: url.com
      [Text]
    refs <- RSTParser m [Text]
    forall (m :: * -> *). PandocMonad m => RSTParser m [Text]
    referenceNames
      Text
    src <- ParserT Text ParserState m Text
    forall (m :: * -> *) st. Monad m => ParserT Text st m Text
    targetURI
      Bool -> RSTParser m ()
    forall (f :: * -> *). Alternative f => Bool -> f ()
    guard (Bool -> RSTParser m ()) -> Bool -> RSTParser m ()
    forall a b. (a -> b) -> a -> b
    $ Bool -> Bool
    not (Text -> Bool
    T.null Text
    src)
      let keys :: [Key]
    keys = (Text -> Key) -> [Text] -> [Key]
    forall a b. (a -> b) -> [a] -> [b]
    map Text -> Key
    toKey [Text]
    refs
      [Key] -> (Key -> RSTParser m ()) -> RSTParser m ()
    forall (t :: * -> *) (m :: * -> *) a b.
    (Foldable t, Monad m) =>
    t a -> (a -> m b) -> m ()
    forM_ [Key]
    keys ((Key -> RSTParser m ()) -> RSTParser m ())
    -> (Key -> RSTParser m ()) -> RSTParser m ()
    forall a b. (a -> b) -> a -> b
    $ \key :: Key
    key ->
        (ParserState -> ParserState) -> RSTParser m ()
    forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
    updateState ((ParserState -> ParserState) -> RSTParser m ())
    -> (ParserState -> ParserState) -> RSTParser m ()
    forall a b. (a -> b) -> a -> b
    $ \s :: ParserState
    s -> ParserState
    s { stateKeys :: KeyTable
    stateKeys = Key -> ((Text, Text), Attr) -> KeyTable -> KeyTable
    forall k a. Ord k => k -> a -> Map k a -> Map k a
    M.insert Key
    key ((Text
    src,""), Attr
    nullAttr) (KeyTable -> KeyTable) -> KeyTable -> KeyTable
    forall a b. (a -> b) -> a -> b
    $
                                ParserState -> KeyTable
    stateKeys ParserState
    s }

    anchorDef :: PandocMonad m => RSTParser m Text
    anchorDef :: RSTParser m Text
    anchorDef = RSTParser m Text -> RSTParser m Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m Text -> RSTParser m Text)
    -> RSTParser m Text -> RSTParser m Text
    forall a b. (a -> b) -> a -> b
    $ do
      (refs :: [Text]
    refs, raw :: Text
    raw) <- ParsecT Text ParserState m [Text]
    -> ParsecT Text ParserState m ([Text], Text)
    forall (m :: * -> *) st a.
    Monad m =>
    ParsecT Text st m a -> ParsecT Text st m (a, Text)
    withRaw (ParsecT Text ParserState m [Text]
     -> ParsecT Text ParserState m ([Text], Text))
    -> ParsecT Text ParserState m [Text]
    -> ParsecT Text ParserState m ([Text], Text)
    forall a b. (a -> b) -> a -> b
    $ ParsecT Text ParserState m [Text]
    -> ParsecT Text ParserState m [Text]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParsecT Text ParserState m [Text]
    forall (m :: * -> *). PandocMonad m => RSTParser m [Text]
    referenceNames ParsecT Text ParserState m [Text]
    -> RSTParser m Text -> ParsecT Text ParserState m [Text]
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <* RSTParser m Text
    forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Text
    blanklines)
      [Text]
    -> (Text -> ParsecT Text ParserState m ())
    -> ParsecT Text ParserState m ()
    forall (t :: * -> *) (m :: * -> *) a b.
    (Foldable t, Monad m) =>
    t a -> (a -> m b) -> m ()
    forM_ [Text]
    refs ((Text -> ParsecT Text ParserState m ())
     -> ParsecT Text ParserState m ())
    -> (Text -> ParsecT Text ParserState m ())
    -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ \rawkey :: Text
    rawkey ->
        (ParserState -> ParserState) -> ParsecT Text ParserState m ()
    forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
    updateState ((ParserState -> ParserState) -> ParsecT Text ParserState m ())
    -> (ParserState -> ParserState) -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ \s :: ParserState
    s -> ParserState
    s { stateKeys :: KeyTable
    stateKeys =
           Key -> ((Text, Text), Attr) -> KeyTable -> KeyTable
    forall k a. Ord k => k -> a -> Map k a -> Map k a
    M.insert (Text -> Key
    toKey Text
    rawkey) (("#" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    rawkey,""), Attr
    nullAttr) (KeyTable -> KeyTable) -> KeyTable -> KeyTable
    forall a b. (a -> b) -> a -> b
    $ ParserState -> KeyTable
    stateKeys ParserState
    s }
      -- keep this for 2nd round of parsing, where we'll add the divs (anchor)
      Text -> RSTParser m Text
    forall (m :: * -> *) a. Monad m => a -> m a
    return Text
    raw

    anchor :: PandocMonad m => RSTParser m Blocks
    anchor :: RSTParser m Blocks
    anchor = RSTParser m Blocks -> RSTParser m Blocks
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m Blocks -> RSTParser m Blocks)
    -> RSTParser m Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ do
      [Text]
    refs <- RSTParser m [Text]
    forall (m :: * -> *). PandocMonad m => RSTParser m [Text]
    referenceNames
      ParserT Text ParserState m Text
    forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Text
    blanklines
      Blocks
    b <- RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    block
      let addDiv :: Text -> Blocks -> Blocks
    addDiv ref :: Text
    ref = Attr -> Blocks -> Blocks
    B.divWith (Text
    ref, [], [])
      let emptySpanWithId :: Text -> Inline
    emptySpanWithId id' :: Text
    id' = Attr -> [Inline] -> Inline
    Span (Text
    id',[],[]) []
      -- put identifier on next block:
      case Blocks -> [Block]
    forall a. Many a -> [a]
    B.toList Blocks
    b of
           [Header lev :: Int
    lev (_,classes :: [Text]
    classes,kvs :: NoteTable
    kvs) txt :: [Inline]
    txt] ->
             case [Text] -> [Text]
    forall a. [a] -> [a]
    reverse [Text]
    refs of
                  [] -> Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return Blocks
    b
                  (r :: Text
    r:rs :: [Text]
    rs) -> Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> RSTParser m Blocks) -> Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ Block -> Blocks
    forall a. a -> Many a
    B.singleton (Block -> Blocks) -> Block -> Blocks
    forall a b. (a -> b) -> a -> b
    $
                               Int -> Attr -> [Inline] -> Block
    Header Int
    lev (Text
    r,[Text]
    classes,NoteTable
    kvs)
                                 ([Inline]
    txt [Inline] -> [Inline] -> [Inline]
    forall a. [a] -> [a] -> [a]
    ++ (Text -> Inline) -> [Text] -> [Inline]
    forall a b. (a -> b) -> [a] -> [b]
    map Text -> Inline
    emptySpanWithId [Text]
    rs)
                    -- we avoid generating divs for headers,
                    -- because it hides them from promoteHeader, see #4240
           _ -> Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> RSTParser m Blocks) -> Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ (Text -> Blocks -> Blocks) -> Blocks -> [Text] -> Blocks
    forall (t :: * -> *) a b.
    Foldable t =>
    (a -> b -> b) -> b -> t a -> b
    foldr Text -> Blocks -> Blocks
    addDiv Blocks
    b [Text]
    refs

    headerBlock :: PandocMonad m => RSTParser m Text
    headerBlock :: RSTParser m Text
    headerBlock = do
      ((txt :: Many Inline
    txt, _), raw :: Text
    raw) <- ParsecT Text ParserState m (Many Inline, Char)
    -> ParsecT Text ParserState m ((Many Inline, Char), Text)
    forall (m :: * -> *) st a.
    Monad m =>
    ParsecT Text st m a -> ParsecT Text st m (a, Text)
    withRaw (ParsecT Text ParserState m (Many Inline, Char)
    forall (m :: * -> *).
    PandocMonad m =>
    RSTParser m (Many Inline, Char)
    doubleHeader' ParsecT Text ParserState m (Many Inline, Char)
    -> ParsecT Text ParserState m (Many Inline, Char)
    -> ParsecT Text ParserState m (Many Inline, Char)
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT Text ParserState m (Many Inline, Char)
    forall (m :: * -> *).
    PandocMonad m =>
    RSTParser m (Many Inline, Char)
    singleHeader')
      (ident :: Text
    ident,_,_) <- Attr -> Many Inline -> ParserT Text ParserState m Attr
    forall s (m :: * -> *) a st.
    (Stream s m a, HasReaderOptions st, HasLogMessages st,
     HasIdentifierList st) =>
    Attr -> Many Inline -> ParserT s st m Attr
    registerHeader Attr
    nullAttr Many Inline
    txt
      let key :: Key
    key = Text -> Key
    toKey (Many Inline -> Text
    forall a. Walkable Inline a => a -> Text
    stringify Many Inline
    txt)
      (ParserState -> ParserState) -> ParsecT Text ParserState m ()
    forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
    updateState ((ParserState -> ParserState) -> ParsecT Text ParserState m ())
    -> (ParserState -> ParserState) -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ \s :: ParserState
    s -> ParserState
    s { stateKeys :: KeyTable
    stateKeys = Key -> ((Text, Text), Attr) -> KeyTable -> KeyTable
    forall k a. Ord k => k -> a -> Map k a -> Map k a
    M.insert Key
    key (("#" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    ident,""), Attr
    nullAttr)
                              (KeyTable -> KeyTable) -> KeyTable -> KeyTable
    forall a b. (a -> b) -> a -> b
    $ ParserState -> KeyTable
    stateKeys ParserState
    s }
      Text -> RSTParser m Text
    forall (m :: * -> *) a. Monad m => a -> m a
    return Text
    raw

    --
    -- tables
    --

    -- General tables TODO:
    --  - figure out if leading spaces are acceptable and if so, add
    --    support for them
    --
    -- Simple tables TODO:
    --  - column spans
    --  - multiline support
    --  - ensure that rightmost column span does not need to reach end
    --  - require at least 2 columns
    --
    -- Grid tables TODO:
    --  - column spans

    dashedLine :: Monad m => Char -> ParserT Text st m (Int, Int)
    dashedLine :: Char -> ParserT Text st m (Int, Int)
    dashedLine ch :: Char
    ch = do
      [Char]
    dashes <- ParsecT Text st m Char -> ParsecT Text st m [Char]
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m [a]
    many1 (Char -> ParsecT Text st m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char Char
    ch)
      [Char]
    sp     <- ParsecT Text st m Char -> ParsecT Text st m [Char]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many (Char -> ParsecT Text st m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char ' ')
      (Int, Int) -> ParserT Text st m (Int, Int)
    forall (m :: * -> *) a. Monad m => a -> m a
    return ([Char] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length [Char]
    dashes, [Char] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length ([Char] -> Int) -> [Char] -> Int
    forall a b. (a -> b) -> a -> b
    $ [Char]
    dashes [Char] -> [Char] -> [Char]
    forall a. [a] -> [a] -> [a]
    ++ [Char]
    sp)

    simpleDashedLines :: Monad m => Char -> ParserT Text st m [(Int,Int)]
    simpleDashedLines :: Char -> ParserT Text st m [(Int, Int)]
    simpleDashedLines ch :: Char
    ch = ParserT Text st m [(Int, Int)] -> ParserT Text st m [(Int, Int)]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParserT Text st m [(Int, Int)] -> ParserT Text st m [(Int, Int)])
    -> ParserT Text st m [(Int, Int)] -> ParserT Text st m [(Int, Int)]
    forall a b. (a -> b) -> a -> b
    $ ParsecT Text st m (Int, Int) -> ParserT Text st m [(Int, Int)]
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m [a]
    many1 (Char -> ParsecT Text st m (Int, Int)
    forall (m :: * -> *) st.
    Monad m =>
    Char -> ParserT Text st m (Int, Int)
    dashedLine Char
    ch)

    -- Parse a table row separator
    simpleTableSep :: Monad m => Char -> RSTParser m Char
    simpleTableSep :: Char -> RSTParser m Char
    simpleTableSep ch :: Char
    ch = RSTParser m Char -> RSTParser m Char
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m Char -> RSTParser m Char)
    -> RSTParser m Char -> RSTParser m Char
    forall a b. (a -> b) -> a -> b
    $ Char -> ParserT Text ParserState m [(Int, Int)]
    forall (m :: * -> *) st.
    Monad m =>
    Char -> ParserT Text st m [(Int, Int)]
    simpleDashedLines Char
    ch ParserT Text ParserState m [(Int, Int)]
    -> RSTParser m Char -> RSTParser m Char
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> RSTParser m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    newline

    -- Parse a table footer
    simpleTableFooter :: Monad m => RSTParser m Text
    simpleTableFooter :: RSTParser m Text
    simpleTableFooter = RSTParser m Text -> RSTParser m Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m Text -> RSTParser m Text)
    -> RSTParser m Text -> RSTParser m Text
    forall a b. (a -> b) -> a -> b
    $ Char -> RSTParser m Char
    forall (m :: * -> *). Monad m => Char -> RSTParser m Char
    simpleTableSep '=' RSTParser m Char -> RSTParser m Text -> RSTParser m Text
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> RSTParser m Text
    forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Text
    blanklines

    -- Parse a raw line and split it into chunks by indices.
    simpleTableRawLine :: Monad m => [Int] -> RSTParser m [Text]
    simpleTableRawLine :: [Int] -> RSTParser m [Text]
    simpleTableRawLine indices :: [Int]
    indices = [Int] -> Text -> [Text]
    simpleTableSplitLine [Int]
    indices (Text -> [Text])
    -> ParsecT Text ParserState m Text -> RSTParser m [Text]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Text ParserState m Text
    forall (m :: * -> *) st. Monad m => ParserT Text st m Text
    anyLine

    simpleTableRawLineWithEmptyCell :: Monad m => [Int] -> RSTParser m [Text]
    simpleTableRawLineWithEmptyCell :: [Int] -> RSTParser m [Text]
    simpleTableRawLineWithEmptyCell indices :: [Int]
    indices = RSTParser m [Text] -> RSTParser m [Text]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m [Text] -> RSTParser m [Text])
    -> RSTParser m [Text] -> RSTParser m [Text]
    forall a b. (a -> b) -> a -> b
    $ do
      [Text]
    cs <- [Int] -> RSTParser m [Text]
    forall (m :: * -> *). Monad m => [Int] -> RSTParser m [Text]
    simpleTableRawLine [Int]
    indices
      let isEmptyCell :: Text -> Bool
    isEmptyCell = (Char -> Bool) -> Text -> Bool
    T.all (\c :: Char
    c -> Char
    c Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    == ' ' Bool -> Bool -> Bool
    || Char
    c Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    == '\t')
      Bool -> ParsecT Text ParserState m ()
    forall (f :: * -> *). Alternative f => Bool -> f ()
    guard (Bool -> ParsecT Text ParserState m ())
    -> Bool -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ (Text -> Bool) -> [Text] -> Bool
    forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
    any Text -> Bool
    isEmptyCell [Text]
    cs
      [Text] -> RSTParser m [Text]
    forall (m :: * -> *) a. Monad m => a -> m a
    return [Text]
    cs

    -- Parse a table row and return a list of blocks (columns).
    simpleTableRow :: PandocMonad m => [Int] -> RSTParser m [Blocks]
    simpleTableRow :: [Int] -> RSTParser m [Blocks]
    simpleTableRow indices :: [Int]
    indices = do
      ParserT Text ParserState m Text -> ParserT Text ParserState m ()
    forall b s (m :: * -> *) a st.
    (Show b, Stream s m a) =>
    ParserT s st m b -> ParserT s st m ()
    notFollowedBy' ParserT Text ParserState m Text
    forall (m :: * -> *). Monad m => RSTParser m Text
    simpleTableFooter
      [Text]
    firstLine <- [Int] -> RSTParser m [Text]
    forall (m :: * -> *). Monad m => [Int] -> RSTParser m [Text]
    simpleTableRawLine [Int]
    indices
      [[Text]]
    conLines  <- RSTParser m [Text] -> ParsecT Text ParserState m [[Text]]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many (RSTParser m [Text] -> ParsecT Text ParserState m [[Text]])
    -> RSTParser m [Text] -> ParsecT Text ParserState m [[Text]]
    forall a b. (a -> b) -> a -> b
    $ [Int] -> RSTParser m [Text]
    forall (m :: * -> *). Monad m => [Int] -> RSTParser m [Text]
    simpleTableRawLineWithEmptyCell [Int]
    indices
      let cols :: [Text]
    cols = ([Text] -> Text) -> [[Text]] -> [Text]
    forall a b. (a -> b) -> [a] -> [b]
    map [Text] -> Text
    T.unlines ([[Text]] -> [Text])
    -> ([[Text]] -> [[Text]]) -> [[Text]] -> [Text]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [[Text]] -> [[Text]]
    forall a. [[a]] -> [[a]]
    transpose ([[Text]] -> [Text]) -> [[Text]] -> [Text]
    forall a b. (a -> b) -> a -> b
    $ [Text]
    firstLine [Text] -> [[Text]] -> [[Text]]
    forall a. a -> [a] -> [a]
    : [[Text]]
    conLines [[Text]] -> [[Text]] -> [[Text]]
    forall a. [a] -> [a] -> [a]
    ++
                                      [Int -> Text -> [Text]
    forall a. Int -> a -> [a]
    replicate ([Int] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length [Int]
    indices) ""
                                        | Bool -> Bool
    not ([[Text]] -> Bool
    forall (t :: * -> *) a. Foldable t => t a -> Bool
    null [[Text]]
    conLines)]
      (Text -> ParsecT Text ParserState m Blocks)
    -> [Text] -> RSTParser m [Blocks]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    mapM (ParsecT Text ParserState m Blocks
    -> Text -> ParsecT Text ParserState m Blocks
    forall s (m :: * -> *) u a.
    (Stream s m Char, IsString s, HasLastStrPosition u) =>
    ParserT s u m a -> Text -> ParserT s u m a
    parseFromString' ParsecT Text ParserState m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    parseBlocks) [Text]
    cols

    simpleTableSplitLine :: [Int] -> Text -> [Text]
    simpleTableSplitLine :: [Int] -> Text -> [Text]
    simpleTableSplitLine indices :: [Int]
    indices line :: Text
    line =
      (Text -> Text) -> [Text] -> [Text]
    forall a b. (a -> b) -> [a] -> [b]
    map Text -> Text
    trimr
      ([Text] -> [Text]) -> [Text] -> [Text]
    forall a b. (a -> b) -> a -> b
    $ [Text] -> [Text]
    forall a. [a] -> [a]
    tail ([Text] -> [Text]) -> [Text] -> [Text]
    forall a b. (a -> b) -> a -> b
    $ [Int] -> Text -> [Text]
    splitTextByIndices ([Int] -> [Int]
    forall a. [a] -> [a]
    init [Int]
    indices) Text
    line

    simpleTableHeader :: PandocMonad m
                      => Bool  -- ^ Headerless table
                      -> RSTParser m ([Blocks], [Alignment], [Int])
    simpleTableHeader :: Bool -> RSTParser m ([Blocks], [Alignment], [Int])
    simpleTableHeader headless :: Bool
    headless = RSTParser m ([Blocks], [Alignment], [Int])
    -> RSTParser m ([Blocks], [Alignment], [Int])
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m ([Blocks], [Alignment], [Int])
     -> RSTParser m ([Blocks], [Alignment], [Int]))
    -> RSTParser m ([Blocks], [Alignment], [Int])
    -> RSTParser m ([Blocks], [Alignment], [Int])
    forall a b. (a -> b) -> a -> b
    $ do
      ParsecT Text ParserState m Text -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m ()
    optional ParsecT Text ParserState m Text
    forall s (m :: * -> *) st. Stream s m Char => ParserT s st m Text
    blanklines
      Text
    rawContent  <- if Bool
    headless
                        then Text -> ParsecT Text ParserState m Text
    forall (m :: * -> *) a. Monad m => a -> m a
    return ""
                        else Char -> RSTParser m Char
    forall (m :: * -> *). Monad m => Char -> RSTParser m Char
    simpleTableSep '=' RSTParser m Char
    -> ParsecT Text ParserState m Text
    -> ParsecT Text ParserState m Text
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> ParsecT Text ParserState m Text
    forall (m :: * -> *) st. Monad m => ParserT Text st m Text
    anyLine
      [(Int, Int)]
    dashes      <- if Bool
    headless
                        then Char -> ParserT Text ParserState m [(Int, Int)]
    forall (m :: * -> *) st.
    Monad m =>
    Char -> ParserT Text st m [(Int, Int)]
    simpleDashedLines '='
                        else Char -> ParserT Text ParserState m [(Int, Int)]
    forall (m :: * -> *) st.
    Monad m =>
    Char -> ParserT Text st m [(Int, Int)]
    simpleDashedLines '=' ParserT Text ParserState m [(Int, Int)]
    -> ParserT Text ParserState m [(Int, Int)]
    -> ParserT Text ParserState m [(Int, Int)]
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> Char -> ParserT Text ParserState m [(Int, Int)]
    forall (m :: * -> *) st.
    Monad m =>
    Char -> ParserT Text st m [(Int, Int)]
    simpleDashedLines '-'
      RSTParser m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    newline
      let lines' :: [Int]
    lines'   = ((Int, Int) -> Int) -> [(Int, Int)] -> [Int]
    forall a b. (a -> b) -> [a] -> [b]
    map (Int, Int) -> Int
    forall a b. (a, b) -> b
    snd [(Int, Int)]
    dashes
      let indices :: [Int]
    indices  = (Int -> Int -> Int) -> Int -> [Int] -> [Int]
    forall b a. (b -> a -> b) -> b -> [a] -> [b]
    scanl Int -> Int -> Int
    forall a. Num a => a -> a -> a
    (+) 0 [Int]
    lines'
      let aligns :: [Alignment]
    aligns   = Int -> Alignment -> [Alignment]
    forall a. Int -> a -> [a]
    replicate ([Int] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length [Int]
    lines') Alignment
    AlignDefault
      let rawHeads :: [Text]
    rawHeads = if Bool
    headless
                        then Int -> Text -> [Text]
    forall a. Int -> a -> [a]
    replicate ([(Int, Int)] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length [(Int, Int)]
    dashes) ""
                        else [Int] -> Text -> [Text]
    simpleTableSplitLine [Int]
    indices Text
    rawContent
      [Blocks]
    heads <- (Text -> ParsecT Text ParserState m Blocks)
    -> [Text] -> ParsecT Text ParserState m [Blocks]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    mapM ( ParsecT Text ParserState m Blocks
    -> Text -> ParsecT Text ParserState m Blocks
    forall s (m :: * -> *) u a.
    (Stream s m Char, IsString s, HasLastStrPosition u) =>
    ParserT s u m a -> Text -> ParserT s u m a
    parseFromString' ([Blocks] -> Blocks
    forall a. Monoid a => [a] -> a
    mconcat ([Blocks] -> Blocks)
    -> ParsecT Text ParserState m [Blocks]
    -> ParsecT Text ParserState m Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Text ParserState m Blocks
    -> ParsecT Text ParserState m [Blocks]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many ParsecT Text ParserState m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    plain) (Text -> ParsecT Text ParserState m Blocks)
    -> (Text -> Text) -> Text -> ParsecT Text ParserState m Blocks
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Text
    trim) [Text]
    rawHeads
      ([Blocks], [Alignment], [Int])
    -> RSTParser m ([Blocks], [Alignment], [Int])
    forall (m :: * -> *) a. Monad m => a -> m a
    return ([Blocks]
    heads, [Alignment]
    aligns, [Int]
    indices)

    -- Parse a simple table.
    simpleTable :: PandocMonad m
                => Bool  -- ^ Headerless table
                -> RSTParser m Blocks
    simpleTable :: Bool -> RSTParser m Blocks
    simpleTable headless :: Bool
    headless = do
      let wrapIdFst :: (a, b, c) -> (Identity a, b, c)
    wrapIdFst (a :: a
    a, b :: b
    b, c :: c
    c) = (a -> Identity a
    forall a. a -> Identity a
    Identity a
    a, b
    b, c
    c)
          wrapId :: ParsecT Text ParserState m a
    -> ParsecT Text ParserState m (Identity a)
    wrapId = (a -> Identity a)
    -> ParsecT Text ParserState m a
    -> ParsecT Text ParserState m (Identity a)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap a -> Identity a
    forall a. a -> Identity a
    Identity
      Blocks
    tbl <- Identity Blocks -> Blocks
    forall a. Identity a -> a
    runIdentity (Identity Blocks -> Blocks)
    -> ParsecT Text ParserState m (Identity Blocks)
    -> RSTParser m Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParserT Text ParserState m (Identity [Blocks], [Alignment], [Int])
    -> ([Int] -> ParserT Text ParserState m (Identity [Blocks]))
    -> ParserT Text ParserState m ()
    -> ParserT Text ParserState m Text
    -> ParsecT Text ParserState m (Identity Blocks)
    forall s (m :: * -> *) st (mf :: * -> *) sep end.
    (Stream s m Char, HasReaderOptions st, Monad mf) =>
    ParserT s st m (mf [Blocks], [Alignment], [Int])
    -> ([Int] -> ParserT s st m (mf [Blocks]))
    -> ParserT s st m sep
    -> ParserT s st m end
    -> ParserT s st m (mf Blocks)
    tableWith
               (([Blocks], [Alignment], [Int])
    -> (Identity [Blocks], [Alignment], [Int])
    forall a b c. (a, b, c) -> (Identity a, b, c)
    wrapIdFst (([Blocks], [Alignment], [Int])
     -> (Identity [Blocks], [Alignment], [Int]))
    -> ParsecT Text ParserState m ([Blocks], [Alignment], [Int])
    -> ParserT
         Text ParserState m (Identity [Blocks], [Alignment], [Int])
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Bool -> ParsecT Text ParserState m ([Blocks], [Alignment], [Int])
    forall (m :: * -> *).
    PandocMonad m =>
    Bool -> RSTParser m ([Blocks], [Alignment], [Int])
    simpleTableHeader Bool
    headless)
               (ParsecT Text ParserState m [Blocks]
    -> ParserT Text ParserState m (Identity [Blocks])
    forall a.
    ParsecT Text ParserState m a
    -> ParsecT Text ParserState m (Identity a)
    wrapId (ParsecT Text ParserState m [Blocks]
     -> ParserT Text ParserState m (Identity [Blocks]))
    -> ([Int] -> ParsecT Text ParserState m [Blocks])
    -> [Int]
    -> ParserT Text ParserState m (Identity [Blocks])
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> [Int] -> ParsecT Text ParserState m [Blocks]
    forall (m :: * -> *).
    PandocMonad m =>
    [Int] -> RSTParser m [Blocks]
    simpleTableRow)
               ParserT Text ParserState m ()
    sep ParserT Text ParserState m Text
    forall (m :: * -> *). Monad m => RSTParser m Text
    simpleTableFooter
      -- Simple tables get 0s for relative column widths (i.e., use default)
      case Blocks -> [Block]
    forall a. Many a -> [a]
    B.toList Blocks
    tbl of
           [Table c :: [Inline]
    c a :: [Alignment]
    a _w :: [Double]
    _w h :: [[Block]]
    h l :: [[[Block]]]
    l]  -> Blocks -> RSTParser m Blocks
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Blocks -> RSTParser m Blocks) -> Blocks -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ Block -> Blocks
    forall a. a -> Many a
    B.singleton (Block -> Blocks) -> Block -> Blocks
    forall a b. (a -> b) -> a -> b
    $
                                     [Inline]
    -> [Alignment] -> [Double] -> [[Block]] -> [[[Block]]] -> Block
    Table [Inline]
    c [Alignment]
    a (Int -> Double -> [Double]
    forall a. Int -> a -> [a]
    replicate ([Alignment] -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    length [Alignment]
    a) 0) [[Block]]
    h [[[Block]]]
    l
           _ ->
             PandocError -> RSTParser m Blocks
    forall e (m :: * -> *) a. MonadError e m => e -> m a
    throwError (PandocError -> RSTParser m Blocks)
    -> PandocError -> RSTParser m Blocks
    forall a b. (a -> b) -> a -> b
    $ Text -> PandocError
    PandocShouldNeverHappenError
                "tableWith returned something unexpected"
     where
      sep :: ParserT Text ParserState m ()
    sep = () -> ParserT Text ParserState m ()
    forall (m :: * -> *) a. Monad m => a -> m a
    return () -- optional (simpleTableSep '-')

    gridTable :: PandocMonad m
              => Bool -- ^ Headerless table
              -> RSTParser m Blocks
    gridTable :: Bool -> RSTParser m Blocks
    gridTable headerless :: Bool
    headerless = Identity Blocks -> Blocks
    forall a. Identity a -> a
    runIdentity (Identity Blocks -> Blocks)
    -> ParsecT Text ParserState m (Identity Blocks)
    -> RSTParser m Blocks
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$>
      ParsecT Text ParserState m (Identity Blocks)
    -> Bool -> ParsecT Text ParserState m (Identity Blocks)
    forall s (m :: * -> *) st (mf :: * -> *).
    (Stream s m Char, HasReaderOptions st, HasLastStrPosition st,
     Monad mf, IsString s) =>
    ParserT s st m (mf Blocks) -> Bool -> ParserT s st m (mf Blocks)
    gridTableWith (Blocks -> Identity Blocks
    forall a. a -> Identity a
    Identity (Blocks -> Identity Blocks)
    -> RSTParser m Blocks
    -> ParsecT Text ParserState m (Identity Blocks)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    parseBlocks) Bool
    headerless

    table :: PandocMonad m => RSTParser m Blocks
    table :: RSTParser m Blocks
    table = Bool -> RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => Bool -> RSTParser m Blocks
    gridTable Bool
    False RSTParser m Blocks -> RSTParser m Blocks -> RSTParser m Blocks
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> Bool -> RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => Bool -> RSTParser m Blocks
    simpleTable Bool
    False RSTParser m Blocks -> RSTParser m Blocks -> RSTParser m Blocks
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|>
            Bool -> RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => Bool -> RSTParser m Blocks
    gridTable Bool
    True  RSTParser m Blocks -> RSTParser m Blocks -> RSTParser m Blocks
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> Bool -> RSTParser m Blocks
    forall (m :: * -> *). PandocMonad m => Bool -> RSTParser m Blocks
    simpleTable Bool
    True RSTParser m Blocks -> [Char] -> RSTParser m Blocks
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> [Char] -> ParsecT s u m a
    <?> "table"

    --
    -- inline
    --

    inline :: PandocMonad m => RSTParser m Inlines
    inline :: RSTParser m (Many Inline)
    inline = [RSTParser m (Many Inline)] -> RSTParser m (Many Inline)
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    [ParsecT s u m a] -> ParsecT s u m a
    choice [ RSTParser m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    note          -- can start with whitespace, so try before ws
                    , RSTParser m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    link
                    , RSTParser m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    strong
                    , RSTParser m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    emph
                    , RSTParser m (Many Inline)
    forall (m :: * -> *). Monad m => RSTParser m (Many Inline)
    code
                    , RSTParser m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    subst
                    , RSTParser m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    interpretedRole
                    , RSTParser m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    inlineContent ] RSTParser m (Many Inline) -> [Char] -> RSTParser m (Many Inline)
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> [Char] -> ParsecT s u m a
    <?> "inline"

    -- strings, spaces and other characters that can appear either by
    -- themselves or within inline markup
    inlineContent :: PandocMonad m => RSTParser m Inlines
    inlineContent :: RSTParser m (Many Inline)
    inlineContent = [RSTParser m (Many Inline)] -> RSTParser m (Many Inline)
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    [ParsecT s u m a] -> ParsecT s u m a
    choice [ RSTParser m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    whitespace
                           , RSTParser m (Many Inline)
    forall (m :: * -> *). Monad m => RSTParser m (Many Inline)
    str
                           , RSTParser m (Many Inline)
    forall (m :: * -> *). Monad m => RSTParser m (Many Inline)
    endline
                           , RSTParser m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    smart
                           , RSTParser m (Many Inline)
    forall (m :: * -> *). Monad m => RSTParser m (Many Inline)
    hyphens
                           , RSTParser m (Many Inline)
    forall (m :: * -> *) st. Monad m => ParserT Text st m (Many Inline)
    escapedChar
                           , RSTParser m (Many Inline)
    forall (m :: * -> *). Monad m => RSTParser m (Many Inline)
    symbol ] RSTParser m (Many Inline) -> [Char] -> RSTParser m (Many Inline)
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> [Char] -> ParsecT s u m a
    <?> "inline content"

    parseInlineFromText :: PandocMonad m => Text -> RSTParser m Inlines
    parseInlineFromText :: Text -> RSTParser m (Many Inline)
    parseInlineFromText = RSTParser m (Many Inline) -> Text -> RSTParser m (Many Inline)
    forall s (m :: * -> *) u a.
    (Stream s m Char, IsString s, HasLastStrPosition u) =>
    ParserT s u m a -> Text -> ParserT s u m a
    parseFromString' (Many Inline -> Many Inline
    trimInlines (Many Inline -> Many Inline)
    -> ([Many Inline] -> Many Inline) -> [Many Inline] -> Many Inline
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Many Inline] -> Many Inline
    forall a. Monoid a => [a] -> a
    mconcat ([Many Inline] -> Many Inline)
    -> ParsecT Text ParserState m [Many Inline]
    -> RSTParser m (Many Inline)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> RSTParser m (Many Inline)
    -> ParsecT Text ParserState m [Many Inline]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
    many RSTParser m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    inline)

    hyphens :: Monad m => RSTParser m Inlines
    hyphens :: RSTParser m (Many Inline)
    hyphens = do
      Text
    result <- ParserT Text ParserState m Char -> ParserT Text ParserState m Text
    forall s (m :: * -> *) t st.
    Stream s m t =>
    ParserT s st m Char -> ParserT s st m Text
    many1Char (Char -> ParserT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '-')
      RSTParser m (Many Inline) -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m ()
    optional RSTParser m (Many Inline)
    forall (m :: * -> *). Monad m => RSTParser m (Many Inline)
    endline
      -- don't want to treat endline after hyphen or dash as a space
      Many Inline -> RSTParser m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline -> RSTParser m (Many Inline))
    -> Many Inline -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ Text -> Many Inline
    B.str Text
    result

    escapedChar :: Monad m => ParserT Text st m Inlines
    escapedChar :: ParserT Text st m (Many Inline)
    escapedChar = do Char
    c <- ParserT Text st m Char -> ParserT Text st m Char
    forall s (m :: * -> *) st.
    Stream s m Char =>
    ParserT s st m Char -> ParserT s st m Char
    escaped ParserT Text st m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    anyChar
                     Many Inline -> ParserT Text st m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline -> ParserT Text st m (Many Inline))
    -> Many Inline -> ParserT Text st m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ if Char
    c Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    == ' ' Bool -> Bool -> Bool
    || Char
    c Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    == '\n' Bool -> Bool -> Bool
    || Char
    c Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    == '\r'
                                 -- '\ ' is null in RST
                                 then Many Inline
    forall a. Monoid a => a
    mempty
                                 else Text -> Many Inline
    B.str (Text -> Many Inline) -> Text -> Many Inline
    forall a b. (a -> b) -> a -> b
    $ Char -> Text
    T.singleton Char
    c

    symbol :: Monad m => RSTParser m Inlines
    symbol :: RSTParser m (Many Inline)
    symbol = do
      Char
    result <- [Char] -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m Char
    oneOf [Char]
    specialChars
      Many Inline -> RSTParser m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline -> RSTParser m (Many Inline))
    -> Many Inline -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ Text -> Many Inline
    B.str (Text -> Many Inline) -> Text -> Many Inline
    forall a b. (a -> b) -> a -> b
    $ Char -> Text
    T.singleton Char
    result

    -- parses inline code, between codeStart and codeEnd
    code :: Monad m => RSTParser m Inlines
    code :: RSTParser m (Many Inline)
    code = RSTParser m (Many Inline) -> RSTParser m (Many Inline)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m (Many Inline) -> RSTParser m (Many Inline))
    -> RSTParser m (Many Inline) -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ do
      [Char] -> ParsecT Text ParserState m [Char]
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m [Char]
    string "``"
      Text
    result <- ParserT Text ParserState m Char
    -> ParsecT Text ParserState m [Char]
    -> ParserT Text ParserState m Text
    forall s (m :: * -> *) t st a.
    Stream s m t =>
    ParserT s st m Char -> ParserT s st m a -> ParserT s st m Text
    manyTillChar ParserT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    anyChar (ParsecT Text ParserState m [Char]
    -> ParsecT Text ParserState m [Char]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try ([Char] -> ParsecT Text ParserState m [Char]
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m [Char]
    string "``"))
      Many Inline -> RSTParser m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline -> RSTParser m (Many Inline))
    -> Many Inline -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ Text -> Many Inline
    B.code
             (Text -> Many Inline) -> Text -> Many Inline
    forall a b. (a -> b) -> a -> b
    $ Text -> Text
    trim (Text -> Text) -> Text -> Text
    forall a b. (a -> b) -> a -> b
    $ [Text] -> Text
    T.unwords ([Text] -> Text) -> [Text] -> Text
    forall a b. (a -> b) -> a -> b
    $ Text -> [Text]
    T.lines Text
    result

    -- succeeds only if we're not right after a str (ie. in middle of word)
    atStart :: Monad m => RSTParser m a -> RSTParser m a
    atStart :: RSTParser m a -> RSTParser m a
    atStart p :: RSTParser m a
    p = do
      SourcePos
    pos <- ParsecT Text ParserState m SourcePos
    forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
    getPosition
      ParserState
    st <- ParsecT Text ParserState m ParserState
    forall (m :: * -> *) s u. Monad m => ParsecT s u m u
    getState
      -- single quote start can't be right after str
      Bool -> ParsecT Text ParserState m ()
    forall (f :: * -> *). Alternative f => Bool -> f ()
    guard (Bool -> ParsecT Text ParserState m ())
    -> Bool -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ ParserState -> Maybe SourcePos
    stateLastStrPos ParserState
    st Maybe SourcePos -> Maybe SourcePos -> Bool
    forall a. Eq a => a -> a -> Bool
    /= SourcePos -> Maybe SourcePos
    forall a. a -> Maybe a
    Just SourcePos
    pos
      RSTParser m a
    p

    emph :: PandocMonad m => RSTParser m Inlines
    emph :: RSTParser m (Many Inline)
    emph = Many Inline -> Many Inline
    B.emph (Many Inline -> Many Inline)
    -> ([Many Inline] -> Many Inline) -> [Many Inline] -> Many Inline
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Many Inline -> Many Inline
    trimInlines (Many Inline -> Many Inline)
    -> ([Many Inline] -> Many Inline) -> [Many Inline] -> Many Inline
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Many Inline] -> Many Inline
    forall a. Monoid a => [a] -> a
    mconcat ([Many Inline] -> Many Inline)
    -> ParsecT Text ParserState m [Many Inline]
    -> RSTParser m (Many Inline)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$>
             ParserT Text ParserState m Char
    -> ParserT Text ParserState m Char
    -> RSTParser m (Many Inline)
    -> ParsecT Text ParserState m [Many Inline]
    forall end s (m :: * -> *) st t a.
    (Show end, Stream s m Char) =>
    ParserT s st m t
    -> ParserT s st m end -> ParserT s st m a -> ParserT s st m [a]
    enclosed (ParserT Text ParserState m Char -> ParserT Text ParserState m Char
    forall (m :: * -> *) a. Monad m => RSTParser m a -> RSTParser m a
    atStart (ParserT Text ParserState m Char
     -> ParserT Text ParserState m Char)
    -> ParserT Text ParserState m Char
    -> ParserT Text ParserState m Char
    forall a b. (a -> b) -> a -> b
    $ Char -> ParserT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '*') (Char -> ParserT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '*') RSTParser m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    inlineContent

    strong :: PandocMonad m => RSTParser m Inlines
    strong :: RSTParser m (Many Inline)
    strong = Many Inline -> Many Inline
    B.strong (Many Inline -> Many Inline)
    -> ([Many Inline] -> Many Inline) -> [Many Inline] -> Many Inline
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Many Inline -> Many Inline
    trimInlines (Many Inline -> Many Inline)
    -> ([Many Inline] -> Many Inline) -> [Many Inline] -> Many Inline
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Many Inline] -> Many Inline
    forall a. Monoid a => [a] -> a
    mconcat ([Many Inline] -> Many Inline)
    -> ParsecT Text ParserState m [Many Inline]
    -> RSTParser m (Many Inline)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$>
              ParserT Text ParserState m [Char]
    -> ParserT Text ParserState m [Char]
    -> RSTParser m (Many Inline)
    -> ParsecT Text ParserState m [Many Inline]
    forall end s (m :: * -> *) st t a.
    (Show end, Stream s m Char) =>
    ParserT s st m t
    -> ParserT s st m end -> ParserT s st m a -> ParserT s st m [a]
    enclosed (ParserT Text ParserState m [Char]
    -> ParserT Text ParserState m [Char]
    forall (m :: * -> *) a. Monad m => RSTParser m a -> RSTParser m a
    atStart (ParserT Text ParserState m [Char]
     -> ParserT Text ParserState m [Char])
    -> ParserT Text ParserState m [Char]
    -> ParserT Text ParserState m [Char]
    forall a b. (a -> b) -> a -> b
    $ [Char] -> ParserT Text ParserState m [Char]
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m [Char]
    string "**") (ParserT Text ParserState m [Char]
    -> ParserT Text ParserState m [Char]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (ParserT Text ParserState m [Char]
     -> ParserT Text ParserState m [Char])
    -> ParserT Text ParserState m [Char]
    -> ParserT Text ParserState m [Char]
    forall a b. (a -> b) -> a -> b
    $ [Char] -> ParserT Text ParserState m [Char]
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m [Char]
    string "**") RSTParser m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    inlineContent

    -- Note, this doesn't precisely implement the complex rule in
    -- http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#inline-markup-recognition-rules
    -- but it should be good enough for most purposes
    --
    -- TODO:
    --  - Classes are silently discarded in addNewRole
    --  - Allows direct use of the :raw: role, rST only allows inherited use.
    interpretedRole :: PandocMonad m => RSTParser m Inlines
    interpretedRole :: RSTParser m (Many Inline)
    interpretedRole = RSTParser m (Many Inline) -> RSTParser m (Many Inline)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m (Many Inline) -> RSTParser m (Many Inline))
    -> RSTParser m (Many Inline) -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ do
      (role :: Text
    role, contents :: Text
    contents) <- RSTParser m (Text, Text)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Text, Text)
    roleBefore RSTParser m (Text, Text)
    -> RSTParser m (Text, Text) -> RSTParser m (Text, Text)
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> RSTParser m (Text, Text)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Text, Text)
    roleAfter
      Text -> Maybe Text -> Text -> Attr -> RSTParser m (Many Inline)
    forall (m :: * -> *).
    PandocMonad m =>
    Text -> Maybe Text -> Text -> Attr -> RSTParser m (Many Inline)
    renderRole Text
    contents Maybe Text
    forall a. Maybe a
    Nothing Text
    role Attr
    nullAttr

    renderRole :: PandocMonad m
               => Text -> Maybe Text -> Text -> Attr -> RSTParser m Inlines
    renderRole :: Text -> Maybe Text -> Text -> Attr -> RSTParser m (Many Inline)
    renderRole contents :: Text
    contents fmt :: Maybe Text
    fmt role :: Text
    role attr :: Attr
    attr = case Text
    role of
        "sup"  -> Many Inline -> RSTParser m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline -> RSTParser m (Many Inline))
    -> Many Inline -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ Many Inline -> Many Inline
    B.superscript (Many Inline -> Many Inline) -> Many Inline -> Many Inline
    forall a b. (a -> b) -> a -> b
    $ Text -> Many Inline
    treatAsText Text
    contents
        "superscript" -> Many Inline -> RSTParser m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline -> RSTParser m (Many Inline))
    -> Many Inline -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ Many Inline -> Many Inline
    B.superscript (Many Inline -> Many Inline) -> Many Inline -> Many Inline
    forall a b. (a -> b) -> a -> b
    $ Text -> Many Inline
    treatAsText Text
    contents
        "sub"  -> Many Inline -> RSTParser m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline -> RSTParser m (Many Inline))
    -> Many Inline -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ Many Inline -> Many Inline
    B.subscript (Many Inline -> Many Inline) -> Many Inline -> Many Inline
    forall a b. (a -> b) -> a -> b
    $ Text -> Many Inline
    treatAsText Text
    contents
        "subscript"  -> Many Inline -> RSTParser m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline -> RSTParser m (Many Inline))
    -> Many Inline -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ Many Inline -> Many Inline
    B.subscript (Many Inline -> Many Inline) -> Many Inline -> Many Inline
    forall a b. (a -> b) -> a -> b
    $ Text -> Many Inline
    treatAsText Text
    contents
        "emphasis" -> Many Inline -> RSTParser m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline -> RSTParser m (Many Inline))
    -> Many Inline -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ Many Inline -> Many Inline
    B.emph (Many Inline -> Many Inline) -> Many Inline -> Many Inline
    forall a b. (a -> b) -> a -> b
    $ Text -> Many Inline
    treatAsText Text
    contents
        "strong" -> Many Inline -> RSTParser m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline -> RSTParser m (Many Inline))
    -> Many Inline -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ Many Inline -> Many Inline
    B.strong (Many Inline -> Many Inline) -> Many Inline -> Many Inline
    forall a b. (a -> b) -> a -> b
    $ Text -> Many Inline
    treatAsText Text
    contents
        "rfc-reference" -> Many Inline -> RSTParser m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline -> RSTParser m (Many Inline))
    -> Many Inline -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ Text -> Many Inline
    rfcLink Text
    contents
        "RFC" -> Many Inline -> RSTParser m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline -> RSTParser m (Many Inline))
    -> Many Inline -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ Text -> Many Inline
    rfcLink Text
    contents
        "pep-reference" -> Many Inline -> RSTParser m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline -> RSTParser m (Many Inline))
    -> Many Inline -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ Text -> Many Inline
    pepLink Text
    contents
        "PEP" -> Many Inline -> RSTParser m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline -> RSTParser m (Many Inline))
    -> Many Inline -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ Text -> Many Inline
    pepLink Text
    contents
        "literal" -> Many Inline -> RSTParser m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline -> RSTParser m (Many Inline))
    -> Many Inline -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ Attr -> Text -> Many Inline
    B.codeWith Attr
    attr Text
    contents
        "math" -> Many Inline -> RSTParser m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline -> RSTParser m (Many Inline))
    -> Many Inline -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ Text -> Many Inline
    B.math Text
    contents
        "title-reference" -> Text -> RSTParser m (Many Inline)
    forall (m :: * -> *). Monad m => Text -> m (Many Inline)
    titleRef Text
    contents
        "title" -> Text -> RSTParser m (Many Inline)
    forall (m :: * -> *). Monad m => Text -> m (Many Inline)
    titleRef Text
    contents
        "t" -> Text -> RSTParser m (Many Inline)
    forall (m :: * -> *). Monad m => Text -> m (Many Inline)
    titleRef Text
    contents
        "code" -> Many Inline -> RSTParser m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline -> RSTParser m (Many Inline))
    -> Many Inline -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ Attr -> Text -> Many Inline
    B.codeWith Attr
    attr Text
    contents
        "span" -> Many Inline -> RSTParser m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline -> RSTParser m (Many Inline))
    -> Many Inline -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ Attr -> Many Inline -> Many Inline
    B.spanWith Attr
    attr (Many Inline -> Many Inline) -> Many Inline -> Many Inline
    forall a b. (a -> b) -> a -> b
    $ Text -> Many Inline
    treatAsText Text
    contents
        "raw" -> Many Inline -> RSTParser m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline -> RSTParser m (Many Inline))
    -> Many Inline -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ Text -> Text -> Many Inline
    B.rawInline (Text -> Maybe Text -> Text
    forall a. a -> Maybe a -> a
    fromMaybe "" Maybe Text
    fmt) Text
    contents
        custom :: Text
    custom -> do
            Map Text (Text, Maybe Text, Attr)
    customRoles <- ParserState -> Map Text (Text, Maybe Text, Attr)
    stateRstCustomRoles (ParserState -> Map Text (Text, Maybe Text, Attr))
    -> ParsecT Text ParserState m ParserState
    -> ParsecT Text ParserState m (Map Text (Text, Maybe Text, Attr))
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Text ParserState m ParserState
    forall (m :: * -> *) s u. Monad m => ParsecT s u m u
    getState
            case Text
    -> Map Text (Text, Maybe Text, Attr)
    -> Maybe (Text, Maybe Text, Attr)
    forall k a. Ord k => k -> Map k a -> Maybe a
    M.lookup Text
    custom Map Text (Text, Maybe Text, Attr)
    customRoles of
                Just (newRole :: Text
    newRole, newFmt :: Maybe Text
    newFmt, newAttr :: Attr
    newAttr) ->
                    Text -> Maybe Text -> Text -> Attr -> RSTParser m (Many Inline)
    forall (m :: * -> *).
    PandocMonad m =>
    Text -> Maybe Text -> Text -> Attr -> RSTParser m (Many Inline)
    renderRole Text
    contents Maybe Text
    newFmt Text
    newRole Attr
    newAttr
                Nothing -> -- undefined role
                    Many Inline -> RSTParser m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline -> RSTParser m (Many Inline))
    -> Many Inline -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ Attr -> Text -> Many Inline
    B.codeWith ("",["interpreted-text"],[("role",Text
    role)])
                              Text
    contents
     where
       titleRef :: Text -> m (Many Inline)
    titleRef ref :: Text
    ref = Many Inline -> m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline -> m (Many Inline)) -> Many Inline -> m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ Attr -> Many Inline -> Many Inline
    B.spanWith ("",["title-ref"],[]) (Many Inline -> Many Inline) -> Many Inline -> Many Inline
    forall a b. (a -> b) -> a -> b
    $ Text -> Many Inline
    treatAsText Text
    ref
       rfcLink :: Text -> Many Inline
    rfcLink rfcNo :: Text
    rfcNo = Text -> Text -> Many Inline -> Many Inline
    B.link Text
    rfcUrl ("RFC " Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    rfcNo) (Many Inline -> Many Inline) -> Many Inline -> Many Inline
    forall a b. (a -> b) -> a -> b
    $ Text -> Many Inline
    B.str ("RFC " Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    rfcNo)
         where rfcUrl :: Text
    rfcUrl = "http://www.faqs.org/rfcs/rfc" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    rfcNo Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> ".html"
       pepLink :: Text -> Many Inline
    pepLink pepNo :: Text
    pepNo = Text -> Text -> Many Inline -> Many Inline
    B.link Text
    pepUrl ("PEP " Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    pepNo) (Many Inline -> Many Inline) -> Many Inline -> Many Inline
    forall a b. (a -> b) -> a -> b
    $ Text -> Many Inline
    B.str ("PEP " Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    pepNo)
         where padNo :: Text
    padNo = Int -> Text -> Text
    T.replicate (4 Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Text -> Int
    T.length Text
    pepNo) "0" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    pepNo
               pepUrl :: Text
    pepUrl = "http://www.python.org/dev/peps/pep-" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    padNo Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> "/"
       treatAsText :: Text -> Many Inline
    treatAsText = Text -> Many Inline
    B.text (Text -> Many Inline) -> (Text -> Text) -> Text -> Many Inline
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Text
    handleEscapes
       handleEscapes :: Text -> Text
    handleEscapes = [Text] -> Text
    T.concat ([Text] -> Text) -> (Text -> [Text]) -> Text -> Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Text] -> [Text]
    removeSpace ([Text] -> [Text]) -> (Text -> [Text]) -> Text -> [Text]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Text -> [Text]
    T.splitOn "\\"
         where headSpace :: Text -> Text
    headSpace t :: Text
    t = Text -> Maybe Text -> Text
    forall a. a -> Maybe a -> a
    fromMaybe Text
    t (Maybe Text -> Text) -> Maybe Text -> Text
    forall a b. (a -> b) -> a -> b
    $ Text -> Text -> Maybe Text
    T.stripPrefix " " Text
    t
               removeSpace :: [Text] -> [Text]
    removeSpace (x :: Text
    x:xs :: [Text]
    xs) = Text
    x Text -> [Text] -> [Text]
    forall a. a -> [a] -> [a]
    : (Text -> Text) -> [Text] -> [Text]
    forall a b. (a -> b) -> [a] -> [b]
    map Text -> Text
    headSpace [Text]
    xs
               removeSpace []     = []

    roleName :: PandocMonad m => RSTParser m Text
    roleName :: RSTParser m Text
    roleName = ParserT Text ParserState m Char -> RSTParser m Text
    forall s (m :: * -> *) t st.
    Stream s m t =>
    ParserT s st m Char -> ParserT s st m Text
    many1Char (ParserT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    letter ParserT Text ParserState m Char
    -> ParserT Text ParserState m Char
    -> ParserT Text ParserState m Char
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> Char -> ParserT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '-')

    roleMarker :: PandocMonad m => RSTParser m Text
    roleMarker :: RSTParser m Text
    roleMarker = Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char ':' ParsecT Text ParserState m Char
    -> RSTParser m Text -> RSTParser m Text
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> RSTParser m Text
    forall (m :: * -> *). PandocMonad m => RSTParser m Text
    roleName RSTParser m Text
    -> ParsecT Text ParserState m Char -> RSTParser m Text
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <* Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char ':'

    roleBefore :: PandocMonad m => RSTParser m (Text,Text)
    roleBefore :: RSTParser m (Text, Text)
    roleBefore = RSTParser m (Text, Text) -> RSTParser m (Text, Text)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m (Text, Text) -> RSTParser m (Text, Text))
    -> RSTParser m (Text, Text) -> RSTParser m (Text, Text)
    forall a b. (a -> b) -> a -> b
    $ do
      Text
    role <- RSTParser m Text
    forall (m :: * -> *). PandocMonad m => RSTParser m Text
    roleMarker
      Text
    contents <- RSTParser m Text
    forall (m :: * -> *). PandocMonad m => RSTParser m Text
    unmarkedInterpretedText
      (Text, Text) -> RSTParser m (Text, Text)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Text
    role,Text
    contents)

    roleAfter :: PandocMonad m => RSTParser m (Text,Text)
    roleAfter :: RSTParser m (Text, Text)
    roleAfter = RSTParser m (Text, Text) -> RSTParser m (Text, Text)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m (Text, Text) -> RSTParser m (Text, Text))
    -> RSTParser m (Text, Text) -> RSTParser m (Text, Text)
    forall a b. (a -> b) -> a -> b
    $ do
      Text
    contents <- RSTParser m Text
    forall (m :: * -> *). PandocMonad m => RSTParser m Text
    unmarkedInterpretedText
      Text
    role <- RSTParser m Text
    forall (m :: * -> *). PandocMonad m => RSTParser m Text
    roleMarker RSTParser m Text -> RSTParser m Text -> RSTParser m Text
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> (ParserState -> Text
    stateRstDefaultRole (ParserState -> Text)
    -> ParsecT Text ParserState m ParserState -> RSTParser m Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Text ParserState m ParserState
    forall (m :: * -> *) s u. Monad m => ParsecT s u m u
    getState)
      (Text, Text) -> RSTParser m (Text, Text)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Text
    role,Text
    contents)

    unmarkedInterpretedText :: PandocMonad m => RSTParser m Text
    unmarkedInterpretedText :: RSTParser m Text
    unmarkedInterpretedText = RSTParser m Text -> RSTParser m Text
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m Text -> RSTParser m Text)
    -> RSTParser m Text -> RSTParser m Text
    forall a b. (a -> b) -> a -> b
    $ do
      RSTParser m Char -> RSTParser m Char
    forall (m :: * -> *) a. Monad m => RSTParser m a -> RSTParser m a
    atStart (Char -> RSTParser m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '`')
      [Char]
    contents <- [[Char]] -> [Char]
    forall a. Monoid a => [a] -> a
    mconcat ([[Char]] -> [Char])
    -> ParsecT Text ParserState m [[Char]]
    -> ParsecT Text ParserState m [Char]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Text ParserState m [Char]
    -> ParsecT Text ParserState m [[Char]]
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m [a]
    many1
           (  RSTParser m Char -> ParsecT Text ParserState m [Char]
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m [a]
    many1 ([Char] -> RSTParser m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m Char
    noneOf "`\\\n")
          ParsecT Text ParserState m [Char]
    -> ParsecT Text ParserState m [Char]
    -> ParsecT Text ParserState m [Char]
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> (Char -> RSTParser m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '\\' RSTParser m Char
    -> ParsecT Text ParserState m [Char]
    -> ParsecT Text ParserState m [Char]
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> ((\c :: Char
    c -> ['\\',Char
    c]) (Char -> [Char])
    -> RSTParser m Char -> ParsecT Text ParserState m [Char]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> [Char] -> RSTParser m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m Char
    noneOf "\n"))
          ParsecT Text ParserState m [Char]
    -> ParsecT Text ParserState m [Char]
    -> ParsecT Text ParserState m [Char]
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ([Char] -> ParsecT Text ParserState m [Char]
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m [Char]
    string "\n" ParsecT Text ParserState m [Char]
    -> ParsecT Text ParserState m ()
    -> ParsecT Text ParserState m [Char]
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <* RSTParser m Char -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) t a u.
    (Stream s m t, Show a) =>
    ParsecT s u m a -> ParsecT s u m ()
    notFollowedBy RSTParser m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    blankline)
          ParsecT Text ParserState m [Char]
    -> ParsecT Text ParserState m [Char]
    -> ParsecT Text ParserState m [Char]
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> ParsecT Text ParserState m [Char]
    -> ParsecT Text ParserState m [Char]
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try ([Char] -> ParsecT Text ParserState m [Char]
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m [Char]
    string "`" ParsecT Text ParserState m [Char]
    -> ParsecT Text ParserState m ()
    -> ParsecT Text ParserState m [Char]
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <*
                    ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) t a u.
    (Stream s m t, Show a) =>
    ParsecT s u m a -> ParsecT s u m ()
    notFollowedBy (() () -> RSTParser m Text -> ParsecT Text ParserState m ()
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ RSTParser m Text
    forall (m :: * -> *). PandocMonad m => RSTParser m Text
    roleMarker) ParsecT Text ParserState m [Char]
    -> RSTParser m Char -> ParsecT Text ParserState m [Char]
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <*
                    RSTParser m Char -> RSTParser m Char
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m a
    lookAhead ((Char -> Bool) -> RSTParser m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    (Char -> Bool) -> ParsecT s u m Char
    satisfy Char -> Bool
    isAlphaNum))
           )
      Char -> RSTParser m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '`'
      Text -> RSTParser m Text
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Text -> RSTParser m Text) -> Text -> RSTParser m Text
    forall a b. (a -> b) -> a -> b
    $ [Char] -> Text
    T.pack [Char]
    contents

    whitespace :: PandocMonad m => RSTParser m Inlines
    whitespace :: RSTParser m (Many Inline)
    whitespace = Many Inline
    B.space Many Inline
    -> ParsecT Text ParserState m () -> RSTParser m (Many Inline)
    forall (f :: * -> *) a b. Functor f => a -> f b -> f a
    <$ ParsecT Text ParserState m Char -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m ()
    skipMany1 ParsecT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    spaceChar RSTParser m (Many Inline) -> [Char] -> RSTParser m (Many Inline)
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> [Char] -> ParsecT s u m a
    <?> "whitespace"

    str :: Monad m => RSTParser m Inlines
    str :: RSTParser m (Many Inline)
    str = do
      let strChar :: ParsecT Text u m Char
    strChar = [Char] -> ParsecT Text u m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m Char
    noneOf ("\t\n " [Char] -> [Char] -> [Char]
    forall a. [a] -> [a] -> [a]
    ++ [Char]
    specialChars)
      Text
    result <- ParserT Text ParserState m Char -> ParserT Text ParserState m Text
    forall s (m :: * -> *) t st.
    Stream s m t =>
    ParserT s st m Char -> ParserT s st m Text
    many1Char ParserT Text ParserState m Char
    forall u. ParsecT Text u m Char
    strChar
      ParserT Text ParserState m ()
    forall s (m :: * -> *) a st.
    (Stream s m a, HasLastStrPosition st) =>
    ParserT s st m ()
    updateLastStrPos
      Many Inline -> RSTParser m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline -> RSTParser m (Many Inline))
    -> Many Inline -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ Text -> Many Inline
    B.str Text
    result

    -- an endline character that can be treated as a space, not a structural break
    endline :: Monad m => RSTParser m Inlines
    endline :: RSTParser m (Many Inline)
    endline = RSTParser m (Many Inline) -> RSTParser m (Many Inline)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m (Many Inline) -> RSTParser m (Many Inline))
    -> RSTParser m (Many Inline) -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ do
      ParsecT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    newline
      ParsecT Text ParserState m Char -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) t a u.
    (Stream s m t, Show a) =>
    ParsecT s u m a -> ParsecT s u m ()
    notFollowedBy ParsecT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    blankline
      -- parse potential list-starts at beginning of line differently in a list:
      ParserState
    st <- ParsecT Text ParserState m ParserState
    forall (m :: * -> *) s u. Monad m => ParsecT s u m u
    getState
      Bool
    -> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
    forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
    when (ParserState -> ParserContext
    stateParserContext ParserState
    st ParserContext -> ParserContext -> Bool
    forall a. Eq a => a -> a -> Bool
    == ParserContext
    ListItemState) (ParsecT Text ParserState m () -> ParsecT Text ParserState m ())
    -> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ ParsecT Text ParserState m Char -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) t a u.
    (Stream s m t, Show a) =>
    ParsecT s u m a -> ParsecT s u m ()
    notFollowedBy (ParserT Text ParserState m ListAttributes
    forall s (m :: * -> *).
    Stream s m Char =>
    ParserT s ParserState m ListAttributes
    anyOrderedListMarker ParserT Text ParserState m ListAttributes
    -> ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m Char
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
    spaceChar) ParsecT Text ParserState m ()
    -> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >>
              ParserT Text ParserState m Int -> ParsecT Text ParserState m ()
    forall b s (m :: * -> *) a st.
    (Show b, Stream s m a) =>
    ParserT s st m b -> ParserT s st m ()
    notFollowedBy' ParserT Text ParserState m Int
    forall (m :: * -> *) st. Monad m => ParserT Text st m Int
    bulletListStart
      Many Inline -> RSTParser m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return Many Inline
    B.softbreak

    --
    -- links
    --

    link :: PandocMonad m => RSTParser m Inlines
    link :: RSTParser m (Many Inline)
    link = [RSTParser m (Many Inline)] -> RSTParser m (Many Inline)
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    [ParsecT s u m a] -> ParsecT s u m a
    choice [RSTParser m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    explicitLink, RSTParser m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    referenceLink, RSTParser m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    autoLink]  RSTParser m (Many Inline) -> [Char] -> RSTParser m (Many Inline)
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> [Char] -> ParsecT s u m a
    <?> "link"

    explicitLink :: PandocMonad m => RSTParser m Inlines
    explicitLink :: RSTParser m (Many Inline)
    explicitLink = RSTParser m (Many Inline) -> RSTParser m (Many Inline)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m (Many Inline) -> RSTParser m (Many Inline))
    -> RSTParser m (Many Inline) -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ do
      Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '`'
      ParsecT Text ParserState m Char -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) t a u.
    (Stream s m t, Show a) =>
    ParsecT s u m a -> ParsecT s u m ()
    notFollowedBy (Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '`') -- `` marks start of inline code
      Many Inline
    label' <- Many Inline -> Many Inline
    trimInlines (Many Inline -> Many Inline)
    -> ([Many Inline] -> Many Inline) -> [Many Inline] -> Many Inline
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Many Inline] -> Many Inline
    forall a. Monoid a => [a] -> a
    mconcat ([Many Inline] -> Many Inline)
    -> ParsecT Text ParserState m [Many Inline]
    -> RSTParser m (Many Inline)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$>
                 RSTParser m (Many Inline)
    -> ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m [Many Inline]
    forall s (m :: * -> *) t u a end.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
    manyTill (ParsecT Text ParserState m Char -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) t a u.
    (Stream s m t, Show a) =>
    ParsecT s u m a -> ParsecT s u m ()
    notFollowedBy (Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '`') ParsecT Text ParserState m ()
    -> RSTParser m (Many Inline) -> RSTParser m (Many Inline)
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> RSTParser m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    inlineContent) (Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '<')
      Text
    src <- Text -> Text
    trim (Text -> Text)
    -> ParsecT Text ParserState m Text
    -> ParsecT Text ParserState m Text
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m Char
    -> ParsecT Text ParserState m Text
    forall s (m :: * -> *) t st a.
    Stream s m t =>
    ParserT s st m Char -> ParserT s st m a -> ParserT s st m Text
    manyTillChar ([Char] -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m Char
    noneOf ">\n") (Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '>')
      ParsecT Text ParserState m ()
    forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
    skipSpaces
      [Char] -> ParsecT Text ParserState m [Char]
    forall s (m :: * -> *) u.
    Stream s m Char =>
    [Char] -> ParsecT s u m [Char]
    string "`_"
      ParsecT Text ParserState m Char -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m ()
    optional (ParsecT Text ParserState m Char -> ParsecT Text ParserState m ())
    -> ParsecT Text ParserState m Char -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '_' -- anonymous form
      let label'' :: Many Inline
    label'' = if Many Inline
    label' Many Inline -> Many Inline -> Bool
    forall a. Eq a => a -> a -> Bool
    == Many Inline
    forall a. Monoid a => a
    mempty
                       then Text -> Many Inline
    B.str Text
    src
                       else Many Inline
    label'
      -- `link <google_>` is a reference link to _google!
      ((src' :: Text
    src',tit :: Text
    tit),attr :: Attr
    attr) <-
        if Text -> Bool
    isURI Text
    src
           then ((Text, Text), Attr)
    -> ParsecT Text ParserState m ((Text, Text), Attr)
    forall (m :: * -> *) a. Monad m => a -> m a
    return ((Text
    src, ""), Attr
    nullAttr)
           else
             case Text -> Maybe (Text, Char)
    T.unsnoc Text
    src of
               Just (xs :: Text
    xs, '_') -> [Key] -> Key -> ParsecT Text ParserState m ((Text, Text), Attr)
    forall (m :: * -> *).
    PandocMonad m =>
    [Key] -> Key -> RSTParser m ((Text, Text), Attr)
    lookupKey [] (Text -> Key
    toKey Text
    xs)
               _              -> ((Text, Text), Attr)
    -> ParsecT Text ParserState m ((Text, Text), Attr)
    forall (m :: * -> *) a. Monad m => a -> m a
    return ((Text
    src, ""), Attr
    nullAttr)
      Many Inline -> RSTParser m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline -> RSTParser m (Many Inline))
    -> Many Inline -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ Attr -> Text -> Text -> Many Inline -> Many Inline
    B.linkWith Attr
    attr (Text -> Text
    escapeURI Text
    src') Text
    tit Many Inline
    label''

    citationName :: PandocMonad m => RSTParser m Text
    citationName :: RSTParser m Text
    citationName = do
      Text
    raw <- RSTParser m Text
    forall (m :: * -> *). Monad m => RSTParser m Text
    citationMarker
      Text -> RSTParser m Text
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Text -> RSTParser m Text) -> Text -> RSTParser m Text
    forall a b. (a -> b) -> a -> b
    $ "[" Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> Text
    raw Text -> Text -> Text
    forall a. Semigroup a => a -> a -> a
    <> "]"

    referenceLink :: PandocMonad m => RSTParser m Inlines
    referenceLink :: RSTParser m (Many Inline)
    referenceLink = RSTParser m (Many Inline) -> RSTParser m (Many Inline)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m (Many Inline) -> RSTParser m (Many Inline))
    -> RSTParser m (Many Inline) -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ do
      Text
    ref <- (RSTParser m Text
    forall (m :: * -> *). PandocMonad m => RSTParser m Text
    referenceName RSTParser m Text -> RSTParser m Text -> RSTParser m Text
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> RSTParser m Text
    forall (m :: * -> *). PandocMonad m => RSTParser m Text
    citationName) RSTParser m Text
    -> ParsecT Text ParserState m Char -> RSTParser m Text
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <* Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '_'
      let label' :: Many Inline
    label' = Text -> Many Inline
    B.text Text
    ref
      let isAnonKey :: Key -> Bool
    isAnonKey (Key (Text -> Maybe (Char, Text)
    T.uncons -> Just ('_',_))) = Bool
    True
          isAnonKey _                                = Bool
    False
      ParserState
    state <- ParsecT Text ParserState m ParserState
    forall (m :: * -> *) s u. Monad m => ParsecT s u m u
    getState
      let keyTable :: KeyTable
    keyTable = ParserState -> KeyTable
    stateKeys ParserState
    state
      Key
    key <- Key
    -> ParsecT Text ParserState m Key -> ParsecT Text ParserState m Key
    forall s (m :: * -> *) t a u.
    Stream s m t =>
    a -> ParsecT s u m a -> ParsecT s u m a
    option (Text -> Key
    toKey Text
    ref) (ParsecT Text ParserState m Key -> ParsecT Text ParserState m Key)
    -> ParsecT Text ParserState m Key -> ParsecT Text ParserState m Key
    forall a b. (a -> b) -> a -> b
    $
                    do Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '_'
                       let anonKeys :: [Key]
    anonKeys = [Key] -> [Key]
    forall a. Ord a => [a] -> [a]
    sort ([Key] -> [Key]) -> [Key] -> [Key]
    forall a b. (a -> b) -> a -> b
    $ (Key -> Bool) -> [Key] -> [Key]
    forall a. (a -> Bool) -> [a] -> [a]
    filter Key -> Bool
    isAnonKey ([Key] -> [Key]) -> [Key] -> [Key]
    forall a b. (a -> b) -> a -> b
    $ KeyTable -> [Key]
    forall k a. Map k a -> [k]
    M.keys KeyTable
    keyTable
                       case [Key]
    anonKeys of
                            []    -> ParsecT Text ParserState m Key
    forall (m :: * -> *) a. MonadPlus m => m a
    mzero
                            (k :: Key
    k:_) -> Key -> ParsecT Text ParserState m Key
    forall (m :: * -> *) a. Monad m => a -> m a
    return Key
    k
      ((src :: Text
    src,tit :: Text
    tit), attr :: Attr
    attr) <- [Key] -> Key -> RSTParser m ((Text, Text), Attr)
    forall (m :: * -> *).
    PandocMonad m =>
    [Key] -> Key -> RSTParser m ((Text, Text), Attr)
    lookupKey [] Key
    key
      -- if anonymous link, remove key so it won't be used again
      Bool
    -> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
    forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
    when (Key -> Bool
    isAnonKey Key
    key) (ParsecT Text ParserState m () -> ParsecT Text ParserState m ())
    -> ParsecT Text ParserState m () -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ (ParserState -> ParserState) -> ParsecT Text ParserState m ()
    forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
    updateState ((ParserState -> ParserState) -> ParsecT Text ParserState m ())
    -> (ParserState -> ParserState) -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ \s :: ParserState
    s ->
                              ParserState
    s{ stateKeys :: KeyTable
    stateKeys = Key -> KeyTable -> KeyTable
    forall k a. Ord k => k -> Map k a -> Map k a
    M.delete Key
    key KeyTable
    keyTable }
      Many Inline -> RSTParser m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline -> RSTParser m (Many Inline))
    -> Many Inline -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ Attr -> Text -> Text -> Many Inline -> Many Inline
    B.linkWith Attr
    attr Text
    src Text
    tit Many Inline
    label'

    -- We keep a list of oldkeys so we can detect lookup loops.
    lookupKey :: PandocMonad m
              => [Key] -> Key -> RSTParser m ((Text, Text), Attr)
    lookupKey :: [Key] -> Key -> RSTParser m ((Text, Text), Attr)
    lookupKey oldkeys :: [Key]
    oldkeys key :: Key
    key = do
      SourcePos
    pos <- ParsecT Text ParserState m SourcePos
    forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
    getPosition
      ParserState
    state <- ParsecT Text ParserState m ParserState
    forall (m :: * -> *) s u. Monad m => ParsecT s u m u
    getState
      let keyTable :: KeyTable
    keyTable = ParserState -> KeyTable
    stateKeys ParserState
    state
      case Key -> KeyTable -> Maybe ((Text, Text), Attr)
    forall k a. Ord k => k -> Map k a -> Maybe a
    M.lookup Key
    key KeyTable
    keyTable of
           Nothing  -> do
             let Key key' :: Text
    key' = Key
    key
             LogMessage -> ParserT Text ParserState m ()
    forall s (m :: * -> *) a st.
    (Stream s m a, HasLogMessages st) =>
    LogMessage -> ParserT s st m ()
    logMessage (LogMessage -> ParserT Text ParserState m ())
    -> LogMessage -> ParserT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ Text -> SourcePos -> LogMessage
    ReferenceNotFound Text
    key' SourcePos
    pos
             ((Text, Text), Attr) -> RSTParser m ((Text, Text), Attr)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (("",""),Attr
    nullAttr)
           -- check for keys of the form link_, which need to be resolved:
           Just ((u :: Text
    u, ""),_) | Text -> Int
    T.length Text
    u Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    > 1, Text -> Char
    T.last Text
    u Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    == '_', Text -> Char
    T.head Text
    u Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    /= '#' -> do
             let rawkey :: Text
    rawkey = Text -> Text
    T.init Text
    u
             let newkey :: Key
    newkey = Text -> Key
    toKey Text
    rawkey
             if Key
    newkey Key -> [Key] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `elem` [Key]
    oldkeys
                then do
                  LogMessage -> ParserT Text ParserState m ()
    forall s (m :: * -> *) a st.
    (Stream s m a, HasLogMessages st) =>
    LogMessage -> ParserT s st m ()
    logMessage (LogMessage -> ParserT Text ParserState m ())
    -> LogMessage -> ParserT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ Text -> SourcePos -> LogMessage
    CircularReference Text
    rawkey SourcePos
    pos
                  ((Text, Text), Attr) -> RSTParser m ((Text, Text), Attr)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (("",""),Attr
    nullAttr)
                else [Key] -> Key -> RSTParser m ((Text, Text), Attr)
    forall (m :: * -> *).
    PandocMonad m =>
    [Key] -> Key -> RSTParser m ((Text, Text), Attr)
    lookupKey (Key
    keyKey -> [Key] -> [Key]
    forall a. a -> [a] -> [a]
    :[Key]
    oldkeys) Key
    newkey
           Just val :: ((Text, Text), Attr)
    val -> ((Text, Text), Attr) -> RSTParser m ((Text, Text), Attr)
    forall (m :: * -> *) a. Monad m => a -> m a
    return ((Text, Text), Attr)
    val

    autoURI :: Monad m => RSTParser m Inlines
    autoURI :: RSTParser m (Many Inline)
    autoURI = do
      (orig :: Text
    orig, src :: Text
    src) <- ParserT Text ParserState m (Text, Text)
    forall s (m :: * -> *) st.
    Stream s m Char =>
    ParserT s st m (Text, Text)
    uri
      Many Inline -> RSTParser m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline -> RSTParser m (Many Inline))
    -> Many Inline -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ Text -> Text -> Many Inline -> Many Inline
    B.link Text
    src "" (Many Inline -> Many Inline) -> Many Inline -> Many Inline
    forall a b. (a -> b) -> a -> b
    $ Text -> Many Inline
    B.str Text
    orig

    autoEmail :: Monad m => RSTParser m Inlines
    autoEmail :: RSTParser m (Many Inline)
    autoEmail = do
      (orig :: Text
    orig, src :: Text
    src) <- ParserT Text ParserState m (Text, Text)
    forall s (m :: * -> *) st.
    Stream s m Char =>
    ParserT s st m (Text, Text)
    emailAddress
      Many Inline -> RSTParser m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline -> RSTParser m (Many Inline))
    -> Many Inline -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ Text -> Text -> Many Inline -> Many Inline
    B.link Text
    src "" (Many Inline -> Many Inline) -> Many Inline -> Many Inline
    forall a b. (a -> b) -> a -> b
    $ Text -> Many Inline
    B.str Text
    orig

    autoLink :: PandocMonad m => RSTParser m Inlines
    autoLink :: RSTParser m (Many Inline)
    autoLink = RSTParser m (Many Inline)
    forall (m :: * -> *). Monad m => RSTParser m (Many Inline)
    autoURI RSTParser m (Many Inline)
    -> RSTParser m (Many Inline) -> RSTParser m (Many Inline)
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> RSTParser m (Many Inline)
    forall (m :: * -> *). Monad m => RSTParser m (Many Inline)
    autoEmail

    subst :: PandocMonad m => RSTParser m Inlines
    subst :: RSTParser m (Many Inline)
    subst = RSTParser m (Many Inline) -> RSTParser m (Many Inline)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m (Many Inline) -> RSTParser m (Many Inline))
    -> RSTParser m (Many Inline) -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ do
      (_,ref :: Text
    ref) <- ParsecT Text ParserState m [Many Inline]
    -> ParsecT Text ParserState m ([Many Inline], Text)
    forall (m :: * -> *) st a.
    Monad m =>
    ParsecT Text st m a -> ParsecT Text st m (a, Text)
    withRaw (ParsecT Text ParserState m [Many Inline]
     -> ParsecT Text ParserState m ([Many Inline], Text))
    -> ParsecT Text ParserState m [Many Inline]
    -> ParsecT Text ParserState m ([Many Inline], Text)
    forall a b. (a -> b) -> a -> b
    $ ParserT Text ParserState m Char
    -> ParserT Text ParserState m Char
    -> RSTParser m (Many Inline)
    -> ParsecT Text ParserState m [Many Inline]
    forall end s (m :: * -> *) st t a.
    (Show end, Stream s m Char) =>
    ParserT s st m t
    -> ParserT s st m end -> ParserT s st m a -> ParserT s st m [a]
    enclosed (Char -> ParserT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '|') (Char -> ParserT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '|') RSTParser m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    inline
      ParserState
    state <- ParsecT Text ParserState m ParserState
    forall (m :: * -> *) s u. Monad m => ParsecT s u m u
    getState
      let substTable :: SubstTable
    substTable = ParserState -> SubstTable
    stateSubstitutions ParserState
    state
      let key :: Key
    key = Text -> Key
    toKey (Text -> Key) -> Text -> Key
    forall a b. (a -> b) -> a -> b
    $ Text -> Text
    stripFirstAndLast Text
    ref
      case Key -> SubstTable -> Maybe (Many Inline)
    forall k a. Ord k => k -> Map k a -> Maybe a
    M.lookup Key
    key SubstTable
    substTable of
           Nothing     -> do
             SourcePos
    pos <- ParsecT Text ParserState m SourcePos
    forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
    getPosition
             LogMessage -> ParserT Text ParserState m ()
    forall s (m :: * -> *) a st.
    (Stream s m a, HasLogMessages st) =>
    LogMessage -> ParserT s st m ()
    logMessage (LogMessage -> ParserT Text ParserState m ())
    -> LogMessage -> ParserT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ Text -> SourcePos -> LogMessage
    ReferenceNotFound (Key -> Text
    forall a. Show a => a -> Text
    tshow Key
    key) SourcePos
    pos
             Many Inline -> RSTParser m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return Many Inline
    forall a. Monoid a => a
    mempty
           Just target :: Many Inline
    target -> Many Inline -> RSTParser m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return Many Inline
    target

    note :: PandocMonad m => RSTParser m Inlines
    note :: RSTParser m (Many Inline)
    note = RSTParser m (Many Inline) -> RSTParser m (Many Inline)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m (Many Inline) -> RSTParser m (Many Inline))
    -> RSTParser m (Many Inline) -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ do
      RSTParser m (Many Inline) -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    ParsecT s u m a -> ParsecT s u m ()
    optional RSTParser m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    whitespace
      Text
    ref <- RSTParser m Text
    forall (m :: * -> *). Monad m => RSTParser m Text
    noteMarker
      Char -> ParsecT Text ParserState m Char
    forall s (m :: * -> *) u.
    Stream s m Char =>
    Char -> ParsecT s u m Char
    char '_'
      ParserState
    state <- ParsecT Text ParserState m ParserState
    forall (m :: * -> *) s u. Monad m => ParsecT s u m u
    getState
      let notes :: NoteTable
    notes = ParserState -> NoteTable
    stateNotes ParserState
    state
      case Text -> NoteTable -> Maybe Text
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup Text
    ref NoteTable
    notes of
        Nothing   -> do
          SourcePos
    pos <- ParsecT Text ParserState m SourcePos
    forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
    getPosition
          LogMessage -> ParsecT Text ParserState m ()
    forall s (m :: * -> *) a st.
    (Stream s m a, HasLogMessages st) =>
    LogMessage -> ParserT s st m ()
    logMessage (LogMessage -> ParsecT Text ParserState m ())
    -> LogMessage -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ Text -> SourcePos -> LogMessage
    ReferenceNotFound Text
    ref SourcePos
    pos
          Many Inline -> RSTParser m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return Many Inline
    forall a. Monoid a => a
    mempty
        Just raw :: Text
    raw  -> do
          -- We temporarily empty the note list while parsing the note,
          -- so that we don't get infinite loops with notes inside notes...
          -- Note references inside other notes are allowed in reST, but
          -- not yet in this implementation.
          (ParserState -> ParserState) -> ParsecT Text ParserState m ()
    forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
    updateState ((ParserState -> ParserState) -> ParsecT Text ParserState m ())
    -> (ParserState -> ParserState) -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ \st :: ParserState
    st -> ParserState
    st{ stateNotes :: NoteTable
    stateNotes = [] }
          Blocks
    contents <- ParserT Text ParserState m Blocks
    -> Text -> ParserT Text ParserState m Blocks
    forall s (m :: * -> *) u a.
    (Stream s m Char, IsString s, HasLastStrPosition u) =>
    ParserT s u m a -> Text -> ParserT s u m a
    parseFromString' ParserT Text ParserState m Blocks
    forall (m :: * -> *). PandocMonad m => RSTParser m Blocks
    parseBlocks Text
    raw
          let newnotes :: NoteTable
    newnotes = if Text
    ref Text -> Text -> Bool
    forall a. Eq a => a -> a -> Bool
    == "*" Bool -> Bool -> Bool
    || Text
    ref Text -> Text -> Bool
    forall a. Eq a => a -> a -> Bool
    == "#" -- auto-numbered
                            -- delete the note so the next auto-numbered note
                            -- doesn't get the same contents:
                            then ((Text, Text) -> (Text, Text) -> Bool)
    -> NoteTable -> NoteTable -> NoteTable
    forall a. (a -> a -> Bool) -> [a] -> [a] -> [a]
    deleteFirstsBy (Text, Text) -> (Text, Text) -> Bool
    forall a. Eq a => a -> a -> Bool
    (==) NoteTable
    notes [(Text
    ref,Text
    raw)]
                            else NoteTable
    notes
          (ParserState -> ParserState) -> ParsecT Text ParserState m ()
    forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
    updateState ((ParserState -> ParserState) -> ParsecT Text ParserState m ())
    -> (ParserState -> ParserState) -> ParsecT Text ParserState m ()
    forall a b. (a -> b) -> a -> b
    $ \st :: ParserState
    st -> ParserState
    st{ stateNotes :: NoteTable
    stateNotes = NoteTable
    newnotes }
          Many Inline -> RSTParser m (Many Inline)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Many Inline -> RSTParser m (Many Inline))
    -> Many Inline -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ Blocks -> Many Inline
    B.note Blocks
    contents

    smart :: PandocMonad m => RSTParser m Inlines
    smart :: RSTParser m (Many Inline)
    smart = do
      Extension -> ParserT Text ParserState m ()
    forall s (m :: * -> *) a st.
    (Stream s m a, HasReaderOptions st) =>
    Extension -> ParserT s st m ()
    guardEnabled Extension
    Ext_smart
      RSTParser m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    doubleQuoted RSTParser m (Many Inline)
    -> RSTParser m (Many Inline) -> RSTParser m (Many Inline)
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|> RSTParser m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    singleQuoted RSTParser m (Many Inline)
    -> RSTParser m (Many Inline) -> RSTParser m (Many Inline)
    forall s u (m :: * -> *) a.
    ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
    <|>
        [RSTParser m (Many Inline)] -> RSTParser m (Many Inline)
    forall s (m :: * -> *) t u a.
    Stream s m t =>
    [ParsecT s u m a] -> ParsecT s u m a
    choice [RSTParser m (Many Inline)
    forall s (m :: * -> *) st.
    Stream s m Char =>
    ParserT s st m (Many Inline)
    apostrophe, RSTParser m (Many Inline)
    forall st s (m :: * -> *).
    (HasReaderOptions st, Stream s m Char) =>
    ParserT s st m (Many Inline)
    dash, RSTParser m (Many Inline)
    forall s (m :: * -> *) st.
    Stream s m Char =>
    ParserT s st m (Many Inline)
    ellipses]

    singleQuoted :: PandocMonad m => RSTParser m Inlines
    singleQuoted :: RSTParser m (Many Inline)
    singleQuoted = RSTParser m (Many Inline) -> RSTParser m (Many Inline)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m (Many Inline) -> RSTParser m (Many Inline))
    -> RSTParser m (Many Inline) -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ do
      ParserT Text ParserState m ()
    forall st (m :: * -> *) s.
    (HasLastStrPosition st, HasQuoteContext st m, Stream s m Char) =>
    ParserT s st m ()
    singleQuoteStart
      QuoteContext
    -> RSTParser m (Many Inline) -> RSTParser m (Many Inline)
    forall st (m :: * -> *) s a.
    HasQuoteContext st m =>
    QuoteContext -> ParsecT s st m a -> ParsecT s st m a
    withQuoteContext QuoteContext
    InSingleQuote (RSTParser m (Many Inline) -> RSTParser m (Many Inline))
    -> RSTParser m (Many Inline) -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $
        Many Inline -> Many Inline
    B.singleQuoted (Many Inline -> Many Inline)
    -> ([Many Inline] -> Many Inline) -> [Many Inline] -> Many Inline
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Many Inline -> Many Inline
    trimInlines (Many Inline -> Many Inline)
    -> ([Many Inline] -> Many Inline) -> [Many Inline] -> Many Inline
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Many Inline] -> Many Inline
    forall a. Monoid a => [a] -> a
    mconcat ([Many Inline] -> Many Inline)
    -> ParsecT Text ParserState m [Many Inline]
    -> RSTParser m (Many Inline)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$>
          RSTParser m (Many Inline)
    -> ParserT Text ParserState m ()
    -> ParsecT Text ParserState m [Many Inline]
    forall end s (m :: * -> *) t st a.
    (Show end, Stream s m t) =>
    ParserT s st m a -> ParserT s st m end -> ParserT s st m [a]
    many1Till RSTParser m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    inline ParserT Text ParserState m ()
    forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
    singleQuoteEnd

    doubleQuoted :: PandocMonad m => RSTParser m Inlines
    doubleQuoted :: RSTParser m (Many Inline)
    doubleQuoted = RSTParser m (Many Inline) -> RSTParser m (Many Inline)
    forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
    try (RSTParser m (Many Inline) -> RSTParser m (Many Inline))
    -> RSTParser m (Many Inline) -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $ do
      ParserT Text ParserState m ()
    forall st (m :: * -> *) s.
    (HasQuoteContext st m, Stream s m Char) =>
    ParserT s st m ()
    doubleQuoteStart
      QuoteContext
    -> RSTParser m (Many Inline) -> RSTParser m (Many Inline)
    forall st (m :: * -> *) s a.
    HasQuoteContext st m =>
    QuoteContext -> ParsecT s st m a -> ParsecT s st m a
    withQuoteContext QuoteContext
    InDoubleQuote (RSTParser m (Many Inline) -> RSTParser m (Many Inline))
    -> RSTParser m (Many Inline) -> RSTParser m (Many Inline)
    forall a b. (a -> b) -> a -> b
    $
        Many Inline -> Many Inline
    B.doubleQuoted (Many Inline -> Many Inline)
    -> ([Many Inline] -> Many Inline) -> [Many Inline] -> Many Inline
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Many Inline -> Many Inline
    trimInlines (Many Inline -> Many Inline)
    -> ([Many Inline] -> Many Inline) -> [Many Inline] -> Many Inline
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Many Inline] -> Many Inline
    forall a. Monoid a => [a] -> a
    mconcat ([Many Inline] -> Many Inline)
    -> ParsecT Text ParserState m [Many Inline]
    -> RSTParser m (Many Inline)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$>
          RSTParser m (Many Inline)
    -> ParserT Text ParserState m ()
    -> ParsecT Text ParserState m [Many Inline]
    forall end s (m :: * -> *) t st a.
    (Show end, Stream s m t) =>
    ParserT s st m a -> ParserT s st m end -> ParserT s st m [a]
    many1Till RSTParser m (Many Inline)
    forall (m :: * -> *). PandocMonad m => RSTParser m (Many Inline)
    inline ParserT Text ParserState m ()
    forall s (m :: * -> *) st. Stream s m Char => ParserT s st m ()
    doubleQuoteEnd