summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
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)