Refactor RST and Markdown readers using parseFromString.

git-svn-id: https://pandoc.googlecode.com/svn/trunk@864 788f1e2b-df1e-0410-8736-df70ead52e1b
This commit is contained in:
fiddlosopher 2007-08-19 00:18:46 +00:00
parent 4e149f898a
commit 81eba062f2
2 changed files with 7 additions and 28 deletions

View file

@ -195,10 +195,7 @@ noteBlock = try $ do
raw <- sepBy rawLines (try (blankline >> indentSpaces))
optional blanklines
-- parse the extracted text, which may contain various block elements:
rest <- getInput
setInput $ (joinWithSep "\n" raw) ++ "\n\n"
contents <- parseBlocks
setInput rest
contents <- parseFromString parseBlocks $ (joinWithSep "\n" raw) ++ "\n\n"
return $ NoteBlock ref contents
--
@ -307,10 +304,7 @@ emailBlockQuote = try $ do
blockQuote = do
raw <- emailBlockQuote <|> emacsBoxQuote
-- parse the extracted block, which may contain various block elements:
rest <- getInput
setInput $ (joinWithSep "\n" raw) ++ "\n\n"
contents <- parseBlocks
setInput rest
contents <- parseFromString parseBlocks $ (joinWithSep "\n" raw) ++ "\n\n"
return $ BlockQuote contents
--
@ -393,11 +387,8 @@ listItem start = try $ do
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
contents <- parseFromString parseBlocks raw
updateState (\st -> st {stateParserContext = oldContext})
return contents
@ -419,10 +410,7 @@ definitionListItem = try $ do
state <- getState
let oldContext = stateParserContext state
-- parse the extracted block, which may contain various block elements:
rest <- getInput
setInput (concat raw)
contents <- parseBlocks
setInput rest
contents <- parseFromString parseBlocks $ concat raw
updateState (\st -> st {stateParserContext = oldContext})
return ((normalizeSpaces term), contents)

View file

@ -328,10 +328,7 @@ rawLaTeXBlock = try $ do
blockQuote = try $ do
raw <- indentedBlock True
-- parse the extracted block, which may contain various block elements:
rest <- getInput
setInput $ raw ++ "\n\n"
contents <- parseBlocks
setInput rest
contents <- parseFromString parseBlocks $ raw ++ "\n\n"
return $ BlockQuote contents
--
@ -344,10 +341,7 @@ definitionListItem = try $ do
term <- many1Till inline endline
raw <- indentedBlock True
-- parse the extracted block, which may contain various block elements:
rest <- getInput
setInput $ raw ++ "\n\n"
contents <- parseBlocks
setInput rest
contents <- parseFromString parseBlocks $ raw ++ "\n\n"
return (normalizeSpaces term, contents)
definitionList = try $ do
@ -408,12 +402,9 @@ listItem start = try $ do
-- see definition of "endline"
state <- getState
let oldContext = stateParserContext state
remaining <- getInput
setState $ state {stateParserContext = ListItemState}
-- parse the extracted block, which may itself contain block elements
setInput $ concat (first:rest) ++ blanks
parsed <- parseBlocks
setInput remaining
parsed <- parseFromString parseBlocks $ concat (first:rest) ++ blanks
updateState (\st -> st {stateParserContext = oldContext})
return parsed