git.iko.soy/typeable/pandoc
on master help sign in
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

commit48b8267126fc82aadf289762718b8c01e5331e4c authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateThu 21 Dec 2006, 09:02 (20 years ago) parent862471e
4 files changed+36−42
src/Text/Pandoc/Readers/LaTeX.hs+6−5 src/Text/Pandoc/Readers/Markdown.hs+22−25 src/Text/Pandoc/Readers/RST.hs+7−10 src/Text/Pandoc/Shared.hs+1−2
src/Text/Pandoc/Readers/LaTeX.hs+6−5
@@ -601,13 +601,14 @@ footnote = try (do
601601 then string ""
602602 else fail "not a footnote or thanks command"
603603 let contents' = stripFirstAndLast contents
604+ -- parse the extracted block, which may contain various block elements:
605+ rest <- getInput
606+ setInput $ contents'
607+ blocks <- parseBlocks
608+ setInput rest
604609 state <- getState
605− let blocks = case runParser parseBlocks state "footnote" contents of
606− Left err -> error $ "Input:\n" ++ show contents' ++
607− "\nError:\n" ++ show err
608− Right result -> result
609610 let notes = stateNoteBlocks state
610− let nextRef = case notes of
611+ let nextRef = case notes of
611612 [] -> "1"
612613 (Note ref body):rest -> (show ((read ref) + 1))
613614 setState (state { stateNoteBlocks = (Note nextRef blocks):notes })
src/Text/Pandoc/Readers/Markdown.hs+22−25
@@ -263,17 +263,15 @@ note = try (do
263263 raw <- sepBy rawLines (try (do {blankline; indentSpaces}))
264264 option "" blanklines
265265 -- parse the extracted text, which may contain various block elements:
266+ rest <- getInput
267+ setInput $ (joinWithSep "\n" raw) ++ "\n\n"
268+ contents <- parseBlocks
269+ setInput rest
266270 state <- getState
267− let parsed = case runParser parseBlocks
268− (state {stateParserContext = BlockQuoteState}) "block"
269− ((joinWithSep "\n" raw) ++ "\n\n") of
270− Left err -> error $ "Raw block:\n" ++ show raw ++
271− "\nError:\n" ++ show err
272− Right result -> result
273271 let identifiers = stateNoteIdentifiers state
274272 case (findIndex (== ref) identifiers) of
275273 Just n -> updateState (\s -> s {stateNoteBlocks =
276− (Note (show (n+1)) parsed):(stateNoteBlocks s)})
274+ (Note (show (n+1)) contents):(stateNoteBlocks s)})
277275 Nothing -> updateState id
278276 return Null)
279277
@@ -315,15 +313,12 @@ emailBlockQuote = try (do
315313blockQuote = do
316314 raw <- choice [ emailBlockQuote, emacsBoxQuote ]
317315 -- parse the extracted block, which may contain various block elements:
318− state <- getState
319− let parsed = case runParser parseBlocks
320− (state {stateParserContext = BlockQuoteState}) "block"
321− ((joinWithSep "\n" raw) ++ "\n\n") of
322− Left err -> error $ "Raw block:\n" ++ show raw ++
323− "\nError:\n" ++ show err
324− Right result -> result
325− return (BlockQuote parsed)
326−
316+ rest <- getInput
317+ setInput $ (joinWithSep "\n" raw) ++ "\n\n"
318+ contents <- parseBlocks
319+ setInput rest
320+ return (BlockQuote contents)
321+
327322--
328323-- list blocks
329324--
@@ -382,19 +377,21 @@ listContinuationLine start = try (do
382377
383378listItem start = try (do
384379 first <- rawListItem start
385− rest <- many (listContinuation start)
380+ continuations <- many (listContinuation start)
386381 -- parsing with ListItemState forces markers at beginning of lines to
387382 -- count as list item markers, even if not separated by blank space.
388383 -- see definition of "endline"
389384 state <- getState
390− let parsed = case runParser parseBlocks
391− (state {stateParserContext = ListItemState})
392− "block" raw of
393− Left err -> error $ "Raw block:\n" ++ raw ++
394− "\nError:\n" ++ show err
395− Right result -> result
396− where raw = concat (first:rest)
397− return parsed)
385+ let oldContext = stateParserContext state
386+ setState $ state {stateParserContext = ListItemState}
387+ -- parse the extracted block, which may contain various block elements:
388+ rest <- getInput
389+ let raw = concat (first:continuations)
390+ setInput $ raw
391+ contents <- parseBlocks
392+ setInput rest
393+ updateState (\st -> st {stateParserContext = oldContext})
394+ return contents)
398395
399396orderedList = try (do
400397 items <- many1 (listItem orderedListStart)
src/Text/Pandoc/Readers/RST.hs+7−10
@@ -112,7 +112,7 @@ parseRST = do
112112 "RST source, second pass" input of
113113 Left err -> error $ "\nError:\n" ++ show err
114114 Right result ->
115− (filter isNotAnonKeyBlock result)
115+ filter isNotAnonKeyBlock result
116116 let (blocks'', title) = if stateStandalone state
117117 then titleTransform blocks'
118118 else (blocks', [])
@@ -352,16 +352,13 @@ rawLaTeXBlock = try (do
352352--
353353
354354blockQuote = try (do
355− block <- indentedBlock True
355+ raw <- indentedBlock True
356356 -- parse the extracted block, which may contain various block elements:
357− state <- getState
358− let parsed = case runParser parseBlocks
359− (state {stateParserContext = BlockQuoteState})
360− "block" (block ++ "\n\n") of
361− Left err -> error $ "Raw block:\n" ++ show block ++
362− "\nError:\n" ++ show err
363− Right result -> result
364− return (BlockQuote parsed))
357+ rest <- getInput
358+ setInput $ raw ++ "\n\n"
359+ contents <- parseBlocks
360+ setInput rest
361+ return (BlockQuote contents))
365362
366363--
367364-- list blocks
src/Text/Pandoc/Shared.hs+1−2
@@ -95,8 +95,7 @@ data HeaderType
9595 deriving (Eq, Show)
9696
9797data ParserContext
98− = BlockQuoteState -- ^ Used when running parser on contents of blockquote
99− | ListItemState -- ^ Used when running parser on list item contents
98+ = ListItemState -- ^ Used when running parser on list item contents
10099 | NullState -- ^ Default state
101100 deriving (Eq, Show)
102101