# HG changeset patch # User Thierry Florac # Date 1545396994 -3600 # Node ID 7601e1471970bf7ce238298e31f21f359e73dab4 # Parent 3f26c34ccaabd7f7fd3a5399e3e242f19a66b72e Added "remove_tags" HTML renderer diff -r 3f26c34ccaab -r 7601e1471970 src/pyams_content/features/html/__init__.py --- a/src/pyams_content/features/html/__init__.py Fri Dec 21 10:26:11 2018 +0100 +++ b/src/pyams_content/features/html/__init__.py Fri Dec 21 13:56:34 2018 +0100 @@ -12,22 +12,18 @@ __docformat__ = 'restructuredtext' +from pyquery import PyQuery +from pyramid.interfaces import IRequest -# import standard library -from pyquery import PyQuery - -# import interfaces from pyams_sequence.interfaces import ISequentialIntIds +from pyams_sequence.reference import get_reference_target +from pyams_utils.adapter import ContextRequestAdapter, adapter_config from pyams_utils.interfaces.text import IHTMLRenderer from pyams_utils.interfaces.url import DISPLAY_CONTEXT +from pyams_utils.registry import get_utility +from pyams_utils.text import text_to_html +from pyams_utils.url import relative_url from pyams_workflow.interfaces import IWorkflowPublicationInfo -from pyramid.interfaces import IRequest - -# import packages -from pyams_sequence.reference import get_reference_target -from pyams_utils.adapter import adapter_config, ContextRequestAdapter -from pyams_utils.registry import get_utility -from pyams_utils.url import relative_url @adapter_config(name='oid_to_href', context=(str, IRequest), provides=IHTMLRenderer) @@ -36,7 +32,7 @@ def render(self): context = self.request.annotations.get(DISPLAY_CONTEXT, self.request.context) - html = PyQuery('
{0}
'.format(self.context)) + html = PyQuery('
{}
'.format(self.context)) sequence = get_utility(ISequentialIntIds) for link in html('a[href]'): href = link.attrib['href'] @@ -51,3 +47,12 @@ # invalid link => remove href! del link.attrib['href'] return html.html() + + +@adapter_config(name='remove_tags', context=(str, IRequest), provides=IHTMLRenderer) +class TagsRemoveHTMLRenderer(ContextRequestAdapter): + """Remove all tags from HTML code""" + + def render(self): + html = PyQuery('
{}
'.format(self.context)) + return text_to_html(html.text())