On Tue, 11 Sep 2012 13:33:16 -0700 (PDT)
Terry <[email protected]> wrote:
> 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 ?
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---
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/leo-editor?hl=en.