Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docx writer: use styleIds not styleNames for Title, Subtitle, etc. #10466

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Docx writer: use styleIds not styleNames for Title, Subtitle, etc.
This change affects the default openxml template as well as the
OpenXML writer.

Closes #10282 (regression introduced in pandoc 3.5).
jgm committed Dec 17, 2024
commit 05ba8a0ffaa954fa36e4bedf5196c8f137a328c2
10 changes: 5 additions & 5 deletions data/templates/default.openxml
Original file line number Diff line number Diff line change
@@ -4,31 +4,31 @@
$if(title)$
<w:p>
<w:pPr>
<w:pStyle w:val="Title" />
<w:pStyle w:val="$title-style-id$" />
</w:pPr>
$title$
</w:p>
$endif$
$if(subtitle)$
<w:p>
<w:pPr>
<w:pStyle w:val="Subtitle" />
<w:pStyle w:val="$subtitle-style-id$" />
</w:pPr>
$subtitle$
</w:p>
$endif$
$for(author)$
<w:p>
<w:pPr>
<w:pStyle w:val="Author" />
<w:pStyle w:val="$author-style-id$" />
</w:pPr>
$author$
</w:p>
$endfor$
$if(date)$
<w:p>
<w:pPr>
<w:pStyle w:val="Date" />
<w:pStyle w:val="$date-style-id$" />
</w:pPr>
$date$
</w:p>
@@ -37,7 +37,7 @@ $if(abstract)$
$if(abstract-title)$
<w:p>
<w:pPr>
<w:pStyle w:val="AbstractTitle" />
<w:pStyle w:val="$abstract-title-style-id$" />
</w:pPr>
<w:r><w:t xml:space="preserve">$abstract-title$</w:t></w:r>
</w:p>
8 changes: 8 additions & 0 deletions src/Text/Pandoc/Writers/Docx/OpenXML.hs
Original file line number Diff line number Diff line change
@@ -286,6 +286,8 @@ writeOpenXML opts (Pandoc meta blocks) = do
(fmap (vcat . map (literal . showContent)) . blocksToOpenXML opts)
(fmap (hcat . map (literal . showContent)) . inlinesToOpenXML opts)
meta
cStyleMap <- gets (smParaStyle . stStyleMaps)
let styleIdOf name = fromStyleId $ getStyleIdFromName name cStyleMap
let context = resetField "body" body
. resetField "toc"
(vcat (map (literal . showElement) toc))
@@ -299,6 +301,12 @@ writeOpenXML opts (Pandoc meta blocks) = do
. resetField "date" date
. resetField "abstract-title" abstractTitle
. resetField "abstract" abstract
. resetField "title-style-id" (styleIdOf "Title")
. resetField "subtitle-style-id" (styleIdOf "Subtitle")
. resetField "author-style-id" (styleIdOf "Author")
. resetField "date-style-id" (styleIdOf "Date")
. resetField "abstract-title-style-id" (styleIdOf "AbstractTitle")
. resetField "abstract-style-id" (styleIdOf "Abstract")
$ metadata
tpl <- maybe (lift $ compileDefaultTemplate "openxml") pure $ writerTemplate opts
let rendered = render Nothing $ renderTemplate tpl context