- # Parse XSLT
- try:
- document = load_including_children(wldoc)
-
- if cover:
- if cover is True:
- cover = WLCover
- document.edoc.getroot().set('data-cover-width', str(cover.width))
- document.edoc.getroot().set('data-cover-height', str(cover.height))
- if cover.uses_dc_cover:
- if document.book_info.cover_by:
- document.edoc.getroot().set('data-cover-by', document.book_info.cover_by)
- if document.book_info.cover_source:
- document.edoc.getroot().set('data-cover-source', document.book_info.cover_source)
- if flags:
- for flag in flags:
- document.edoc.getroot().set('flag-' + flag, 'yes')
-
- # check for LaTeX packages
- if morefloats:
- document.edoc.getroot().set('morefloats', morefloats.lower())
- elif package_available('morefloats', 'maxfloats=19'):
- document.edoc.getroot().set('morefloats', 'new')
-
- # add customizations
- if customizations is not None:
- document.edoc.getroot().set('customizations', u','.join(customizations))
-
- # hack the tree
- move_motifs_inside(document.edoc)
- hack_motifs(document.edoc)
- parse_creator(document.edoc)
- substitute_hyphens(document.edoc)
- fix_hanging(document.edoc)
-
- # wl -> TeXML
- style_filename = get_stylesheet("wl2tex")
- style = etree.parse(style_filename)
-
- texml = document.transform(style)
-
- # TeXML -> LaTeX
- temp = mkdtemp('-wl2pdf')
+ if uri and provider:
+ f = provider.by_uri(uri)
+ # WTF DocProvider.by_uri() returns IOFile, so no .read() there
+ text = f.read().decode('utf-8')
+ f.close()
+ elif wldoc is not None:
+ text = etree.tostring(wldoc.edoc, encoding=unicode)
+ provider = wldoc.provider
+ else:
+ raise ValueError('Neither a WLDocument, nor provider and URI were provided.')