comparison src/plugins/plugin_xep_0071.py @ 832:c4b22aedb7d7

plugin groupblog, XEP-0071, XEP-0277, text_syntaxes: manage raw/rich/xhtml data for content/title: Implementation should follow the following formal specification: "title" and "content" data can be passed in raw, xhtml or rich format. When we receive from a frontend a new/updated microblog item: - keys "title" or "content" have to be escaped (disable HTML tags) - keys "title_rich" or "content_rich" have to be converted from the current syntax to XHTML - keys "title_xhtml" or "content_xhtml" have to be cleaned from unwanted XHTML content Rules to deal with concurrent keys: - existence of both "*_xhtml" and "*_rich" keys must raise an exception - existence of both raw and ("*_xhtml" or "*_rich") is OK As the storage always need raw data, if it is not given by the user it can be extracted from the "*_rich" or "*_xhtml" data (remove the XHTML tags). When a frontend wants to edit a blog post that contains XHTML title or content, the conversion is made from XHTML to the current user-defined syntax. - plugin text_syntaxes: added "text" syntax (using lxml)
author souliane <souliane@mailoo.org>
date Wed, 05 Feb 2014 16:36:51 +0100
parents 1fe00f0c9a91
children c897c8d321b3
comparison
equal deleted inserted replaced
831:d7f9cd8a08cd 832:c4b22aedb7d7
16 16
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from sat.core.i18n import _ 20 from sat.core.i18n import _
21 from sat.core import exceptions
21 from logging import debug, info, error 22 from logging import debug, info, error
22 23
23 from wokkel import disco, pubsub, iwokkel 24 from wokkel import disco, pubsub, iwokkel
24 from zope.interface import implements 25 from zope.interface import implements
25 # from lxml import etree 26 # from lxml import etree
102 body_elt = html_elt.addElement('body', NS_XHTML) 103 body_elt = html_elt.addElement('body', NS_XHTML)
103 body_elt.addRawXml(xhtml_im) 104 body_elt.addRawXml(xhtml_im)
104 mess_data['extra']['xhtml'] = xhtml_im 105 mess_data['extra']['xhtml'] = xhtml_im
105 return mess_data 106 return mess_data
106 107
107 rich = mess_data['extra'].pop('rich')
108 syntax = self.synt_plg.getCurrentSyntax(profile) 108 syntax = self.synt_plg.getCurrentSyntax(profile)
109 d = self.synt_plg.convert(rich, syntax, self.SYNTAX_XHTML_IM) 109 rich = mess_data['extra'].get('rich', '')
110 xhtml = mess_data['extra'].get('xhtml', '')
111 if rich:
112 d = self.synt_plg.convert(rich, syntax, self.SYNTAX_XHTML_IM)
113 if xhtml:
114 raise exceptions.DataError(_("Can't have xhtml and rich content at the same time"))
115 if xhtml:
116 d = self.synt_plg.clean_xhtml(xhtml)
110 d.addCallback(syntax_converted) 117 d.addCallback(syntax_converted)
111 return d 118 return d
112 119
113 def messageReceivedTrigger(self, message, post_treat, profile): 120 def messageReceivedTrigger(self, message, post_treat, profile):
114 """ Check presence of XHTML-IM in message 121 """ Check presence of XHTML-IM in message
124 return True 131 return True
125 132
126 def sendMessageTrigger(self, mess_data, treatments, profile): 133 def sendMessageTrigger(self, mess_data, treatments, profile):
127 """ Check presence of rich text in extra 134 """ Check presence of rich text in extra
128 """ 135 """
129 try: 136 if 'rich' in mess_data['extra'] or 'xhtml' in mess_data['extra']:
130 rich = mess_data['extra']['rich']
131 # OK, we have found rich text
132 treatments.addCallback(self._sendMessageAddRich, profile) 137 treatments.addCallback(self._sendMessageAddRich, profile)
133 except KeyError:
134 # No rich text found
135 pass
136 return True 138 return True
137 139
138 def _purgeStyle(self, styles_raw): 140 def _purgeStyle(self, styles_raw):
139 """ Remove unauthorised styles according to the XEP-0071 141 """ Remove unauthorised styles according to the XEP-0071
140 @param styles_raw: raw styles (value of the style attribute) 142 @param styles_raw: raw styles (value of the style attribute)