aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2006-12-31 17:34:26 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2006-12-31 17:34:26 +0000
commit3f5194b3bf10331cc8ca8fe82a5bc56f7ca6355e (patch)
treef4b3d3f7d0c73fb56a77f38a86e87e4c74f04104 /src/Text/Pandoc/Readers
parent0b6dc98a0aba0e76567744c00ed6840215ca5d9d (diff)
downloadpandoc-3f5194b3bf10331cc8ca8fe82a5bc56f7ca6355e.tar.gz
Cleaned up some code in RST reader.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@354 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r--src/Text/Pandoc/Readers/RST.hs35
1 files changed, 15 insertions, 20 deletions
diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs
index cec4f9313..419876ed1 100644
--- a/src/Text/Pandoc/Readers/RST.hs
+++ b/src/Text/Pandoc/Readers/RST.hs
@@ -102,33 +102,28 @@ titleTransform blocks = (blocks, [])
parseRST = do
state <- getState
input <- getInput
- blocks <- parseBlocks -- first pass
- let anonymousKeys = filter isAnonKeyBlock blocks
- let blocks' = if (null anonymousKeys)
- then blocks
- else -- run parser again to fill in anonymous links...
- case runParser parseBlocks
- (state { stateKeyBlocks = anonymousKeys })
- "RST source, second pass" input of
- Left err -> error $ "\nError:\n" ++ show err
- Right result ->
- filter isNotAnonKeyBlock result
+ -- first pass: get anonymous keys
+ keyBlocks <- manyTill (anonymousKey <|> (do{anyLine; return Null})) eof
+ let anonymousKeys = filter (/= Null) keyBlocks
+ -- run parser again to fill in anonymous links...
+ setState (state { stateKeyBlocks = anonymousKeys })
+ setInput input
+ blocks <- parseBlocks
+ let blocks' = filter isNotAnonKeyBlock blocks
let (blocks'', title) = if stateStandalone state
- then titleTransform blocks'
- else (blocks', [])
- state <- getState
- let authors = stateAuthors state
- let date = stateDate state
- let title' = if (null title) then (stateTitle state) else title
+ then titleTransform blocks'
+ else (blocks', [])
+ state' <- getState
+ let authors = stateAuthors state'
+ let date = stateDate state'
+ let title' = if (null title) then (stateTitle state') else title
return (Pandoc (Meta title' authors date) blocks'')
--
-- parsing blocks
--
-parseBlocks = do
- result <- manyTill block eof
- return result
+parseBlocks = manyTill block eof
block = choice [ codeBlock, rawHtmlBlock, rawLaTeXBlock, blockQuote,
referenceKey, imageBlock, unknownDirective, header,