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)
This commit is contained in:
parent
5aa76d7d23
commit
ff81f76184
1 changed files with 135 additions and 49 deletions
|
|
@ -18,6 +18,7 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from sat.core.i18n import _
|
||||
from sat.core import exceptions
|
||||
from logging import debug, info, error
|
||||
|
||||
from wokkel import disco, pubsub, iwokkel
|
||||
|
|
@ -104,9 +105,15 @@ class XEP_0071(object):
|
|||
mess_data['extra']['xhtml'] = xhtml_im
|
||||
return mess_data
|
||||
|
||||
rich = mess_data['extra'].pop('rich')
|
||||
syntax = self.synt_plg.getCurrentSyntax(profile)
|
||||
d = self.synt_plg.convert(rich, syntax, self.SYNTAX_XHTML_IM)
|
||||
rich = mess_data['extra'].get('rich', '')
|
||||
xhtml = mess_data['extra'].get('xhtml', '')
|
||||
if rich:
|
||||
d = self.synt_plg.convert(rich, syntax, self.SYNTAX_XHTML_IM)
|
||||
if xhtml:
|
||||
raise exceptions.DataError(_("Can't have xhtml and rich content at the same time"))
|
||||
if xhtml:
|
||||
d = self.synt_plg.clean_xhtml(xhtml)
|
||||
d.addCallback(syntax_converted)
|
||||
return d
|
||||
|
||||
|
|
@ -126,13 +133,8 @@ class XEP_0071(object):
|
|||
def sendMessageTrigger(self, mess_data, treatments, profile):
|
||||
""" Check presence of rich text in extra
|
||||
"""
|
||||
try:
|
||||
rich = mess_data['extra']['rich']
|
||||
# OK, we have found rich text
|
||||
if 'rich' in mess_data['extra'] or 'xhtml' in mess_data['extra']:
|
||||
treatments.addCallback(self._sendMessageAddRich, profile)
|
||||
except KeyError:
|
||||
# No rich text found
|
||||
pass
|
||||
return True
|
||||
|
||||
def _purgeStyle(self, styles_raw):
|
||||
|
|
|
|||
Loading…
Reference in a new issue