On Sun, Sep 25, 2016 at 9:20 AM, <[email protected]> wrote:
I'm in the process of writing a programming book.
> ..
> The usual literate programming tools however leave room for improvement,
> and so I found Leo.
>
Welcome aboard.
>
> So I have a section of code annotated with
> @language assembly_x86
> which displays well in the code branch.
>
> When I clone this section into the book branch it needs the sphinx
> annotation
>
> .. code:: nasm
> or else it
> isn't recognized for block layout (all lines of assembly are displayed
> on a single line in the browser) and syntax highlighting.
>
> So far I have failed to get Leo to use the cloned section to display
> properly in both contexts.
>
You have identified what could be called the Holy Grail of documentation
, namely to use a single source that can generate different text depending
on context.
In all such "challenging" situations, the most straightforward approach is
to use a script to create "helper" nodes from you list of clones. Here is
a tested prototype:
use_tags = False
if use_tags:
tc = c.theTagController
assert tc, 'when use_tags is True this script requires nodetags.py
plugin'
root1 = g.findNodeAnywhere(c, 'my book')
assert root1, 'my book not found'
root2 = g.findNodeAnywhere(c, 'my book (sphinx)')
if root2:
while root2.hasChildren():
root2.firstChild().doDelete()
else:
last = c.lastTopLevel()
root2 = last.insertAfter()
nasm = '.. code:: nasm\n\n'
for p in root1.self_and_subtree():
if not use_tags or use_tags and 'nasm' in tc.get_tags(p):
print(p.h)
p2 = root2.insertAsLastChild()
p2.h = p.h
p2.b = nasm + p.b
root2.expand()
c.redraw()
This creates a *copy *(not clones) of the previously cloned nodes. If
use_tags is true, it adds '.. code:: nasm\n\n' to all nodes tagged with
'nasm'. Otherwise, it adds
'.. code:: nasm\n\n' to all nodes.
Again, this is just a prototype, but it shows that relatively simple Leo
scripts can massage text in any desired manner. This script could be
placed in an @button node.
Please study this script (running it would be best) and ask any further
questions you like.
Edward
--
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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.