aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2006-12-21 09:02:06 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2006-12-21 09:02:06 +0000
commit48b8267126fc82aadf289762718b8c01e5331e4c (patch)
treec4c581bb4a12e9b12b0f2f5c91ad95b6537282fa /src/Text/Pandoc
parent862471e417a0a61082d33dacb78438b5b253b1c1 (diff)
downloadpandoc-48b8267126fc82aadf289762718b8c01e5331e4c.tar.gz
Fixed a serious bug in the Markdown reader (also affecting LaTeX
and RST readers). The problem: these readers ran 'runParser' on processed chunks of text to handle embedded block lists in lists and quotation blocks. But then any changes made to the parser state in these chunks was lost, as the state is local to the parser. So, for example, footnotes didn't work in quotes or list items. The fix: instead of calling runParser on some raw text, use setInput to make it the input, then parse it, then use setInput to restore the input to what it was before. This is shorter and more elegant, and it fixes the problem. 'BlockQuoteContext' was also eliminated from ParserContext, as it isn't used anywhere. git-svn-id: https://pandoc.googlecode.com/svn/trunk@261 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Readers/LaTeX.hs11
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs47
-rw-r--r--src/Text/Pandoc/Readers/RST.hs17
-rw-r--r--src/Text/Pandoc/Shared.hs3
4 files changed, 36 insertions, 42 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index 0b101b4d9..f82705bb2 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -601,13 +601,14 @@ footnote = try (do
then string ""
else fail "not a footnote or thanks command"
let contents' = stripFirstAndLast contents
+ -- parse the extracted block, which may contain various block elements:
+ rest <- getInput
+ setInput $ contents'
+ blocks <- parseBlocks
+ setInput rest
state <- getState
- let blocks = case runParser parseBlocks state "footnote" contents of
- Left err -> error $ "Input:\n" ++ show contents' ++
- "\nError:\n" ++ show err
- Right result -> result
let notes = stateNoteBlocks state
- let nextRef = case notes of
+ let nextRef = case notes of
[] -> "1"
(Note ref body):rest -> (show ((read ref) + 1))
setState (state { stateNoteBlocks = (Note nextRef blocks):notes })
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index 63a87e273..2556c0aac 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -263,17 +263,15 @@ note = try (do
raw <- sepBy rawLines (try (do {blankline; indentSpaces}))
option "" blanklines
-- parse the extracted text, which may contain various block elements:
+ rest <- getInput
+ setInput $ (joinWithSep "\n" raw) ++ "\n\n"
+ contents <- parseBlocks
+ setInput rest
state <- getState
- let parsed = case runParser parseBlocks
- (state {stateParserContext = BlockQuoteState}) "block"
- ((joinWithSep "\n" raw) ++ "\n\n") of
- Left err -> error $ "Raw block:\n" ++ show raw ++
- "\nError:\n" ++ show err
- Right result -> result
let identifiers = stateNoteIdentifiers state
case (findIndex (== ref) identifiers) of
Just n -> updateState (\s -> s {stateNoteBlocks =
- (Note (show (n+1)) parsed):(stateNoteBlocks s)})
+ (Note (show (n+1)) contents):(stateNoteBlocks s)})
Nothing -> updateState id
return Null)
@@ -315,15 +313,12 @@ emailBlockQuote = try (do
blockQuote = do
raw <- choice [ emailBlockQuote, emacsBoxQuote ]
-- parse the extracted block, which may contain various block elements:
- state <- getState
- let parsed = case runParser parseBlocks
- (state {stateParserContext = BlockQuoteState}) "block"
- ((joinWithSep "\n" raw) ++ "\n\n") of
- Left err -> error $ "Raw block:\n" ++ show raw ++
- "\nError:\n" ++ show err
- Right result -> result
- return (BlockQuote parsed)
-
+ rest <- getInput
+ setInput $ (joinWithSep "\n" raw) ++ "\n\n"
+ contents <- parseBlocks
+ setInput rest
+ return (BlockQuote contents)
+
--
-- list blocks
--
@@ -382,19 +377,21 @@ listContinuationLine start = try (do
listItem start = try (do
first <- rawListItem start
- rest <- many (listContinuation start)
+ continuations <- many (listContinuation start)
-- parsing with ListItemState forces markers at beginning of lines to
-- count as list item markers, even if not separated by blank space.
-- see definition of "endline"
state <- getState
- let parsed = case runParser parseBlocks
- (state {stateParserContext = ListItemState})
- "block" raw of
- Left err -> error $ "Raw block:\n" ++ raw ++
- "\nError:\n" ++ show err
- Right result -> result
- where raw = concat (first:rest)
- return parsed)
+ let oldContext = stateParserContext state
+ setState $ state {stateParserContext = ListItemState}
+ -- parse the extracted block, which may contain various block elements:
+ rest <- getInput
+ let raw = concat (first:continuations)
+ setInput $ raw
+ contents <- parseBlocks
+ setInput rest
+ updateState (\st -> st {stateParserContext = oldContext})
+ return contents)
orderedList = try (do
items <- many1 (listItem orderedListStart)
diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs
index 3132e78be..cec4f9313 100644
--- a/src/Text/Pandoc/Readers/RST.hs
+++ b/src/Text/Pandoc/Readers/RST.hs
@@ -112,7 +112,7 @@ parseRST = do
"RST source, second pass" input of
Left err -> error $ "\nError:\n" ++ show err
Right result ->
- (filter isNotAnonKeyBlock result)
+ filter isNotAnonKeyBlock result
let (blocks'', title) = if stateStandalone state
then titleTransform blocks'
else (blocks', [])
@@ -352,16 +352,13 @@ rawLaTeXBlock = try (do
--
blockQuote = try (do
- block <- indentedBlock True
+ raw <- indentedBlock True
-- parse the extracted block, which may contain various block elements:
- state <- getState
- let parsed = case runParser parseBlocks
- (state {stateParserContext = BlockQuoteState})
- "block" (block ++ "\n\n") of
- Left err -> error $ "Raw block:\n" ++ show block ++
- "\nError:\n" ++ show err
- Right result -> result
- return (BlockQuote parsed))
+ rest <- getInput
+ setInput $ raw ++ "\n\n"
+ contents <- parseBlocks
+ setInput rest
+ return (BlockQuote contents))
--
-- list blocks
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index c933742bd..8418ecffd 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -95,8 +95,7 @@ data HeaderType
deriving (Eq, Show)
data ParserContext
- = BlockQuoteState -- ^ Used when running parser on contents of blockquote
- | ListItemState -- ^ Used when running parser on list item contents
+ = ListItemState -- ^ Used when running parser on list item contents
| NullState -- ^ Default state
deriving (Eq, Show)