git.iko.soy/typeable/pandoc
on master help sign in
DocBook reader: Supported variablelist.

Also added 'named' convenience function to avoid repetition.

commit41016eebe22b629c93314b39b3c773f07e75a994 authorJohn MacFarlane <fiddlosopher@gmail.com> dateSat 28 Apr 2012, 11:04 (14 years ago) parent56f15b5
1 file changed+25−14
src/Text/Pandoc/Readers/DocBook.hs+25−14
src/Text/Pandoc/Readers/DocBook.hs+25−14
@@ -7,6 +7,7 @@ import Data.Monoid
77import Data.Char (isSpace)
88import Control.Monad.State
99import Control.Applicative ((<$>))
10+import Data.List (intersperse)
1011
1112{-
1213
@@ -427,7 +428,7 @@ List of all DocBook tags, with [x] indicating implemented:
427428[ ] tasksummary - A summary of a task
428429[ ] tbody - A wrapper for the rows of a table or informal table
429430[ ] td - A table entry in an HTML table
430−[ ] term - The word or phrase being defined or described in a variable list
431+[x] term - The word or phrase being defined or described in a variable list
431432[ ] termdef - An inline term definition
432433[ ] tertiary - A tertiary word or phrase in an index term
433434[ ] tertiaryie - A tertiary term in an index entry, rather than in the text
@@ -469,9 +470,9 @@ List of all DocBook tags, with [x] indicating implemented:
469470[ ] userinput - Data entered by the user
470471[x] varargs - An empty element in a function synopsis indicating a variable
471472 number of arguments
472−[ ] variablelist - A list in which each entry is composed of a set of one or
473+[x] variablelist - A list in which each entry is composed of a set of one or
473474 more terms and an associated description
474−[ ] varlistentry - A wrapper for a set of terms and the associated description
475+[x] varlistentry - A wrapper for a set of terms and the associated description
475476 in a variable list
476477[x] varname - The name of a variable
477478[ ] videodata - Pointer to external video data
@@ -517,19 +518,20 @@ attrValue attr elt =
517518 Just z -> z
518519 Nothing -> ""
519520
521+-- convenience function
522+named :: String -> Element -> Bool
523+named s e = qName (elName e) == s
524+
520525-- function that is used by both mediaobject (in parseBlock)
521526-- and inlinemediaobject (in parseInline)
522527getImage :: Element -> DB Inlines
523528getImage e = do
524− imageUrl <- case filterChild
525− (\e' -> qName (elName e') == "imageobject") e of
529+ imageUrl <- case filterChild (named "imageobject") e of
526530 Nothing -> return mempty
527− Just z -> case filterChild
528− (\e' -> qName (elName e') == "imagedata") z of
531+ Just z -> case filterChild (named "imagedata") z of
529532 Nothing -> return mempty
530533 Just i -> return $ attrValue "fileref" i
531− caption <- case filterChild
532− (\e' -> qName (elName e') == "caption") e of
534+ caption <- case filterChild (named "caption") e of
533535 Nothing -> return mempty
534536 Just z -> mconcat <$> (mapM parseInline $ elContent z)
535537 return $ image imageUrl "" caption
@@ -543,8 +545,7 @@ parseBlock (Elem e) =
543545 case qName (elName e) of
544546 "para" -> para <$> getInlines e
545547 "blockquote" -> do
546− attrib <- case filterChild
547− (\e' -> qName (elName e') == "attribution") e of
548+ attrib <- case filterChild (named "attribution") e of
548549 Nothing -> return mempty
549550 Just z -> (para . (str "— " <>) . mconcat)
550551 <$> (mapM parseInline $ elContent z)
@@ -560,6 +561,7 @@ parseBlock (Elem e) =
560561 "abstract" -> blockQuote <$> getBlocks e
561562 "itemizedlist" -> bulletList <$> listitems
562563 "orderedlist" -> orderedList <$> listitems -- TODO list attributes
564+ "variablelist" -> definitionList <$> deflistitems
563565 "mediaobject" -> para <$> (getImage e)
564566 "caption" -> return mempty
565567 "info" -> getTitle >> getAuthors >> getDate >> return mempty
@@ -570,11 +572,20 @@ parseBlock (Elem e) =
570572 where getBlocks e' = mconcat <$> (mapM parseBlock $ elContent e')
571573 getInlines e' = (trimInlines . mconcat) <$>
572574 (mapM parseInline $ elContent e')
573− isTitle e' = qName (elName e') == "title"
574575 skipWhite (Text (CData _ s _):xs) | all isSpace s = skipWhite xs
575576 | otherwise = xs
576577 skipWhite xs = xs
577− listitems = mapM getBlocks $ filterChildren (\e' -> qName (elName e') == "listitem") e
578+ listitems = mapM getBlocks $ filterChildren (named "listitem") e
579+ deflistitems = mapM parseVarListEntry $ filterChildren
580+ (named "varlistentry") e
581+ parseVarListEntry e' = do
582+ let defs = filterChildren (named "term") e'
583+ let items = filterChildren (named "listitem") e'
584+ defs' <- mapM ((mconcat <$>) . mapM parseInline)
585+ $ map elContent defs
586+ items' <- mapM ((mconcat <$>) . mapM parseBlock)
587+ $ map elContent items
588+ return (mconcat $ intersperse (str "; ") defs', items')
578589 getTitle = case findChild (unqual "title") e of
579590 Just t -> do
580591 tit <- getInlines t
@@ -591,7 +602,7 @@ parseBlock (Elem e) =
591602 Nothing -> return ()
592603 sect n = case skipWhite (elContent e) of
593604 ((Elem t):body)
594− | isTitle t -> do
605+ | named "title" t -> do
595606 h <- header n <$> (getInlines t)
596607 modify $ \st -> st{ dbSectionLevel = n }
597608 b <- mconcat <$> (mapM parseBlock body)