Writer recently got a new markdown import option to take styles from a template, leading to much prettier output when converting markdown to PDF, DOCX or ODT.
This work is primarily for Collabora Online, but the templating feature is available in desktop Writer as well.
Motivation¶
A previous post mentioned recent improvements to the markdown import/export in Writer.
But if you convert some markdown to e.g. PDF, all the headings just have the default look, wouldn't it be nice to take your organization template and add colors and other formatting there, automatically?
Also, wouldn't it be nice if you could paste as markdown in COOL or copy the current selection as markdown? Which would enable all sorts of interesting use-cases, like using an external API to turn the selection into a summary or translating it to a different language.
Results so far¶
Here is a sample input markdown:
# heading 1
body text
Here is how it looks like if you template it using the core.git sw/qa/filter/md/data/template.docx
sample:
curl invocation for this:
curl -k -F "data=@/path/to/test.md" -F "template=@/path/to/template.docx" -F "format=pdf" -o out.pdf https://localhost:9980/cool/convert-to
Or example desktop command-line:
soffice --infilter='Markdown:{"TemplateURL":{"type":"string","value":"./template.ott"}}' test.md
While it would look like this by default:
The other part is the PostMessage API of COOL, if you want to copy and paste as markdown. What's newly possible:
- Copy the current selection: set MessageId to
Action_Copyand the value to{"Mimetype": "text/markdown;charset=utf-8"} - Paste at the current cursor position: set MessageId to
Action_Pasteand the value to something like{"Mimetype": "text/markdown;charset=utf-8", "Data": "foo _bar_ baz"}
You can read more about the PostMessage API in the COOL SDK.
How is this implemented?¶
If you would like to know a bit more about how this works, continue reading... :-)
As usual, the high-level problem was addressed by a series of small changes. Core side:
- tdf#169316 sw markdown import: add a TemplateURL parameter
- tdf#169316 sw markdown import, template: handle non-ODF formats as well
- cool#13468 sw markdown paste: add UNO command parameter to skip the detection
- Related: tdf#169251 sw markdown export: fix crash on OLE with no graphic
Online side:
- cool#13419 convert-to template option: handle multiple streams in ConvertToPartHandler
- cool#13419 convert-to template option: pass it to doc broker
- cool#13419 convert-to template option: pass it to the kit process
- cool#13419 convert-to template option: more strict param name, generalize filenames
- cool#13419 convert-to template option: add testcase
- cool#13468 PostMessage API: allow copying the current text selection
Want to start using this?¶
You can get a development edition of Collabora Online 25.04 and try it out yourself right now: try the development edition. Collabora intends to continue supporting and contributing to LibreOffice, the code is merged so we expect the core of this …

PDF result: templated
PDF result: default
Interdependent tracked change: baseline
Interdependent tracked change: default accept result
Interdependent tracked change: direct accept via the dialog
Interdependent tracked change: direct accept result
Code span: baseline
Code span: old result
Code span: new result
Lists: baseline
Lists: old result
Lists: new result
Image: baseline
Image: old result
Image: new result
Table: baseline
Table: old result
Table: new result
Quote: baseline
Quote: old result
Quote: new result
Interdependent tracked change: improved format, after document load
Interdependent tracked change: old reject, lost character style / direct format
Interdependent tracked change: new reject, handled character style / direct format
Unit selection
Floating table, followed by heading: new Writer render
Floating table, followed by heading: old Writer render
Floating table, followed by heading: reference render


Interdependent tracked change: just insert
Interdependent tracked change: old, format is not tracked separately
Interdependent tracked change: new, format is tracked separately
Interdependent tracked change: UI dialog now showing multiple redlines
Interdependent tracked change: insert, then delete
Interdependent tracked change: insert, then format
Interdependent tracked change: delete, then format
Reinstate: an insert
Reinstate: a reinstated insert
Reinstate: a delete
Reinstate: a reinstated delete
LibreOffice splash screen bitmap
LibreOffice dev splash screen


git log