From 5ec31cc7278acb102fa444b9f8f92e8bb442d21f Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Sat, 10 Mar 2007 17:48:16 +0000 Subject: Added parser for definition lists, derived from reStructuredText syntax: term 1 Definition 1 Paragraph 2 of definition 1. term 2 There must be whitespace between entries. Any kind of block may serve as a definition, but the first line of each block must be indented. terms can contain any *inline* elements If you want to be lazy, you can just indent the first line of the definition block. git-svn-id: https://pandoc.googlecode.com/svn/trunk@566 788f1e2b-df1e-0410-8736-df70ead52e1b --- src/Text/Pandoc/Readers/Markdown.hs | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'src/Text/Pandoc/Readers') diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index df41e1dd6..70a94fb2c 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -271,7 +271,7 @@ rawLine = try (do contents <- many1 nonEndline end <- option "" (do newline - option "" indentSpaces + option "" (try indentSpaces) return "\n") return (contents ++ end)) @@ -405,7 +405,7 @@ listContinuation start = try (do listContinuationLine start = try (do notFollowedBy' blankline notFollowedBy' start - option "" indentSpaces + option "" (try indentSpaces) result <- manyTill anyChar newline return (result ++ "\n")) @@ -421,7 +421,7 @@ listItem start = try (do -- parse the extracted block, which may contain various block elements: rest <- getInput let raw = concat (first:continuations) - setInput $ raw + setInput raw contents <- parseBlocks setInput rest updateState (\st -> st {stateParserContext = oldContext}) @@ -437,6 +437,35 @@ bulletList = try (do let items' = compactify items return (BulletList items')) +-- definition lists + +definitionListItem = try $ do + notFollowedBy blankline + notFollowedBy' indentSpaces + term <- manyTill inline newline + raw <- many1 defRawBlock + state <- getState + let oldContext = stateParserContext state + setState $ state {stateParserContext = ListItemState} + -- parse the extracted block, which may contain various block elements: + rest <- getInput + setInput (concat raw) + contents <- parseBlocks + setInput rest + updateState (\st -> st {stateParserContext = oldContext}) + return ((normalizeSpaces term), contents) + +defRawBlock = try $ do + indentSpaces + first <- anyLine + rest <- manyTill (do {option "" (try indentSpaces); + anyLine}) blanklines + return $ (unlines (first:rest)) ++ "\n" + +definitionList = do + items <- many1 definitionListItem + return $ DefinitionList items + -- -- paragraph block -- -- cgit v1.2.3