diff --git a/modules/purchase_trade/process_documentation.py b/modules/purchase_trade/process_documentation.py index 52a3180..804d4a7 100644 --- a/modules/purchase_trade/process_documentation.py +++ b/modules/purchase_trade/process_documentation.py @@ -15,6 +15,8 @@ from trytond.transaction import Transaction DOCUMENTATION_ROOT = Path(__file__).with_name('process_documentation') MARKDOWN_LINK = re.compile(r'(!?)\[([^\]]*)\]\(([^)]+)\)') +HTML_IMAGE_SOURCE = re.compile( + r'(]*\bsrc=)(["\'])([^"\']+)(\2)', re.IGNORECASE) class ProcessDocumentation(ModelSingleton, ModelSQL, ModelView): @@ -50,13 +52,30 @@ def _html_file_content(filename): common_path = os.path.commonpath([str(root), str(path)]) if path != root and common_path == str(root): if path.exists() and path.is_file() and path.suffix.lower() == '.html': + document = path.read_text(encoding='utf-8') + document = _inline_html_assets(document, _relative_name(path)) return IFRAME_TEMPLATE % { - 'document': html.escape(path.read_text(encoding='utf-8'), - quote=True), + 'document': html.escape(document, quote=True), } return _html_error('Documentation page not found: %s' % filename) +def _inline_html_assets(document, current_file): + def replace(match): + prefix, quote, source, suffix = match.groups() + resolved = _resolve_link(current_file, source) + if resolved.startswith(('http://', 'https://', 'data:', 'mailto:')): + return match.group(0) + + data_uri = _asset_data_uri(resolved) + if not data_uri: + return match.group(0) + return '%s%s%s%s' % (prefix, quote, html.escape(data_uri, quote=True), + suffix) + + return HTML_IMAGE_SOURCE.sub(replace, document) + + def _html_error(message): document = HTML_TEMPLATE % { 'content': '

%s

' % html.escape(message), diff --git a/modules/purchase_trade/process_documentation/ITSA/Operations_Workflow.html b/modules/purchase_trade/process_documentation/ITSA/Operations_Workflow.html index e042027..bfa2256 100644 --- a/modules/purchase_trade/process_documentation/ITSA/Operations_Workflow.html +++ b/modules/purchase_trade/process_documentation/ITSA/Operations_Workflow.html @@ -382,7 +382,7 @@
  • Contract lines: product, quantity, unit, tolerance, price formula, Mtm.
  • - Purchase contract header + Purchase contract header