Skip to content

Commit

Permalink
Docx writer: Print subtitle from metadata if present.
Browse files Browse the repository at this point in the history
Use Subtitle style.

See #1451.
  • Loading branch information
John MacFarlane committed Jul 30, 2014
1 parent 8c2ed54 commit 33a051d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 3 additions & 3 deletions README
Expand Up @@ -541,9 +541,9 @@ Options affecting specific writers
for a file `reference.docx` in the user data directory (see
`--data-dir`). If this is not found either, sensible defaults will be
used. The following styles are used by pandoc: [paragraph]
Normal, Compact, Title, Authors, Date, Abstract, Heading 1, Heading 2,
Heading 3, Heading 4, Heading 5, Block Quote, Definition Term, Definition,
Body Text, Table Caption, Image Caption; [character] Default
Normal, Compact, Title, Subtitle, Authors, Date, Abstract, Heading 1,
Heading 2, Heading 3, Heading 4, Heading 5, Block Quote, Definition Term,
Definition, Body Text, Table Caption, Image Caption; [character] Default
Paragraph Font, Body Text Char, Verbatim Char, Footnote Ref,
Link.

Expand Down
Binary file modified data/reference.docx
Binary file not shown.
12 changes: 9 additions & 3 deletions src/Text/Pandoc/Writers/Docx.hs
Expand Up @@ -485,9 +485,15 @@ writeOpenXML opts (Pandoc meta blocks) = do
Just (MetaBlocks bs) -> bs
Just (MetaInlines ils) -> [Plain ils]
_ -> []
let subtitle' = case lookupMeta "subtitle" meta of
Just (MetaBlocks [Plain xs]) -> xs
Just (MetaBlocks [Para xs]) -> xs
Just (MetaInlines xs) -> xs
_ -> []
title <- withParaProp (pStyle "Title") $ blocksToOpenXML opts [Para tit | not (null tit)]
authors <- withParaProp (pStyle "Authors") $ blocksToOpenXML opts
[Para (intercalate [LineBreak] auths) | not (null auths)]
subtitle <- withParaProp (pStyle "Subtitle") $ blocksToOpenXML opts [Para subtitle' | not (null subtitle')]
authors <- withParaProp (pStyle "Author") $ blocksToOpenXML opts $
map Para auths
date <- withParaProp (pStyle "Date") $ blocksToOpenXML opts [Para dat | not (null dat)]
abstract <- if null abstract'
then return []
Expand All @@ -498,7 +504,7 @@ writeOpenXML opts (Pandoc meta blocks) = do
let blocks' = bottomUp convertSpace $ blocks
doc' <- blocksToOpenXML opts blocks'
notes' <- reverse `fmap` gets stFootnotes
let meta' = title ++ authors ++ date ++ abstract
let meta' = title ++ subtitle ++ authors ++ date ++ abstract
return (meta' ++ doc', notes')

-- | Convert a list of Pandoc blocks to OpenXML.
Expand Down

0 comments on commit 33a051d

Please sign in to comment.