@@ -31,7 +31,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3131Conversion from reStructuredText to 'Pandoc' document.
3232-}
3333module Text.Pandoc.Readers.RST ( readRST ) where
34−import Control.Monad (guard, liftM, mzero, when)
34+import Control.Monad (guard, liftM, mzero, when, forM_)
3535import Control.Monad.Identity (Identity(..))
3636import Control.Monad.Except (throwError)
3737import Data.Char (isHexDigit, isSpace, toLower, toUpper)
@@ -1054,16 +1054,29 @@ stripTicks = reverse . stripTick . reverse . stripTick
10541054 where stripTick ('`':xs) = xs
10551055 stripTick xs = xs
10561056
1057+referenceNames :: PandocMonad m => RSTParser m [String]
1058+referenceNames = do
1059+ let rn = try $ do
1060+ string ".. _"
1061+ (_, ref) <- withRaw referenceName
1062+ char ':'
1063+ return ref
1064+ first <- rn
1065+ rest <- many (try (blanklines *> rn))
1066+ return (first:rest)
1067+
10571068regularKey :: PandocMonad m => RSTParser m ()
10581069regularKey = try $ do
1059− string ".. _"
1060− (_,ref) <- withRaw referenceName
1061− char ':'
1070+ -- we allow several references to the same URL, e.g.
1071+ -- .. _hello:
1072+ -- .. _goodbye: url.com
1073+ refs <- referenceNames
10621074 src <- targetURI
1063− let key = toKey $ stripTicks ref
10641075 --TODO: parse width, height, class and name attributes
1065− updateState $ \s -> s { stateKeys = M.insert key ((src,""), nullAttr) $
1066− stateKeys s }
1076+ let keys = map (toKey . stripTicks) refs
1077+ forM_ keys $ \key ->
1078+ updateState $ \s -> s { stateKeys = M.insert key ((src,""), nullAttr) $
1079+ stateKeys s }
10671080
10681081headerBlock :: PandocMonad m => RSTParser m [Char]
10691082headerBlock = do