git.iko.soy/typeable/pandoc
on master help sign in
Added definition list support to HTML reader.

Added a test for definition lists to the html-reader test suite. git-svn-id: https://pandoc.googlecode.com/svn/trunk@781 788f1e2b-df1e-0410-8736-df70ead52e1b

commitf69d9efc8323b202dc0f333036da1c38a2fd270a authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateMon 23 Jul 2007, 01:21 (19 years ago) parent1296273
3 files changed+49−13
src/Text/Pandoc/Readers/HTML.hs+32−13 tests/html-reader.html+9 tests/html-reader.native+8
src/Text/Pandoc/Readers/HTML.hs+32−13
@@ -83,6 +83,18 @@ inlinesTilEnd tag = try (do
8383 inlines <- manyTill inline (htmlEndTag tag)
8484 return inlines)
8585
86+-- | Parse blocks between open and close tag.
87+blocksIn tag = try $ do
88+ htmlTag tag
89+ spaces
90+ blocksTilEnd tag
91+
92+-- | Parse inlines between open and close tag.
93+inlinesIn tag = try $ do
94+ htmlTag tag
95+ spaces
96+ inlinesTilEnd tag
97+
8698-- | Extract type from a tag: e.g. @br@ from @\<br\>@
8799extractTagType :: String -> String
88100extractTagType ('<':rest) =
@@ -339,27 +351,34 @@ blockQuote = try (do
339351-- list blocks
340352--
341353
342−list = choice [ bulletList, orderedList ] <?> "list"
354+list = choice [ bulletList, orderedList, definitionList ] <?> "list"
343355
344−orderedList = try (do
345− tag <- htmlTag "ol"
356+orderedList = try $ do
357+ htmlTag "ol"
346358 spaces
347− items <- sepEndBy1 listItem spaces
359+ items <- sepEndBy1 (blocksIn "li") spaces
348360 htmlEndTag "ol"
349− return (OrderedList items))
361+ return (OrderedList items)
350362
351−bulletList = try (do
352− tag <- htmlTag "ul"
363+bulletList = try $ do
364+ htmlTag "ul"
353365 spaces
354− items <- sepEndBy1 listItem spaces
366+ items <- sepEndBy1 (blocksIn "li") spaces
355367 htmlEndTag "ul"
356− return (BulletList items))
368+ return (BulletList items)
357369
358−listItem = try (do
359− tag <- htmlTag "li"
370+definitionList = try $ do
371+ tag <- htmlTag "dl"
360372 spaces
361− blocks <- blocksTilEnd "li"
362− return blocks)
373+ items <- sepEndBy1 definitionListItem spaces
374+ htmlEndTag "dl"
375+ return (DefinitionList items)
376+
377+definitionListItem = try $ do
378+ terms <- sepEndBy1 (inlinesIn "dt") spaces
379+ defs <- sepEndBy1 (blocksIn "dd") spaces
380+ let term = joinWithSep [LineBreak] terms
381+ return (term, concat defs)
363382
364383--
365384-- paragraph block
tests/html-reader.html+9
@@ -232,6 +232,15 @@ These should not be escaped: \$ \\ \> \[ \{
232232</ul>
233233</li>
234234</ul>
235+<h2>Definition</h2>
236+<dl>
237+ <dt>Violin</dt>
238+ <dd>Stringed musical instrument.</dd>
239+ <dd>Torture device.</dd>
240+ <dt>Cello</dt>
241+ <dt>Violoncello</dt>
242+ <dd>Low-voiced stringed instrument.</dd>
243+</dl>
235244<hr />
236245<h1>HTML Blocks</h1>
237246<p>Simple block on one line:</p>
tests/html-reader.native+8
@@ -150,6 +150,14 @@ Pandoc (Meta [Str "Pandoc",Space,Str "Test",Space,Str "Suite"] [] "")
150150 , BulletList
151151 [ [ Para [Str "this",Space,Str "is",Space,Str "an",Space,Str "example",Space,Str "list",Space,Str "item",Space,Str "indented",Space,Str "with",Space,Str "tabs"] ]
152152 , [ Para [Str "this",Space,Str "is",Space,Str "an",Space,Str "example",Space,Str "list",Space,Str "item",Space,Str "indented",Space,Str "with",Space,Str "spaces"] ] ] ] ]
153+, Header 2 [Str "Definition"]
154+, DefinitionList
155+ [ ([Str "Violin"],
156+ [ Plain [Str "Stringed",Space,Str "musical",Space,Str "instrument."]
157+ , Plain [Str "Torture",Space,Str "device."] ] ),
158+ ([Str "Cello",LineBreak,Str "Violoncello"],
159+ [ Plain [Str "Low-voiced",Space,Str "stringed",Space,Str "instrument."] ]
160+ ) ]
153161, HorizontalRule
154162, Header 1 [Str "HTML",Space,Str "Blocks"]
155163, Para [Str "Simple",Space,Str "block",Space,Str "on",Space,Str "one",Space,Str "line:"]