One possible solution would be to use Leo-UNL instead of clones. For 
example in your @rst file you put somewhere following:

.. code:: nasm
    LEOUNL:: <here paste leo unl path to desired node>

Then run the following script (could be turned in to button) to generate 
your rst files:
@first # -*- coding:utf-8 -*-
import re
import os
LEOUNLpat = re.compile(u'LEOUNL::([^#]*)#(.*)$', re.M)
def process_rst_files():
    for p1 in c.allNodes_iter():
        if p1.h.startswith(u'@rst '):
            fname = p1.h[5:].strip()
            g.es(u'processing %s'%fname)
            do_one_file(p1, fname)

def do_one_file(p1, fname):
    c.rstCommands.processTree(p1, None, toString=True, justOneFile=True)[0]
    fname = os.path.join(c.getNodePath(p), fname + '.txt')
    s = c.rstCommands.source.decode('utf-8')
    s = putLeoCode(s).encode('utf-8')
    s1 = getfile(fname)
    if s1 != s:
        putfile(fname, s)
        g.es('changed')
    else:
        g.es('unchanged')

def getfile(fname):
    try:
        s = open(fname,'rb').read()
    except IOError:
        s = ""
    return s

def putfile(fname, s):
    out = open(fname, 'wb')
    out.write(s)
    out.close()

def putLeoCode(txt):
    i = 0
    res = []
    while i < len(txt):
        m = LEOUNLpat.search(txt, i)
        if not m:
            res.append(txt[i:])
            break
        else:
            res.append(txt[i:m.start()])
            ind = u'\n' + indentation(txt, m.start())
            leofile = m.group(1)
            unl = m.group(2)
            found, depth, p1 = g.recursiveUNLSearch(unl.split(u"-->"), c)
            if found:
                kod = c.p.b.splitlines(False)
                res.append(ind.join(kod))
            else:
                print (u"Leofile:"+leofile)
                print (u"unl:[%s]"%unl)
                print (u'not found')
                raise ValueError, unl
            i = m.end()
    return u''.join(res)

def indentation(txt, i):
    j = i
    while j > 0 and txt[j-1] == ' ':
        j -= 1
    return ' '*(i-j)
process_rst_files()

I am still using python2. If you use python3 I believe it would complain a 
little about syntax. In that case remove all .encode('utf-8') and 
.decode('utf-8') and all string literals that are prefixed with u should be 
without that prefix.
HTH VItalije

-- 
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.

Reply via email to