Skip to content

Commit

Permalink
Docx writer: include abstract title.
Browse files Browse the repository at this point in the history
Closes #8702.

Uses localized term for abstract.
  • Loading branch information
jgm committed Mar 18, 2023
1 parent a23d140 commit 80e750a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions MANUAL.txt
Expand Up @@ -1166,6 +1166,7 @@ header when requesting a document from a URL:
- Author
- Date
- Abstract
- AbstractTitle
- Bibliography
- Heading 1
- Heading 2
Expand Down
20 changes: 19 additions & 1 deletion data/docx/word/styles.xml
Expand Up @@ -99,6 +99,24 @@
<w:jc w:val="center" />
</w:pPr>
</w:style>
<w:style w:type="paragraph" w:customStyle="1" w:styleId="AbstractTitle">
<w:name w:val="Abstract Title" />
<w:basedOn w:val="Normal" />
<w:next w:val="Abstract" />
<w:qFormat />
<w:pPr>
<w:keepNext />
<w:keepLines />
<w:jc w:val="center" />
<w:spacing w:before="300" w:after="0" />
</w:pPr>
<w:rPr>
<w:sz w:val="20" />
<w:szCs w:val="20" />
<w:b />
<w:color w:val="345A8A" />>
</w:rPr>
</w:style>
<w:style w:type="paragraph" w:customStyle="1" w:styleId="Abstract">
<w:name w:val="Abstract" />
<w:basedOn w:val="Normal" />
Expand All @@ -107,7 +125,7 @@
<w:pPr>
<w:keepNext />
<w:keepLines />
<w:spacing w:before="300" w:after="300" />
<w:spacing w:before="100" w:after="300" />
</w:pPr>
<w:rPr>
<w:sz w:val="20" />
Expand Down
12 changes: 10 additions & 2 deletions src/Text/Pandoc/Writers/Docx.hs
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Binary file modified test/docx/golden/document-properties.docx
Binary file not shown.

0 comments on commit 80e750a

Please sign in to comment.