title = 'Leo Outline To XHTML List - Demo' outputDir = 'f:\\leo\\list\\' filename = 'index.html' openLevelString = u'
    ' closeLevelString = u'
' openItemString = u'
  • ' closeItemString = u'
  • ' def safe(s): return s.replace('&', '&').replace('<', '<').replace('>', '>') xhtml = [] def main(): global xhtml root = c.rootPosition() xhtml.append(openLevelString) for pp in root.following_siblings_iter(): xhtml.append(openItemString) doItem(pp) xhtml.append(closeItemString) xhtml.append(closeLevelString) xhtml = '\n'.join(xhtml) xhtml = template%(title, xhtml) write(filename, xhtml) g.es('Outline to XHTML: done', color='magenta') def write(name, data): g.es('writing', g.os_path_join(outputDir, name)) f = open(g.os_path_join(outputDir, name), 'wb') try: f.write(data.encode('utf-8')) finally: f.close() def doItem(p): headline = safe(p.headString()) if p.hasChildren(): xhtml.append(headline +openLevelString) for item in p.children_iter(): xhtml.append(openItemString) doItem(item) xhtml.append(closeItemString) xhtml.append(closeLevelString) else: xhtml.append(headline) template = """ %s %s """ main()