Export Full Content

55 views
Skip to first unread message

Terry

unread,
Sep 11, 2012, 4:33:16 PM9/11/12
to leo-e...@googlegroups.com
I need to present to people who don't have leo installation, in easily readable format, the full content of a .leo file, not just the outline, but all nodes and all contents.

What do I need to do ?

thanks

Terry Brown

unread,
Sep 11, 2012, 4:57:06 PM9/11/12
to leo-e...@googlegroups.com
You could run this script (below):

It only exports selected nodes, so if you want to export everything,
you have to select all the top level nodes, i.e. collapse all the nodes
so only the top level is visible, click the first one, and shift-click
the last one.

It exports to plain text... although you might be able to use the
template to describe HTML, not sure.

---cut here---
# template is everything between r""" and second """
# placeholders are H heading B body C children
# use \n in B and C lines for conditional blank lines

template = r"""H
B
* C"""

lines=[]
exp_only = g.app.gui.runAskYesNoCancelDialog(
c, 'Expanded nodes only?', 'Expanded nodes only?')
if exp_only == 'no':
exp_only = False

def export_text(p, indent=''):

spaces = ' '*(len(indent) - len(indent.lstrip(' ')))

for line in template.split('\n'):

if 'H' in line:
lines.append(indent + line.replace('H', p.h))
elif 'B' in line and p.b.strip():
prefix = line[:line.find('B')].replace('\\n', '\n')
for i in p.b.strip().split('\n'):
lines.append(spaces + prefix + i)
prefix = line[:line.find('B')].replace('\\n', '')
if line.endswith('\\n'):
lines.append('')
elif 'C' in line and (not exp_only or p.isExpanded()):
prefix = line[:line.find('C')].replace('\\n', '\n')
for child in p.children():
export_text(child, indent=spaces + prefix)
if line.endswith('\\n'):
lines.append('')
elif 'C' not in line and 'B' not in line:
lines.append(line)

if exp_only != 'cancel':
for i in c.getSelectedPositions():
export_text(i)

filename = g.app.gui.runSaveFileDialog('Save to file')
# filename = '/home/tbrown/del.txt'

if filename is not None:
open(filename,'w').write('\n'.join(lines))
---cut here---

Terry

unread,
Sep 12, 2012, 9:31:09 AM9/12/12
to leo-e...@googlegroups.com
On Tuesday, September 11, 2012 4:57:10 PM UTC-4, Terry wrote:
> You could run this script (below):


Terry, how do i run it ?  I'm guessing it's not at the cmdline like "python this_script.py"
thanks

Terry Brown

unread,
Sep 12, 2012, 10:43:13 AM9/12/12
to leo-e...@googlegroups.com
On Wed, 12 Sep 2012 06:31:09 -0700 (PDT)
Terry <webto...@gmail.com> wrote:

> Terry, how do i run it ? I'm guessing it's not at the cmdline like "python
> this_script.py"

Right. Paste the content into a node, then click the script-button
button to create a new button for running this script. The button's
name will be the node's name, what it is doesn't matter but 'export'
would be an obvious choice. Then select the node(s) you want exported
- presumably not including the node containing the script :)

Then it will ask for a file name and whether to include unexpanded
nodes.

Cheers -Terry

Terry

unread,
Sep 12, 2012, 4:06:19 PM9/12/12
to leo-e...@googlegroups.com
thanks

Can LEO generate OPML file ? I'm looking at the tool theoutlinerofgiants

Terry Brown

unread,
Sep 12, 2012, 5:05:16 PM9/12/12
to leo-e...@googlegroups.com
On Wed, 12 Sep 2012 13:06:19 -0700 (PDT)
Terry <webto...@gmail.com> wrote:

> Can LEO generate OPML file ? I'm looking at the tool theoutlinerofgiants

There's a leoOPML plugin, I don't know what its status is, try
enabling it... I think OPML support has been through several
iterations, not sure if the plugin was the last of them.

Cheers -Terry
Reply all
Reply to author
Forward
0 new messages