Enable citations extension for docx reader.

When enabled, Zotero citations are parsed as native pandoc
citations.  (When disabled, the Zotero-generated citation
text is passed through as regular text.)  In addition, the
Zotero-generated bibliography is suppressed.

Locators still need some work.
This commit is contained in:
John MacFarlane 2022-02-03 19:34:05 -08:00
parent 04d365623b
commit 1c2f0fe1d2
3 changed files with 34 additions and 19 deletions

View file

@ -3472,6 +3472,11 @@ native pandoc citations.
[org-cite]: https://orgmode.org/manual/Citations.html [org-cite]: https://orgmode.org/manual/Citations.html
[org-ref]: https://github.com/jkitchin/org-ref [org-ref]: https://github.com/jkitchin/org-ref
When `citations` is enabled in `docx`, Zotero-inserted
citations will be parsed as native pandoc citations.
(Otherwise, the Zotero-generated citation text and
bibliography will be parsed as regular text.)
#### Extension: `fancy_lists` {#org-fancy-lists} #### Extension: `fancy_lists` {#org-fancy-lists}
Some aspects of [Pandoc's Markdown fancy lists](#extension-fancy_lists) are also Some aspects of [Pandoc's Markdown fancy lists](#extension-fancy_lists) are also

View file

@ -488,6 +488,7 @@ getAllExtensions f = universalExtensions <> getAll f
[ Ext_empty_paragraphs [ Ext_empty_paragraphs
, Ext_native_numbering , Ext_native_numbering
, Ext_styles , Ext_styles
, Ext_citations
] ]
getAll "opendocument" = extensionsFromList getAll "opendocument" = extensionsFromList
[ Ext_empty_paragraphs [ Ext_empty_paragraphs

View file

@ -458,25 +458,34 @@ parPartToInlines' (Field info children) =
PagerefField fieldAnchor True -> parPartToInlines' $ InternalHyperLink fieldAnchor children PagerefField fieldAnchor True -> parPartToInlines' $ InternalHyperLink fieldAnchor children
ZoteroItem t -> do ZoteroItem t -> do
formattedCite <- smushInlines <$> mapM parPartToInlines' children formattedCite <- smushInlines <$> mapM parPartToInlines' children
let bs = fromTextLazy $ TL.fromStrict t opts <- asks docxOptions
case eitherDecode bs of if isEnabled Ext_citations opts
Left _err -> return formattedCite then do
Right citation -> do let bs = fromTextLazy $ TL.fromStrict t
let toPandocCitation item = case eitherDecode bs of
Citation{ citationId = unItemId (citationItemId item) Left _err -> return formattedCite
, citationPrefix = maybe [] (toList . text) $ Right citation -> do
citationItemPrefix item let toPandocCitation item =
, citationSuffix = (toList . text) $ Citation{ citationId = unItemId (citationItemId item)
maybe mempty (<> " ") , citationPrefix = maybe [] (toList . text) $
(citationItemLabel item) <> citationItemPrefix item
maybe mempty (<> " ") , citationSuffix = (toList . text) $
(citationItemLocator item) <> maybe mempty (<> " ")
maybe mempty id (citationItemSuffix item) (citationItemLabel item) <>
, citationMode = NormalCitation -- TODO for now maybe mempty (<> " ")
, citationNoteNum = 0 (citationItemLocator item) <>
, citationHash = 0 } fromMaybe mempty (citationItemSuffix item)
let cs = map toPandocCitation $ citationItems citation , citationMode = NormalCitation -- TODO for now
return $ cite cs formattedCite , citationNoteNum = 0
, citationHash = 0 }
let cs = map toPandocCitation $ citationItems citation
return $ cite cs formattedCite
else return formattedCite
ZoteroBibliography -> do
opts <- asks docxOptions
if isEnabled Ext_citations opts
then return mempty -- omit Zotero-generated bibliography
else smushInlines <$> mapM parPartToInlines' children
_ -> smushInlines <$> mapM parPartToInlines' children _ -> smushInlines <$> mapM parPartToInlines' children
isAnchorSpan :: Inline -> Bool isAnchorSpan :: Inline -> Bool