@@ -6,7 +6,7 @@ import Text.XML.Light
6import Data.Monoid
6import Data.Monoid
7import Data.Char (isSpace)
7import Data.Char (isSpace)
8import Control.Monad.State
8import Control.Monad.State
9−import Control.Applicative ((<$>))
9+import Control.Applicative ((<$>), (<$))
10import Data.List (intersperse)
10import Data.List (intersperse)
@@ -24,7 +24,7 @@ List of all DocBook tags, with [x] indicating implemented:
24[ ] alt - Text representation for a graphical element
24[ ] alt - Text representation for a graphical element
25[ ] anchor - A spot in the document
25[ ] anchor - A spot in the document
26[ ] answer - An answer to a question posed in a QandASet
26[ ] answer - An answer to a question posed in a QandASet
27−[ ] appendix - An appendix in a Book or Article
27+[x] appendix - An appendix in a Book or Article
28[ ] appendixinfo - Meta-information for an Appendix
28[ ] appendixinfo - Meta-information for an Appendix
29[ ] application - The name of a software program
29[ ] application - The name of a software program
30[ ] area - A region defined for a Callout in a graphic or code example
30[ ] area - A region defined for a Callout in a graphic or code example
@@ -59,8 +59,8 @@ List of all DocBook tags, with [x] indicating implemented:
59[ ] bibliosource - The source of a document
59[ ] bibliosource - The source of a document
60[ ] blockinfo - Meta-information for a block element
60[ ] blockinfo - Meta-information for a block element
61[x] blockquote - A quotation set off from the main text
61[x] blockquote - A quotation set off from the main text
62−[ ] book - A book
62+[x] book - A book
63−[ ] bookinfo - Meta-information for a Book
63+[x] bookinfo - Meta-information for a Book
64[ ] bridgehead - A free-floating heading
64[ ] bridgehead - A free-floating heading
65[ ] callout - A “called out” description of a marked Area
65[ ] callout - A “called out” description of a marked Area
66[ ] calloutlist - A list of Callouts
66[ ] calloutlist - A list of Callouts
@@ -283,7 +283,7 @@ List of all DocBook tags, with [x] indicating implemented:
283[ ] phrase - A span of text
283[ ] phrase - A span of text
284[ ] pob - A post office box in an address
284[ ] pob - A post office box in an address
285[ ] postcode - A postal code in an address
285[ ] postcode - A postal code in an address
286−[ ] preface - Introductory matter preceding the first chapter of a book
286+[x] preface - Introductory matter preceding the first chapter of a book
287[ ] prefaceinfo - Meta-information for a Preface
287[ ] prefaceinfo - Meta-information for a Preface
288[ ] primary - The primary word or phrase under which an index term should be
288[ ] primary - The primary word or phrase under which an index term should be
@@ -442,7 +442,7 @@ List of all DocBook tags, with [x] indicating implemented:
442[ ] tip - A suggestion to the user, set off from the text
442[ ] tip - A suggestion to the user, set off from the text
443[x] title - The text of the title of a section of a document or of a formal
443[x] title - The text of the title of a section of a document or of a formal
444 block-level element
444 block-level element
445−[ ] titleabbrev - The abbreviation of a Title
445+[x] titleabbrev - The abbreviation of a Title
446[ ] toc - A table of contents
446[ ] toc - A table of contents
447[ ] tocback - An entry in a table of contents for a back matter component
447[ ] tocback - An entry in a table of contents for a back matter component
448[ ] tocchap - An entry in a table of contents for a component in the body of
448[ ] tocchap - An entry in a table of contents for a component in the body of
@@ -496,6 +496,7 @@ data DBState = DBState{ dbSectionLevel :: Int
496 , dbDocTitle :: Inlines
496 , dbDocTitle :: Inlines
497 , dbDocAuthors :: [Inlines]
497 , dbDocAuthors :: [Inlines]
498 , dbDocDate :: Inlines
498 , dbDocDate :: Inlines
499 } deriving Show
500 } deriving Show
501readDocBook :: ParserState -> String -> Pandoc
502readDocBook :: ParserState -> String -> Pandoc
@@ -509,6 +510,7 @@ readDocBook st inp = setTitle (dbDocTitle st')
509 , dbDocTitle = mempty
510 , dbDocTitle = mempty
510 , dbDocAuthors = []
511 , dbDocAuthors = []
511 , dbDocDate = mempty
512 , dbDocDate = mempty
514-- convenience function to get an attribute value, defaulting to ""
516-- convenience function to get an attribute value, defaulting to ""
@@ -552,6 +554,11 @@ parseBlock (Elem e) =
552 contents <- getBlocks e
554 contents <- getBlocks e
553 return $ blockQuote (contents <> attrib)
555 return $ blockQuote (contents <> attrib)
554 "attribution" -> return mempty
556 "attribution" -> return mempty
557+ "titleabbrev" -> return mempty
558+ "title" -> return mempty -- handled by getTitle
560+ "appendix" -> sect 0
555 "sect1" -> sect 1
562 "sect1" -> sect 1
556 "sect2" -> sect 2
563 "sect2" -> sect 2
557 "sect3" -> sect 3
564 "sect3" -> sect 3
@@ -566,6 +573,10 @@ parseBlock (Elem e) =
566 "caption" -> return mempty
573 "caption" -> return mempty
567 "info" -> getTitle >> getAuthors >> getDate >> return mempty
574 "info" -> getTitle >> getAuthors >> getDate >> return mempty
568 "articleinfo" -> getTitle >> getAuthors >> getDate >> return mempty
575 "articleinfo" -> getTitle >> getAuthors >> getDate >> return mempty
576+ "bookinfo" -> getTitle >> getAuthors >> getDate >> return mempty
577+ "article" -> modify (\st -> st{ dbBook = False }) >>
578+ getTitle >> getBlocks e
579+ "book" -> modify (\st -> st{ dbBook = True }) >> getTitle >> getBlocks e
569 "programlisting" -> return $ codeBlock $ strContent e -- TODO attrs
580 "programlisting" -> return $ codeBlock $ strContent e -- TODO attrs
570 "?xml" -> return mempty
581 "?xml" -> return mempty
571 _ -> getBlocks e
582 _ -> getBlocks e
@@ -600,16 +611,17 @@ parseBlock (Elem e) =
600 dat <- getInlines t
611 dat <- getInlines t
601 modify $ \st -> st{dbDocDate = dat}
612 modify $ \st -> st{dbDocDate = dat}
602 Nothing -> return ()
613 Nothing -> return ()
614+ sect n = do isbook <- gets dbBook
615+ let n' = if isbook then n + 1 else n
603− sect n = case skipWhite (elContent e) of
616+ case skipWhite (elContent e) of
605− | named "title" t -> do
617+ ((Elem t):body) | named "title" t -> do
606− h <- header n <$> (getInlines t)
618+ h <- header n' <$> (getInlines t)
607 modify $ \st -> st{ dbSectionLevel = n }
619 modify $ \st -> st{ dbSectionLevel = n }
608 b <- mconcat <$> (mapM parseBlock body)
620 b <- mconcat <$> (mapM parseBlock body)
609 modify $ \st -> st{ dbSectionLevel = n - 1 }
621 modify $ \st -> st{ dbSectionLevel = n - 1 }
610 return $ h <> b
622 return $ h <> b
611 body -> do
623 body -> do
612− let h = header n mempty
624+ let h = header n' mempty
613 modify $ \st -> st{ dbSectionLevel = n }
625 modify $ \st -> st{ dbSectionLevel = n }
614 b <- mconcat <$> (mapM parseBlock body)
626 b <- mconcat <$> (mapM parseBlock body)
615 modify $ \st -> st{ dbSectionLevel = n - 1 }
627 modify $ \st -> st{ dbSectionLevel = n - 1 }