git.iko.soy/typeable/pandoc
on master help sign in
Refactor RST and Markdown readers using parseFromString.
81eba06fiddlosopher
src/Text/Pandoc/Readers/Markdown.hs+4−16
@@ -195,10 +195,7 @@ noteBlock = try $ do
195 raw <- sepBy rawLines (try (blankline >> indentSpaces))
195 raw <- sepBy rawLines (try (blankline >> indentSpaces))
196 optional blanklines
196 optional blanklines
197 -- parse the extracted text, which may contain various block elements:
197 -- parse the extracted text, which may contain various block elements:
198− rest <- getInput
199− setInput $ (joinWithSep "\n" raw) ++ "\n\n"
198+ contents <- parseFromString parseBlocks $ (joinWithSep "\n" raw) ++ "\n\n"
200− contents <- parseBlocks
201− setInput rest
202 return $ NoteBlock ref contents
199 return $ NoteBlock ref contents
203
200
204--
201--
@@ -307,10 +304,7 @@ emailBlockQuote = try $ do
307blockQuote = do
304blockQuote = do
308 raw <- emailBlockQuote <|> emacsBoxQuote
305 raw <- emailBlockQuote <|> emacsBoxQuote
309 -- parse the extracted block, which may contain various block elements:
306 -- parse the extracted block, which may contain various block elements:
310− rest <- getInput
311− setInput $ (joinWithSep "\n" raw) ++ "\n\n"
307+ contents <- parseFromString parseBlocks $ (joinWithSep "\n" raw) ++ "\n\n"
312− contents <- parseBlocks
313− setInput rest
314 return $ BlockQuote contents
308 return $ BlockQuote contents
315
309
316--
310--
@@ -393,11 +387,8 @@ listItem start = try $ do
393 let oldContext = stateParserContext state
387 let oldContext = stateParserContext state
394 setState $ state {stateParserContext = ListItemState}
388 setState $ state {stateParserContext = ListItemState}
395 -- parse the extracted block, which may contain various block elements:
389 -- parse the extracted block, which may contain various block elements:
396− rest <- getInput
397 let raw = concat (first:continuations)
390 let raw = concat (first:continuations)
398− setInput raw
399− contents <- parseBlocks
391+ contents <- parseFromString parseBlocks raw
400− setInput rest
401 updateState (\st -> st {stateParserContext = oldContext})
392 updateState (\st -> st {stateParserContext = oldContext})
402 return contents
393 return contents
403
394
@@ -419,10 +410,7 @@ definitionListItem = try $ do
419 state <- getState
410 state <- getState
420 let oldContext = stateParserContext state
411 let oldContext = stateParserContext state
421 -- parse the extracted block, which may contain various block elements:
412 -- parse the extracted block, which may contain various block elements:
422− rest <- getInput
423− setInput (concat raw)
424− contents <- parseBlocks
413+ contents <- parseFromString parseBlocks $ concat raw
425− setInput rest
426 updateState (\st -> st {stateParserContext = oldContext})
414 updateState (\st -> st {stateParserContext = oldContext})
427 return ((normalizeSpaces term), contents)
415 return ((normalizeSpaces term), contents)
428
416
src/Text/Pandoc/Readers/RST.hs+3−12
@@ -328,10 +328,7 @@ rawLaTeXBlock = try $ do
328blockQuote = try $ do
328blockQuote = try $ do
329 raw <- indentedBlock True
329 raw <- indentedBlock True
330 -- parse the extracted block, which may contain various block elements:
330 -- parse the extracted block, which may contain various block elements:
331− rest <- getInput
331+ contents <- parseFromString parseBlocks $ raw ++ "\n\n"
332− setInput $ raw ++ "\n\n"
333− contents <- parseBlocks
334− setInput rest
335 return $ BlockQuote contents
332 return $ BlockQuote contents
336
333
337--
334--
@@ -344,10 +341,7 @@ definitionListItem = try $ do
344 term <- many1Till inline endline
341 term <- many1Till inline endline
345 raw <- indentedBlock True
342 raw <- indentedBlock True
346 -- parse the extracted block, which may contain various block elements:
343 -- parse the extracted block, which may contain various block elements:
347− rest <- getInput
344+ contents <- parseFromString parseBlocks $ raw ++ "\n\n"
348− setInput $ raw ++ "\n\n"
349− contents <- parseBlocks
350− setInput rest
351 return (normalizeSpaces term, contents)
345 return (normalizeSpaces term, contents)
352
346
353definitionList = try $ do
347definitionList = try $ do
@@ -408,12 +402,9 @@ listItem start = try $ do
408 -- see definition of "endline"
402 -- see definition of "endline"
409 state <- getState
403 state <- getState
410 let oldContext = stateParserContext state
404 let oldContext = stateParserContext state
411− remaining <- getInput
412 setState $ state {stateParserContext = ListItemState}
405 setState $ state {stateParserContext = ListItemState}
413 -- parse the extracted block, which may itself contain block elements
406 -- parse the extracted block, which may itself contain block elements
414− setInput $ concat (first:rest) ++ blanks
407+ parsed <- parseFromString parseBlocks $ concat (first:rest) ++ blanks
415− parsed <- parseBlocks
416− setInput remaining
417 updateState (\st -> st {stateParserContext = oldContext})
408 updateState (\st -> st {stateParserContext = oldContext})
418 return parsed
409 return parsed
419
410