git.iko.soy/typeable/pandoc
on master help sign in
textile redcloth definition lists
commitbb609a85e3db8a25fbfac30858c8637eb6664fd6 authorpaul.rivier <paul.r.ml@gmail.com> dateThu 9 Dec 2010, 13:40 (16 years ago) parent88a4068
3 files changed+53−2
src/Text/Pandoc/Readers/Textile.hs+29−2 tests/textile-reader.native+14 tests/textile-reader.textile+10
src/Text/Pandoc/Readers/Textile.hs+29−2
@@ -43,7 +43,6 @@ Implemented but discarded:
4343Left to be implemented:
4444 - dimension sign
4545 - all caps
46− - definition lists
4746 - continued blocks (ex bq..)
4847
4948TODO : refactor common patterns across readers :
@@ -199,7 +198,8 @@ anyList = try $ do
199198-- provided correct nesting
200199anyListAtDepth :: Int -> GenParser Char ParserState Block
201200anyListAtDepth depth = choice [ bulletListAtDepth depth,
202− orderedListAtDepth depth ]
201+ orderedListAtDepth depth,
202+ definitionList ]
203203
204204-- | Bullet List of given depth, depth being the number of leading '*'
205205bulletListAtDepth :: Int -> GenParser Char ParserState Block
@@ -236,6 +236,33 @@ orderedListItemAtDepth depth = try $ do
236236 sublist <- option [] (anyListAtDepth (depth + 1) >>= return . (:[]))
237237 return (p:sublist)
238238
239+-- | A definition list is a set of consecutive definition items
240+definitionList :: GenParser Char ParserState Block
241+definitionList = try $ do
242+ items <- many1 definitionListItem
243+ return $ DefinitionList items
244+
245+-- | A definition list item in textile begins with '- ', followed by
246+-- the term defined, then spaces and ":=". The definition follows, on
247+-- the same single line, or spaned on multiple line, after a line
248+-- break.
249+definitionListItem :: GenParser Char ParserState ([Inline], [[Block]])
250+definitionListItem = try $ do
251+ string "- "
252+ term <- many1Till inline (try (whitespace >> string ":="))
253+ def <- inlineDef <|> multilineDef
254+ return (term, def)
255+ where inlineDef :: GenParser Char ParserState [[Block]]
256+ inlineDef = liftM (\d -> [[Plain d]]) $ try (whitespace >> inlines)
257+ multilineDef :: GenParser Char ParserState [[Block]]
258+ multilineDef = try $ do
259+ optional whitespace >> newline
260+ s <- many1Till anyChar (try (string "=:" >> newline))
261+ -- this ++ "\n\n" does not look very good
262+ ds <- parseFromString parseBlocks (s ++ "\n\n")
263+ return [ds]
264+
265+
239266-- | This terminates a block such as a paragraph. Because of raw html
240267-- blocks support, we have to lookAhead for a rawHtmlBlock.
241268blockBreak :: GenParser Char ParserState ()
tests/textile-reader.native+14
@@ -52,6 +52,20 @@ Pandoc (Meta {docTitle = [], docAuthors = [], docDate = []})
5252 , BulletList
5353 [ [ Plain [Str "ui",Space,Str "2",Str ".",Str "1",Str ".",Str "1"] ]
5454 , [ Plain [Str "ui",Space,Str "2",Str ".",Str "1",Str ".",Str "2"] ] ] ] ] ] ]
55+, Header 2 [Str "Definition",Space,Str "List"]
56+, DefinitionList
57+ [ ([Str "coffee"],
58+ [ [ Plain [Str "Hot",Space,Str "and",Space,Str "black"] ]
59+ ])
60+ , ([Str "tea"],
61+ [ [ Plain [Str "Also",Space,Str "hot",Str ",",Space,Str "but",Space,Str "a",Space,Str "little",Space,Str "less",Space,Str "black"] ]
62+ ])
63+ , ([Str "milk"],
64+ [ [ Para [Str "Nourishing",Space,Str "beverage",Space,Str "for",Space,Str "baby",Space,Str "cows",Str "."]
65+ , Para [Str "Cold",Space,Str "drink",Space,Str "that",Space,Str "goes",Space,Str "great",Space,Str "with",Space,Str "cookies",Str "."] ]])
66+ , ([Str "beer"],
67+ [ [ Plain [Str "fresh",Space,Str "and",Space,Str "bitter"] ]
68+ ]) ]
5569, Header 1 [Str "Inline",Space,Str "Markup"]
5670, Para [Str "This",Space,Str "is",Space,Emph [Str "emphasized"],Str ",",Space,Str "and",Space,Str "so",Space,Emph [Str "is",Space,Str "this"],Str ".",LineBreak,Str "This",Space,Str "is",Space,Strong [Str "strong"],Str ",",Space,Str "and",Space,Str "so",Space,Strong [Str "is",Space,Str "this"],Str ".",LineBreak,Str "A",Space,Link [Strong [Str "strong",Space,Str "link"]] ("http://www.foobar.com",""),Str "."]
5771, Para [Emph [Strong [Str "This",Space,Str "is",Space,Str "strong",Space,Str "and",Space,Str "em",Str "."]],LineBreak,Str "So",Space,Str "is",Space,Strong [Emph [Str "this"]],Space,Str "word",Space,Str "and",Space,Emph [Strong [Str "that",Space,Str "one"]],Str ".",LineBreak,Strikeout [Str "This",Space,Str "is",Space,Str "strikeout",Space,Str "and",Space,Strong [Str "strong"]]]
tests/textile-reader.textile+10
@@ -93,6 +93,16 @@ h2. Nested
9393*** ui 2.1.1
9494*** ui 2.1.2
9595
96+h2. Definition List
97+
98+- coffee := Hot and black
99+- tea := Also hot, but a little less black
100+- milk :=
101+Nourishing beverage for baby cows.
102+
103+Cold drink that goes great with cookies.=:
104+- beer := fresh and bitter
105+
96106
97107h1. Inline Markup
98108