diff --git a/muk_utils/__manifest__.py b/muk_utils/__manifest__.py index 296f52a..6aa4b67 100644 --- a/muk_utils/__manifest__.py +++ b/muk_utils/__manifest__.py @@ -19,7 +19,7 @@ { "name": "MuK Utils", "summary": """Utility Features""", - "version": '12.0.1.6.8', + "version": '12.0.1.6.9', "category": 'Extra Tools', "license": "AGPL-3", "author": "MuK IT", diff --git a/muk_utils/tools/__init__.py b/muk_utils/tools/__init__.py index 515d931..5940866 100644 --- a/muk_utils/tools/__init__.py +++ b/muk_utils/tools/__init__.py @@ -17,6 +17,7 @@ # ################################################################################### +from . import rst from . import file from . import json from . import cache diff --git a/muk_utils/tools/rst.py b/muk_utils/tools/rst.py new file mode 100644 index 0000000..b5ba4d6 --- /dev/null +++ b/muk_utils/tools/rst.py @@ -0,0 +1,52 @@ +################################################################################### +# +# Copyright (C) 2018 MuK IT GmbH +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +################################################################################### + +import logging + +from docutils import nodes +from docutils.core import publish_string +from docutils.transforms import Transform, writer_aux +from docutils.writers.html4css1 import Writer + +from odoo import tools + +_logger = logging.getLogger(__name__) + +class ReStructuredTextFilterMessages(Transform): + default_priority = 870 + def apply(self): + for node in self.document.traverse(nodes.system_message): + node.parent.remove(node) + +class ReStructuredTextWriter(Writer): + def get_transforms(self): + return [ReStructuredTextFilterMessages, writer_aux.Admonitions] + +def rst2html(content): + overrides = { + 'embed_stylesheet': False, + 'doctitle_xform': False, + 'output_encoding': 'unicode', + 'xml_declaration': False, + } + output = publish_string(content, + settings_overrides=overrides, + writer=ReStructuredTextWriter() + ) + return tools.html_sanitize(output)