/ Published in: Python
                    
                                        
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
def GetPath(p):
def GetHs(itr): return itr.headString().strip().split('\n')[0].strip()
def GetBs(itr): return itr.bodyString().strip().split('\n')[0].strip()
lst = []
itr = p.copy()
level = p.copy().level()
while level >= 0:
hs = GetHs(itr)
bs = GetBs(itr)
if hs.startswith('@path'):
ThePath = bs
lst.append( ThePath )
else:
if level > 0:
for p in itr.siblings_iter():
hs = GetHs(p)
bs = GetBs(p)
if hs.startswith('@path'):
ThePath = bs
lst.append( ThePath )
itr = itr.parent()
level = level -1
lst.reverse()
s = '\\'.join( lst )
return s
# Iterate and fix
start = p.copy()
current = p.copy()
for p in current.self_and_subtree_iter():
hs = p.headString().strip()
if hs.startswith('@path'):
sPath = GetPath(p)
NewHeadString = '@path ' + sPath
if hs <> NewHeadString:
print 'NewPath->', NewHeadString
c.setHeadString(p, NewHeadString)
else:
print 'PathCheck', hs
Comments
 Subscribe to comments
                    Subscribe to comments
                
                