@@ -6,7 +6,7 @@ import Text.XML.Light
66import Data.Monoid
77import Data.Char (isSpace)
88import Control.Monad.State
9−import Control.Applicative ((<$>))
9+import Control.Applicative ((<$>), (<$))
1010import Data.List (intersperse)
1111
1212{-
@@ -24,7 +24,7 @@ List of all DocBook tags, with [x] indicating implemented:
2424[ ] alt - Text representation for a graphical element
2525[ ] anchor - A spot in the document
2626[ ] 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
2828[ ] appendixinfo - Meta-information for an Appendix
2929[ ] application - The name of a software program
3030[ ] 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:
5959[ ] bibliosource - The source of a document
6060[ ] blockinfo - Meta-information for a block element
6161[x] blockquote - A quotation set off from the main text
62−[ ] book - A book
63−[ ] bookinfo - Meta-information for a Book
62+[x] book - A book
63+[x] bookinfo - Meta-information for a Book
6464[ ] bridgehead - A free-floating heading
6565[ ] callout - A “called out” description of a marked Area
6666[ ] calloutlist - A list of Callouts
@@ -283,7 +283,7 @@ List of all DocBook tags, with [x] indicating implemented:
283283[ ] phrase - A span of text
284284[ ] pob - A post office box in an address
285285[ ] 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
287287[ ] prefaceinfo - Meta-information for a Preface
288288[ ] primary - The primary word or phrase under which an index term should be
289289 sorted
@@ -442,7 +442,7 @@ List of all DocBook tags, with [x] indicating implemented:
442442[ ] tip - A suggestion to the user, set off from the text
443443[x] title - The text of the title of a section of a document or of a formal
444444 block-level element
445−[ ] titleabbrev - The abbreviation of a Title
445+[x] titleabbrev - The abbreviation of a Title
446446[ ] toc - A table of contents
447447[ ] tocback - An entry in a table of contents for a back matter component
448448[ ] tocchap - An entry in a table of contents for a component in the body of
@@ -496,6 +496,7 @@ data DBState = DBState{ dbSectionLevel :: Int
496496 , dbDocTitle :: Inlines
497497 , dbDocAuthors :: [Inlines]
498498 , dbDocDate :: Inlines
499+ , dbBook :: Bool
499500 } deriving Show
500501
501502readDocBook :: ParserState -> String -> Pandoc
@@ -509,6 +510,7 @@ readDocBook st inp = setTitle (dbDocTitle st')
509510 , dbDocTitle = mempty
510511 , dbDocAuthors = []
511512 , dbDocDate = mempty
513+ , dbBook = False
512514 }
513515
514516-- convenience function to get an attribute value, defaulting to ""
@@ -552,6 +554,11 @@ parseBlock (Elem e) =
552554 contents <- getBlocks e
553555 return $ blockQuote (contents <> attrib)
554556 "attribution" -> return mempty
557+ "titleabbrev" -> return mempty
558+ "title" -> return mempty -- handled by getTitle
559+ "chapter" -> sect 0
560+ "appendix" -> sect 0
561+ "preface" -> sect 0
555562 "sect1" -> sect 1
556563 "sect2" -> sect 2
557564 "sect3" -> sect 3
@@ -566,6 +573,10 @@ parseBlock (Elem e) =
566573 "caption" -> return mempty
567574 "info" -> getTitle >> getAuthors >> getDate >> return mempty
568575 "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
569580 "programlisting" -> return $ codeBlock $ strContent e -- TODO attrs
570581 "?xml" -> return mempty
571582 _ -> getBlocks e
@@ -600,16 +611,17 @@ parseBlock (Elem e) =
600611 dat <- getInlines t
601612 modify $ \st -> st{dbDocDate = dat}
602613 Nothing -> return ()
603− sect n = case skipWhite (elContent e) of
604− ((Elem t):body)
605− | named "title" t -> do
606− h <- header n <$> (getInlines t)
614+ sect n = do isbook <- gets dbBook
615+ let n' = if isbook then n + 1 else n
616+ case skipWhite (elContent e) of
617+ ((Elem t):body) | named "title" t -> do
618+ h <- header n' <$> (getInlines t)
607619 modify $ \st -> st{ dbSectionLevel = n }
608620 b <- mconcat <$> (mapM parseBlock body)
609621 modify $ \st -> st{ dbSectionLevel = n - 1 }
610622 return $ h <> b
611623 body -> do
612− let h = header n mempty
624+ let h = header n' mempty
613625 modify $ \st -> st{ dbSectionLevel = n }
614626 b <- mconcat <$> (mapM parseBlock body)
615627 modify $ \st -> st{ dbSectionLevel = n - 1 }