|
|
def _apply_description_images(doc):
html = lxml.html.document_fromstring(doc)
for element, _attribute, _link, _pos in html.iterlinks():
if element.get('src') and not '//' in element.get('src') and not 'static/' in element.get('src'):
element.set('src', "/%s/static/description/%s" % (module.name, element.get('src')))
return tools.html_sanitize(lxml.html.tostring(html, encoding='unicode'))
for module in self:
if not module.name:
module.description_html = False
continue
path = os.path.join(module.name, 'static/description/index.html')
try:
with tools.file_open(path, 'rb') as desc_file:
doc = desc_file.read()
if doc.startswith(XML_DECLARATION):
warnings.warn(
f"XML declarations in HTML module descriptions are "
f"deprecated since Odoo 17, {module.name} can just "
f"have a UTF8 description with not need for a "
f"declaration.",
category=DeprecationWarning,
)
else:
try:
doc = doc.decode()
except UnicodeDecodeError:
warnings.warn(
f"Non-UTF8 module descriptions are deprecated "
f"since Odoo 17 ({module.name}'s description "
f"is not utf-8)",
category=DeprecationWarning,
)
module.description_html = _apply_description_images(doc)
except FileNotFoundError:
overrides = {
'embed_stylesheet': False,
'doctitle_xform': False,
'output_encoding': 'unicode',
'xml_declaration': False,
'file_insertion_enabled': False,
}
raw_description = module.description or ''
try:
output = publish_string(source=raw_description, settings_overrides=overrides, writer=MyWriter())
except Exception as e: # noqa: BLE001
_logger.warning("Failed to render module description for %s: %s. Falling back to raw description.", module.name, e)
output = Markup('<pre><code>%s</code></pre>') % raw_description
module.description_html = _apply_description_images(output)
|
|