diff --git a/modules/purchase_trade/process_documentation.py b/modules/purchase_trade/process_documentation.py index cafde12..0f1a74b 100644 --- a/modules/purchase_trade/process_documentation.py +++ b/modules/purchase_trade/process_documentation.py @@ -2,7 +2,6 @@ # this repository contains the full copyright notices and license terms. import base64 import html -import json import mimetypes import os import posixpath @@ -24,26 +23,39 @@ class ProcessDocumentation(ModelSingleton, ModelSQL, ModelView): content = fields.Function(fields.Text('Content'), 'get_content') def get_content(self, name): - pages = _documentation_pages() return HTML_TEMPLATE % { - 'initial': pages.get('README.md', ''), - 'pages': json.dumps(pages).replace('%s' % ( + _anchor(relative_name), _markdown_to_html(markdown, relative_name)) def _relative_name(path): return path.relative_to(DOCUMENTATION_ROOT.resolve()).as_posix() +def _anchor(filename): + return 'doc-' + re.sub(r'[^a-zA-Z0-9_-]+', '-', filename) + + def _resolve_link(current_file, target): if target.startswith(('#', 'http://', 'https://', 'mailto:')): return target @@ -81,8 +93,8 @@ def _inline(markdown, current_file): else: parts.append(label) elif resolved.endswith('.md'): - parts.append('%s' % ( - html.escape(resolved, quote=True), label)) + parts.append('%s' % ( + html.escape(_anchor(resolved), quote=True), label)) elif resolved.startswith(('#', 'http://', 'https://', 'mailto:')): parts.append('%s' % ( html.escape(resolved, quote=True), label)) @@ -144,7 +156,7 @@ def _markdown_to_html(markdown, current_file): if current_file != 'README.md': body.insert( - 0, '

Back to index

') + 0, '

Back to index

') return '\n'.join(body) @@ -212,27 +224,7 @@ HTML_TEMPLATE = ''' -
%(initial)s
- +
%(content)s
''' diff --git a/modules/purchase_trade/view/process_documentation_form.xml b/modules/purchase_trade/view/process_documentation_form.xml index 456745d..30d1980 100644 --- a/modules/purchase_trade/view/process_documentation_form.xml +++ b/modules/purchase_trade/view/process_documentation_form.xml @@ -1,5 +1,5 @@
- - + +