From f6538144f0763ae17b60c78810ed52ab96df308d Mon Sep 17 00:00:00 2001
From: Frerich Raabe <raabe@froglogic.com>
Date: Wed, 23 Sep 2015 19:31:25 +0200
Subject: [PATCH] Pass the parsed DocBook content along the state of
 readDocBook

Having access to the entire document will be needed when handling
elements which refer to other elements. This is needed for e.g. <xref>
or <link>, both of which reference other elements (by the 'id'
attribute) for the label text.

I suppose that in practice, the [Content] returned by parseXML always
only contains one 'Elem' value -- the document element. However, I'm not
totally sure about it, so let's just pass all the Content along.
---
 src/Text/Pandoc/Readers/DocBook.hs | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/Text/Pandoc/Readers/DocBook.hs b/src/Text/Pandoc/Readers/DocBook.hs
index a2aa62249..83e2f3900 100644
--- a/src/Text/Pandoc/Readers/DocBook.hs
+++ b/src/Text/Pandoc/Readers/DocBook.hs
@@ -511,6 +511,7 @@ data DBState = DBState{ dbSectionLevel :: Int
                       , dbAcceptsMeta  :: Bool
                       , dbBook         :: Bool
                       , dbFigureTitle  :: Inlines
+                      , dbContent      :: [Content]
                       } deriving Show
 
 instance Default DBState where
@@ -519,12 +520,13 @@ instance Default DBState where
                , dbMeta = mempty
                , dbAcceptsMeta = False
                , dbBook = False
-               , dbFigureTitle = mempty }
+               , dbFigureTitle = mempty
+               , dbContent = [] }
 
 
 readDocBook :: ReaderOptions -> String -> Either PandocError Pandoc
 readDocBook _ inp  = (\blocks -> Pandoc (dbMeta st') (toList . mconcat $ blocks)) <$>  bs
-  where (bs , st') = flip runState def . runExceptT . mapM parseBlock $ tree
+  where (bs , st') = flip runState (def{ dbContent = tree }) . runExceptT . mapM parseBlock $ tree
         tree = normalizeTree . parseXML . handleInstructions $ inp
 
 -- We treat <?asciidoc-br?> specially (issue #1236), converting it