aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-06-27 14:35:03 +0200
committerJohn MacFarlane <jgm@berkeley.edu>2017-06-27 14:35:03 +0200
commit563c9c8687a62acc7361fb49126a1d2030f3a11e (patch)
tree1d6c4a0d304559dbdefd3a8d7a8fc1c64426777d
parenta868b238f253423281b2648896f184e7cdc05014 (diff)
downloadpandoc-563c9c8687a62acc7361fb49126a1d2030f3a11e.tar.gz
RST reader: Handle chained link definitions.
For example, .. _hello: .. _goodbye: example.com Here both `hello` and `goodbye` should link to `example.com`. Fixes the first part of #262.
-rw-r--r--src/Text/Pandoc/Readers/RST.hs27
-rw-r--r--test/command/262.md9
2 files changed, 29 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs
index d13f697b7..c790d5188 100644
--- a/src/Text/Pandoc/Readers/RST.hs
+++ b/src/Text/Pandoc/Readers/RST.hs
@@ -31,7 +31,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Conversion from reStructuredText to 'Pandoc' document.
-}
module Text.Pandoc.Readers.RST ( readRST ) where
-import Control.Monad (guard, liftM, mzero, when)
+import Control.Monad (guard, liftM, mzero, when, forM_)
import Control.Monad.Identity (Identity(..))
import Control.Monad.Except (throwError)
import Data.Char (isHexDigit, isSpace, toLower, toUpper)
@@ -1054,16 +1054,29 @@ stripTicks = reverse . stripTick . reverse . stripTick
where stripTick ('`':xs) = xs
stripTick xs = xs
+referenceNames :: PandocMonad m => RSTParser m [String]
+referenceNames = do
+ let rn = try $ do
+ string ".. _"
+ (_, ref) <- withRaw referenceName
+ char ':'
+ return ref
+ first <- rn
+ rest <- many (try (blanklines *> rn))
+ return (first:rest)
+
regularKey :: PandocMonad m => RSTParser m ()
regularKey = try $ do
- string ".. _"
- (_,ref) <- withRaw referenceName
- char ':'
+ -- we allow several references to the same URL, e.g.
+ -- .. _hello:
+ -- .. _goodbye: url.com
+ refs <- referenceNames
src <- targetURI
- let key = toKey $ stripTicks ref
--TODO: parse width, height, class and name attributes
- updateState $ \s -> s { stateKeys = M.insert key ((src,""), nullAttr) $
- stateKeys s }
+ let keys = map (toKey . stripTicks) refs
+ forM_ keys $ \key ->
+ updateState $ \s -> s { stateKeys = M.insert key ((src,""), nullAttr) $
+ stateKeys s }
headerBlock :: PandocMonad m => RSTParser m [Char]
headerBlock = do
diff --git a/test/command/262.md b/test/command/262.md
new file mode 100644
index 000000000..e23e2d866
--- /dev/null
+++ b/test/command/262.md
@@ -0,0 +1,9 @@
+```
+% pandoc -f rst
+`hello`_ and `goodbye`_
+
+.. _hello:
+.. _goodbye: example.com
+^D
+<p><a href="example.com">hello</a> and <a href="example.com">goodbye</a></p>
+```