aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers
diff options
context:
space:
mode:
authorpaul.rivier <paul.r.ml@gmail.com>2010-12-09 13:40:42 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2010-12-09 09:25:46 -0800
commitbb609a85e3db8a25fbfac30858c8637eb6664fd6 (patch)
treefc6129280f3fba59d971e3aa0965d4afd0231d5a /src/Text/Pandoc/Readers
parent88a40685b8d79dd97d16e2b3988e0e927ec24ec0 (diff)
downloadpandoc-bb609a85e3db8a25fbfac30858c8637eb6664fd6.tar.gz
textile redcloth definition lists
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r--src/Text/Pandoc/Readers/Textile.hs31
1 files changed, 29 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Readers/Textile.hs b/src/Text/Pandoc/Readers/Textile.hs
index d5add8f88..52a9e12c8 100644
--- a/src/Text/Pandoc/Readers/Textile.hs
+++ b/src/Text/Pandoc/Readers/Textile.hs
@@ -43,7 +43,6 @@ Implemented but discarded:
Left to be implemented:
- dimension sign
- all caps
- - definition lists
- continued blocks (ex bq..)
TODO : refactor common patterns across readers :
@@ -199,7 +198,8 @@ anyList = try $ do
-- provided correct nesting
anyListAtDepth :: Int -> GenParser Char ParserState Block
anyListAtDepth depth = choice [ bulletListAtDepth depth,
- orderedListAtDepth depth ]
+ orderedListAtDepth depth,
+ definitionList ]
-- | Bullet List of given depth, depth being the number of leading '*'
bulletListAtDepth :: Int -> GenParser Char ParserState Block
@@ -236,6 +236,33 @@ orderedListItemAtDepth depth = try $ do
sublist <- option [] (anyListAtDepth (depth + 1) >>= return . (:[]))
return (p:sublist)
+-- | A definition list is a set of consecutive definition items
+definitionList :: GenParser Char ParserState Block
+definitionList = try $ do
+ items <- many1 definitionListItem
+ return $ DefinitionList items
+
+-- | A definition list item in textile begins with '- ', followed by
+-- the term defined, then spaces and ":=". The definition follows, on
+-- the same single line, or spaned on multiple line, after a line
+-- break.
+definitionListItem :: GenParser Char ParserState ([Inline], [[Block]])
+definitionListItem = try $ do
+ string "- "
+ term <- many1Till inline (try (whitespace >> string ":="))
+ def <- inlineDef <|> multilineDef
+ return (term, def)
+ where inlineDef :: GenParser Char ParserState [[Block]]
+ inlineDef = liftM (\d -> [[Plain d]]) $ try (whitespace >> inlines)
+ multilineDef :: GenParser Char ParserState [[Block]]
+ multilineDef = try $ do
+ optional whitespace >> newline
+ s <- many1Till anyChar (try (string "=:" >> newline))
+ -- this ++ "\n\n" does not look very good
+ ds <- parseFromString parseBlocks (s ++ "\n\n")
+ return [ds]
+
+
-- | This terminates a block such as a paragraph. Because of raw html
-- blocks support, we have to lookAhead for a rawHtmlBlock.
blockBreak :: GenParser Char ParserState ()