@@ -95,8 +95,8 @@ parseRST = do
9595 startPos <- getPosition
9696 -- go through once just to get list of reference keys and notes
9797 -- docMinusKeys is the raw document with blanks where the keys were...
98− docMinusKeys <- manyTill (referenceKey <|> noteBlock <|> lineClump) eof >>=
99− return . concat
98+ docMinusKeys <- manyTill (referenceKey <|> imageKey <|>
99+ noteBlock <|> lineClump) eof >>= return . concat
100100 setInput docMinusKeys
101101 setPosition startPos
102102 st' <- getState
@@ -652,7 +652,7 @@ referenceName = quotedReferenceName <|>
652652referenceKey :: Parser [Char] ParserState [Char]
653653referenceKey = do
654654 startPos <- getPosition
655− (key, target) <- choice [imageKey, anonymousKey, regularKey]
655+ (key, target) <- choice [anonymousKey, regularKey]
656656 st <- getState
657657 let oldkeys = stateKeys st
658658 updateState $ \s -> s { stateKeys = M.insert key target oldkeys }
@@ -670,14 +670,21 @@ targetURI = do
670670 blanklines
671671 return $ escapeURI $ removeLeadingTrailingSpace $ contents
672672
673−imageKey :: Parser [Char] ParserState (Key, Target)
673+imageKey :: Parser [Char] ParserState [Char]
674674imageKey = try $ do
675+ startPos <- getPosition
675676 string ".. |"
676− (_,ref) <- withRaw (manyTill inline (char '|'))
677+ (alt,ref) <- withRaw (manyTill inline (char '|'))
677678 skipSpaces
678679 string "image::"
679680 src <- targetURI
680− return (toKey $ init ref, (src, ""))
681+ let img = Image alt (src,"")
682+ let key = toKey $ init ref
683+ updateState $ \s -> s{ stateSubstitutions = M.insert key img $ stateSubstitutions s }
684+ optional blanklines
685+ endPos <- getPosition
686+ -- return enough blanks to replace key
687+ return $ replicate (sourceLine endPos - sourceLine startPos) '\n'
681688
682689anonymousKey :: Parser [Char] st (Key, Target)
683690anonymousKey = try $ do
@@ -965,13 +972,12 @@ autoLink = autoURI <|> autoEmail
965972image :: Parser [Char] ParserState Inline
966973image = try $ do
967974 char '|'
968− (alt,ref) <- withRaw (manyTill inline (char '|'))
975+ (_,ref) <- withRaw (manyTill inline (char '|'))
969976 state <- getState
970− let keyTable = stateKeys state
971− (src,tit) <- case M.lookup (toKey $ init ref) keyTable of
972− Nothing -> fail "no corresponding key"
973− Just target -> return target
974− return $ Image (normalizeSpaces alt) (src, tit)
977+ let substTable = stateSubstitutions state
978+ case M.lookup (toKey $ init ref) substTable of
979+ Nothing -> fail "no corresponding key"
980+ Just target -> return target
975981
976982note :: Parser [Char] ParserState Inline
977983note = try $ do