aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Readers/RST.hs24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs
index c790d5188..2daf60a89 100644
--- a/src/Text/Pandoc/Readers/RST.hs
+++ b/src/Text/Pandoc/Readers/RST.hs
@@ -170,7 +170,8 @@ parseRST = do
-- go through once just to get list of reference keys and notes
-- docMinusKeys is the raw document with blanks where the keys were...
docMinusKeys <- concat <$>
- manyTill (referenceKey <|> noteBlock <|> citationBlock <|>
+ manyTill (referenceKey <|> anchorDef <|>
+ noteBlock <|> citationBlock <|>
headerBlock <|> lineClump) eof
setInput docMinusKeys
setPosition startPos
@@ -217,6 +218,7 @@ block = choice [ codeBlock
, fieldList
, include
, directive
+ , anchor
, comment
, header
, hrule
@@ -1072,12 +1074,32 @@ regularKey = try $ do
-- .. _goodbye: url.com
refs <- referenceNames
src <- targetURI
+ guard $ not (null src)
--TODO: parse width, height, class and name attributes
let keys = map (toKey . stripTicks) refs
forM_ keys $ \key ->
updateState $ \s -> s { stateKeys = M.insert key ((src,""), nullAttr) $
stateKeys s }
+anchorDef :: PandocMonad m => RSTParser m [Char]
+anchorDef = try $ do
+ (refs, raw) <- withRaw (try (referenceNames <* blanklines))
+ let keys = map stripTicks refs
+ forM_ keys $ \rawkey ->
+ updateState $ \s -> s { stateKeys =
+ M.insert (toKey rawkey) (('#':rawkey,""), nullAttr) $ stateKeys s }
+ -- keep this for 2nd round of parsing, where we'll add the divs (anchor)
+ return raw
+
+anchor :: PandocMonad m => RSTParser m Blocks
+anchor = try $ do
+ refs <- referenceNames
+ blanklines
+ b <- block
+ -- put identifier on next block:
+ let addDiv ref = B.divWith (ref, [], [])
+ return $ foldr addDiv b refs
+
headerBlock :: PandocMonad m => RSTParser m [Char]
headerBlock = do
((txt, _), raw) <- withRaw (doubleHeader' <|> singleHeader')