aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Parsing.hs5
-rw-r--r--src/Text/Pandoc/Readers/RST.hs30
2 files changed, 23 insertions, 12 deletions
diff --git a/src/Text/Pandoc/Parsing.hs b/src/Text/Pandoc/Parsing.hs
index bee96be82..bf4519a4f 100644
--- a/src/Text/Pandoc/Parsing.hs
+++ b/src/Text/Pandoc/Parsing.hs
@@ -71,6 +71,7 @@ module Text.Pandoc.Parsing ( (>>~),
NoteTable,
NoteTable',
KeyTable,
+ SubstTable,
Key (..),
toKey,
smartPunctuation,
@@ -720,6 +721,7 @@ data ParserState = ParserState
stateMaxNestingLevel :: Int, -- ^ Max # of nested Strong/Emph
stateLastStrPos :: Maybe SourcePos, -- ^ Position after last str parsed
stateKeys :: KeyTable, -- ^ List of reference keys (with fallbacks)
+ stateSubstitutions :: SubstTable, -- ^ List of substitution references
stateNotes :: NoteTable, -- ^ List of notes (raw bodies)
stateNotes' :: NoteTable', -- ^ List of notes (parsed bodies)
stateTitle :: [Inline], -- ^ Title of document
@@ -745,6 +747,7 @@ defaultParserState =
stateMaxNestingLevel = 6,
stateLastStrPos = Nothing,
stateKeys = M.empty,
+ stateSubstitutions = M.empty,
stateNotes = [],
stateNotes' = [],
stateTitle = [],
@@ -795,6 +798,8 @@ toKey = Key . map toLower . unwords . words
type KeyTable = M.Map Key Target
+type SubstTable = M.Map Key Inline
+
-- | Fail unless we're in "smart typography" mode.
failUnlessSmart :: Parser [tok] ParserState ()
failUnlessSmart = getOption readerSmart >>= guard
diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs
index 4527dba14..42a259538 100644
--- a/src/Text/Pandoc/Readers/RST.hs
+++ b/src/Text/Pandoc/Readers/RST.hs
@@ -95,8 +95,8 @@ parseRST = do
startPos <- getPosition
-- go through once just to get list of reference keys and notes
-- docMinusKeys is the raw document with blanks where the keys were...
- docMinusKeys <- manyTill (referenceKey <|> noteBlock <|> lineClump) eof >>=
- return . concat
+ docMinusKeys <- manyTill (referenceKey <|> imageKey <|>
+ noteBlock <|> lineClump) eof >>= return . concat
setInput docMinusKeys
setPosition startPos
st' <- getState
@@ -652,7 +652,7 @@ referenceName = quotedReferenceName <|>
referenceKey :: Parser [Char] ParserState [Char]
referenceKey = do
startPos <- getPosition
- (key, target) <- choice [imageKey, anonymousKey, regularKey]
+ (key, target) <- choice [anonymousKey, regularKey]
st <- getState
let oldkeys = stateKeys st
updateState $ \s -> s { stateKeys = M.insert key target oldkeys }
@@ -670,14 +670,21 @@ targetURI = do
blanklines
return $ escapeURI $ removeLeadingTrailingSpace $ contents
-imageKey :: Parser [Char] ParserState (Key, Target)
+imageKey :: Parser [Char] ParserState [Char]
imageKey = try $ do
+ startPos <- getPosition
string ".. |"
- (_,ref) <- withRaw (manyTill inline (char '|'))
+ (alt,ref) <- withRaw (manyTill inline (char '|'))
skipSpaces
string "image::"
src <- targetURI
- return (toKey $ init ref, (src, ""))
+ let img = Image alt (src,"")
+ let key = toKey $ init ref
+ updateState $ \s -> s{ stateSubstitutions = M.insert key img $ stateSubstitutions s }
+ optional blanklines
+ endPos <- getPosition
+ -- return enough blanks to replace key
+ return $ replicate (sourceLine endPos - sourceLine startPos) '\n'
anonymousKey :: Parser [Char] st (Key, Target)
anonymousKey = try $ do
@@ -965,13 +972,12 @@ autoLink = autoURI <|> autoEmail
image :: Parser [Char] ParserState Inline
image = try $ do
char '|'
- (alt,ref) <- withRaw (manyTill inline (char '|'))
+ (_,ref) <- withRaw (manyTill inline (char '|'))
state <- getState
- let keyTable = stateKeys state
- (src,tit) <- case M.lookup (toKey $ init ref) keyTable of
- Nothing -> fail "no corresponding key"
- Just target -> return target
- return $ Image (normalizeSpaces alt) (src, tit)
+ let substTable = stateSubstitutions state
+ case M.lookup (toKey $ init ref) substTable of
+ Nothing -> fail "no corresponding key"
+ Just target -> return target
note :: Parser [Char] ParserState Inline
note = try $ do