git.iko.soy/typeable/pandoc
on master help sign in
Docx writer: include abstract with Abstract style.

Addresses docx part of #1451.

commit2610de0159cb73948d8972a59bbdcbb8ebc6f468 authorJohn MacFarlane <fiddlosopher@gmail.com> dateSat 26 Jul 2014, 22:55 (12 years ago) parentd9751f9
3 files changed+10−3
README+2−2 data/reference.docx src/Text/Pandoc/Writers/Docx.hs+8−1
README+2−2
@@ -541,8 +541,8 @@ Options affecting specific writers
541541 for a file `reference.docx` in the user data directory (see
542542 `--data-dir`). If this is not found either, sensible defaults will be
543543 used. The following styles are used by pandoc: [paragraph]
544− Normal, Compact, Title, Authors, Date, Heading 1, Heading 2, Heading 3,
545− Heading 4, Heading 5, Block Quote, Definition Term, Definition,
544+ Normal, Compact, Title, Authors, Date, Abstract, Heading 1, Heading 2,
545+ Heading 3, Heading 4, Heading 5, Block Quote, Definition Term, Definition,
546546 Body Text, Table Caption, Image Caption; [character] Default
547547 Paragraph Font, Body Text Char, Verbatim Char, Footnote Ref,
548548 Link.
data/reference.docx

Binary file not shown.

src/Text/Pandoc/Writers/Docx.hs+8−1
@@ -481,17 +481,24 @@ writeOpenXML opts (Pandoc meta blocks) = do
481481 _ -> []
482482 let auths = docAuthors meta
483483 let dat = docDate meta
484+ let abstract' = case lookupMeta "abstract" meta of
485+ Just (MetaBlocks bs) -> bs
486+ Just (MetaInlines ils) -> [Plain ils]
487+ Nothing -> []
484488 title <- withParaProp (pStyle "Title") $ blocksToOpenXML opts [Para tit | not (null tit)]
485489 authors <- withParaProp (pStyle "Authors") $ blocksToOpenXML opts
486490 [Para (intercalate [LineBreak] auths) | not (null auths)]
487491 date <- withParaProp (pStyle "Date") $ blocksToOpenXML opts [Para dat | not (null dat)]
492+ abstract <- if null abstract'
493+ then return []
494+ else withParaProp (pStyle "Abstract") $ blocksToOpenXML opts abstract'
488495 let convertSpace (Str x : Space : Str y : xs) = Str (x ++ " " ++ y) : xs
489496 convertSpace (Str x : Str y : xs) = Str (x ++ y) : xs
490497 convertSpace xs = xs
491498 let blocks' = bottomUp convertSpace $ blocks
492499 doc' <- blocksToOpenXML opts blocks'
493500 notes' <- reverse `fmap` gets stFootnotes
494− let meta' = title ++ authors ++ date
501+ let meta' = title ++ authors ++ date ++ abstract
495502 return (meta' ++ doc', notes')
496503
497504-- | Convert a list of Pandoc blocks to OpenXML.