Recipe for Converting Markdown To Libre Office Files Using Pandoc

78 views
Skip to first unread message

Thomas Passin

unread,
Jun 25, 2020, 9:38:54 AM6/25/20
to leo-e...@googlegroups.com
I recently wrote a document in Leo using Markdown format.  I really intended it to become a Libre Office document on the end.  I wanted to share how I converted the MD document to .odt.  With minor changes, the recipe should work for a range of other formats, like .doc.

First, install pandoc on your computer.  This isn't a Python package; it's an executable of its own.  Make sure that it will run when invoked by issuing the pandoc command (i.e., make sure it's on the path).

Next, your MD doc should be in a Leo @auto-md tree. This means that the top-level node in the outline should have a headline like this:

@auto-md your-doc-name.md

Write your document; no need for <<named sections>> or @other directives.  When you save the Leo outline, the MD file will also be saved.

Before you convert the document, you need a template.  This would specify font, line spacing, and whatever else you want.  In Libreoffice, Word, and many other word processors, you just create a basic document with these properties and save it as a template.  Let's say its name is your-template.odt.  Save it in the same location as your-doc-name.md.

To run the conversion, create an @command node in your @settings tree, preferably in the Leo outline you using.  The body of the @command node should contain the following (change the file names to match the real ones you use):

import subprocess
cmd = ['pandoc', '-t', 'odt', '
your-doc-name.md',
        '--reference-doc=
your-template.odt',
        '-o', '
your-doc-name.odt']
subprocess.call(cmd)

I have this command in a node with the following headline:

@command pandoc-to-odt

To install the command, just reload the file it is in.  Then you can invoke it using ALT-x pandoc-to-odt like you would any other Leo command.  This will create the file your-doc-name.odt in the same directory.

I found that the resulting .odt file needed a little tuning up, mostly by adding occasional blank lines where Pandoc's MD processor seemed to have omitted them.  Footnotes worked as expected.  Overall I was happy with the whole process.

It would not be hard to adapt the command to pick up the file name from the headline of the @auto-md node so that the same command would work for other files, but I haven't done that here.

Edward K. Ream

unread,
Jun 25, 2020, 12:14:39 PM6/25/20
to leo-editor
On Thu, Jun 25, 2020 at 8:38 AM Thomas Passin <tbp1...@gmail.com> wrote:
I recently wrote a document in Leo using Markdown format.  I really intended it to become a Libre Office document on the end.  I wanted to share how I converted the MD document to .odt.  With minor changes, the recipe should work for a range of other formats, like .doc.

Please create an Info issue for this. That way the documentation will be more easily accessible.

Edward

Rob

unread,
Jun 25, 2020, 3:22:02 PM6/25/20
to leo-editor
That's terrific, Thomas!  I do much the same thing except I run the pandoc script in a command window. I build the pandoc commands in Leo, then copy/paste them into the shell. I'll have to try your recipe as it might save me a few steps.

Rob...

Thomas Passin

unread,
Jun 25, 2020, 4:55:57 PM6/25/20
to leo-editor
The script could also be put into an ordinary (non-@setting) node and run with CNTRL-B or turned into a button.

Thomas Passin

unread,
Jun 25, 2020, 10:49:30 PM6/25/20
to leo-editor
I'm not sure what you want here.  How should this differ from any other issue posted to GitHub?

jkn

unread,
Jun 26, 2020, 4:15:02 AM6/26/20
to leo-editor


On Thursday, June 25, 2020 at 8:22:02 PM UTC+1, Rob wrote:
That's terrific, Thomas!  I do much the same thing except I run the pandoc script in a command window. I build the pandoc commands in Leo, then copy/paste them into the shell. I'll have to try your recipe as it might save me a few steps.

Rob...

Yeah, I too do the same sort of thing (also with adoc, and to PDF etc) via pandoc and a Makefile. This might be a good spur to get it all running withing Leo...

Edward K. Ream

unread,
Jun 26, 2020, 6:11:00 AM6/26/20
to leo-editor

On Thursday, June 25, 2020 at 9:49:30 PM UTC-5, Thomas Passin wrote:
I'm not sure what you want here.  How should this differ from any other issue posted to GitHub?

It would have the label "Info".

Edward

Matt Wilkie

unread,
Jul 5, 2020, 11:22:33 AM7/5/20
to leo-editor
I'm not sure what you want here.  How should this differ from any other issue posted to GitHub?

It would have the label "Info".

Info "issues" are documentation or tips and tricks. See https://github.com/leo-editor/leo-editor/issues?q=is%3Aopen+is%3Aissue+label%3AInfo

Arguably these would be better as wiki pages so that the total number of open issues is not inflated, making it look like there are more problems than there are. We tried having them in wiki pages before, on a couple of different platforms, but they suffered from an "they're out there in the storage shed" problem: too far from the regular conversation, and consequently neglected.

-matt

Edward K. Ream

unread,
Jul 5, 2020, 1:31:44 PM7/5/20
to leo-editor
On Sun, Jul 5, 2020 at 10:22 AM Matt Wilkie <map...@gmail.com> wrote:

Info "issues" are documentation or tips and tricks. See https://github.com/leo-editor/leo-editor/issues?q=is%3Aopen+is%3Aissue+label%3AInfo

Arguably these would be better as wiki pages so that the total number of open issues is not inflated, making it look like there are more problems than there are.

The total number of open issues doesn't bother me at all. I suppose we could close info issues, but that might be misleading in a different way. Anyway, it's the total number of bugs that we want to minimize.

Edward
Reply all
Reply to author
Forward
0 new messages