What more are you thinking about? The script I posted was an enhancement of 
an wokrbook one I used to make sure I knew how to do a basic walk down the 
tree, so it's very bare-bones.

On Thursday, September 11, 2025 at 1:08:06 PM UTC-4 jkn wrote:

> Thanks Thomas. This does not give me quite what I was thinking of but I 
> can certainly experiment with it.
>
> I was not aware of, or had forgotten, the 'webbrowser' module, so thanks 
> for that also;-)
>
>     J^n
>
>
> On Thursday, September 11, 2025 at 2:26:46 PM UTC+1 [email protected] 
> wrote:
>
>> 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 [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/leo-editor/9fb90fcc-8c1f-4e06-b91b-1668cb9258aen%40googlegroups.com.

Reply via email to