- style_filename = os.path.join(os.path.dirname(__file__), 'book2html.xslt')
- style = etree.parse(style_filename)
-
- if is_file:
- document = WLDocument.from_file(input, True)
- else:
- document = WLDocument.from_string(input, True)
-
- result = document.transform(style)
- del document # no longer needed large object :)
-
- if result.find('//p') is not None:
- add_anchors(result.getroot())
- add_table_of_contents(result.getroot())
-
- if output_filename is not None:
- result.write(output_filename, xml_declaration=False, pretty_print=True, encoding='utf-8')
+ try:
+ style_filename = get_stylesheet(stylesheet)
+ style = etree.parse(style_filename)
+
+ document = copy.deepcopy(wldoc)
+ del wldoc
+ document.swap_endlines()
+
+ if flags:
+ for flag in flags:
+ document.edoc.getroot().set(flag, 'yes')
+
+ document.clean_ed_note()
+
+ if not options:
+ options = {}
+ result = document.transform(style, **options)
+ del document # no longer needed large object :)
+
+ if html_has_content(result):
+ add_anchors(result.getroot())
+ add_table_of_contents(result.getroot())
+
+ return IOFile.from_string(
+ etree.tostring(result, method='html', xml_declaration=False, pretty_print=True, encoding='utf-8'))