@@ -170,7 +170,8 @@ parseRST = do
170170 -- go through once just to get list of reference keys and notes
171171 -- docMinusKeys is the raw document with blanks where the keys were...
172172 docMinusKeys <- concat <$>
173− manyTill (referenceKey <|> noteBlock <|> citationBlock <|>
173+ manyTill (referenceKey <|> anchorDef <|>
174+ noteBlock <|> citationBlock <|>
174175 headerBlock <|> lineClump) eof
175176 setInput docMinusKeys
176177 setPosition startPos
@@ -217,6 +218,7 @@ block = choice [ codeBlock
217218 , fieldList
218219 , include
219220 , directive
221+ , anchor
220222 , comment
221223 , header
222224 , hrule
@@ -1072,12 +1074,32 @@ regularKey = try $ do
10721074 -- .. _goodbye: url.com
10731075 refs <- referenceNames
10741076 src <- targetURI
1077+ guard $ not (null src)
10751078 --TODO: parse width, height, class and name attributes
10761079 let keys = map (toKey . stripTicks) refs
10771080 forM_ keys $ \key ->
10781081 updateState $ \s -> s { stateKeys = M.insert key ((src,""), nullAttr) $
10791082 stateKeys s }
10801083
1084+anchorDef :: PandocMonad m => RSTParser m [Char]
1085+anchorDef = try $ do
1086+ (refs, raw) <- withRaw (try (referenceNames <* blanklines))
1087+ let keys = map stripTicks refs
1088+ forM_ keys $ \rawkey ->
1089+ updateState $ \s -> s { stateKeys =
1090+ M.insert (toKey rawkey) (('#':rawkey,""), nullAttr) $ stateKeys s }
1091+ -- keep this for 2nd round of parsing, where we'll add the divs (anchor)
1092+ return raw
1093+
1094+anchor :: PandocMonad m => RSTParser m Blocks
1095+anchor = try $ do
1096+ refs <- referenceNames
1097+ blanklines
1098+ b <- block
1099+ -- put identifier on next block:
1100+ let addDiv ref = B.divWith (ref, [], [])
1101+ return $ foldr addDiv b refs
1102+
10811103headerBlock :: PandocMonad m => RSTParser m [Char]
10821104headerBlock = do
10831105 ((txt, _), raw) <- withRaw (doubleHeader' <|> singleHeader')