On Thursday, September 11, 2025 at 7:23:06 AM UTC-4 jkn wrote:

FWIW I might have a use for this as a cheap way of printing out 'scratch' 
nodes/subnodes, with indentation. I make things like shopping lists this 
way. Having a default scratch HTML file might be a nicer way to do this, 
for me at least.


Here's a quick-and-dirty script to display a subtree in the browser as an 
indented list. It leaves an .html file in the ~/.leo directory. It's not 
fancy but it does the job. 

@language python
"""Display current subtree in web browser.

   Writes a temporary .html file in ~/.leo.
"""
 
import os.path
import webbrowser
from tempfile import NamedTemporaryFile

TEMPDIR = os.path.expanduser(r'~/.leo')
ENCODING = 'utf-8'

def subtree_to_indented_list(event = None):
    """Output to browser an indented list for a subtree."""
    tree = c.p.self_and_subtree()

    indented = ''
    for x in tree:
        indent = '   ' * (x.level() - 1)
        body_lines = x.b.split('\n')
        body_lines_indented = [indent + l for l in body_lines]
        body = '\n'.join(body_lines_indented)
        indented += indent + x.h + '\n' + body + '\n'
    return indented

indented = subtree_to_indented_list()

if indented:
    html = f'<pre>{indented}</pre>'
    with NamedTemporaryFile(suffix = '.html',
            dir = TEMPDIR, delete = False) as f:
        f.write(html.encode(ENCODING))
    webbrowser.open(f.name)
else:
    g.es('No results')

I also have a version that will open a print dialog and print on a printer, 
if you would like that.

-- 
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 leo-editor+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/leo-editor/03103b6d-36f5-428c-90ac-de66c88f1af0n%40googlegroups.com.

Reply via email to