Docx reader: add more framework for Zotero citations.

- Add docxReferences to state, so we can accumulate
  references for metadata.
- Add a clause for ZoteroItem to parPartToInlines'.
  So far it doesn't do anything except add a surrounding Cite element.

See #7840.
This commit is contained in:
John MacFarlane 2022-02-03 07:37:30 -08:00
parent 54279149ab
commit 0011c9520d

View file

@ -72,6 +72,7 @@ import Data.Maybe (catMaybes, isJust, fromMaybe)
import Data.Sequence (ViewL (..), viewl)
import qualified Data.Sequence as Seq
import qualified Data.Set as Set
import Citeproc (ItemId(..), Reference(..))
import Text.Pandoc.Builder as Pandoc
import Text.Pandoc.MediaBag (MediaBag)
import Text.Pandoc.Options
@ -115,6 +116,7 @@ data DState = DState { docxAnchorMap :: M.Map T.Text T.Text
, docxListState :: M.Map (T.Text, T.Text) Integer
, docxPrevPara :: Inlines
, docxTableCaptions :: [Blocks]
, docxReferences :: M.Map ItemId (Reference Inlines)
}
instance Default DState where
@ -126,6 +128,7 @@ instance Default DState where
, docxListState = M.empty
, docxPrevPara = mempty
, docxTableCaptions = []
, docxReferences = mempty
}
data DEnv = DEnv { docxOptions :: ReaderOptions
@ -449,6 +452,10 @@ parPartToInlines' (Field info children) =
case info of
HyperlinkField url -> parPartToInlines' $ ExternalHyperLink url children
PagerefField fieldAnchor True -> parPartToInlines' $ InternalHyperLink fieldAnchor children
ZoteroItem _t -> do
formattedCite <- smushInlines <$> mapM parPartToInlines' children
let citations = [] -- TODO parse Citation from t
return $ cite citations formattedCite
_ -> smushInlines <$> mapM parPartToInlines' children
isAnchorSpan :: Inline -> Bool