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.
Do 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.
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/leo-editor/7ab7a116-b0f7-415f-9bdd-ce798aa1e655o%40googlegroups.com.