From 80e750aa5e7ac03add8a3ef5a8f2725b1d0ff901 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 17 Mar 2023 20:06:17 -0700 Subject: Docx writer: include abstract title. Closes #8702. Uses localized term for abstract. --- MANUAL.txt | 1 + data/docx/word/styles.xml | 20 +++++++++++++++++++- src/Text/Pandoc/Writers/Docx.hs | 12 ++++++++++-- test/docx/golden/document-properties.docx | Bin 10314 -> 10324 bytes 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/MANUAL.txt b/MANUAL.txt index 0afe048e3..cc97a5167 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -1166,6 +1166,7 @@ header when requesting a document from a URL: - Author - Date - Abstract + - AbstractTitle - Bibliography - Heading 1 - Heading 2 diff --git a/data/docx/word/styles.xml b/data/docx/word/styles.xml index 832b1b25b..578c3ba5d 100644 --- a/data/docx/word/styles.xml +++ b/data/docx/word/styles.xml @@ -99,6 +99,24 @@ + + + + + + + + + + + + + + + + > + + @@ -107,7 +125,7 @@ - + diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs index e3956c5ef..d33f2aca6 100644 --- a/src/Text/Pandoc/Writers/Docx.hs +++ b/src/Text/Pandoc/Writers/Docx.hs @@ -48,7 +48,7 @@ import Data.Time.Clock.POSIX import Data.Digest.Pure.SHA (sha1, showDigest) import Skylighting import Text.Pandoc.Class (PandocMonad, report, toLang, getMediaBag) -import Text.Pandoc.Translations (translateTerm) +import Text.Pandoc.Translations (Term(Abstract), translateTerm) import Text.Pandoc.MediaBag (lookupMedia, MediaItem(..)) import qualified Text.Pandoc.Translations as Term import qualified Text.Pandoc.Class.PandocMonad as P @@ -767,7 +767,15 @@ writeOpenXML opts (Pandoc meta blocks) = do date <- withParaPropM (pStyleM "Date") $ blocksToOpenXML opts [Para dat | not (null dat)] abstract <- if null abstract' then return [] - else withParaPropM (pStyleM "Abstract") $ blocksToOpenXML opts abstract' + else do + abstractTitle <- translateTerm Abstract + abstractTit <- withParaPropM (pStyleM "AbstractTitle") $ + blocksToOpenXML opts + [Para [Str abstractTitle]] + abstractContents <- withParaPropM (pStyleM "Abstract") $ + blocksToOpenXML opts abstract' + return $ abstractTit <> abstractContents + let convertSpace (Str x : Space : Str y : xs) = Str (x <> " " <> y) : xs convertSpace (Str x : Str y : xs) = Str (x <> y) : xs convertSpace xs = xs diff --git a/test/docx/golden/document-properties.docx b/test/docx/golden/document-properties.docx index d8f091956..5bc62090b 100644 Binary files a/test/docx/golden/document-properties.docx and b/test/docx/golden/document-properties.docx differ -- cgit v1.2.3