Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0277.py @ 837:eff944ff3e13
plugin XEP_0277: check for XHTML namespace and decapsulate the content from the main div container
author | souliane <souliane@mailoo.org> |
---|---|
date | Wed, 12 Feb 2014 15:23:15 +0100 |
parents | c4b22aedb7d7 |
children | 8829a6c0b070 |
comparison
equal
deleted
inserted
replaced
836:2cc0201b4613 | 837:eff944ff3e13 |
---|---|
119 try: | 119 try: |
120 content_type = attr.attrs['type'].lower() | 120 content_type = attr.attrs['type'].lower() |
121 except KeyError: | 121 except KeyError: |
122 content_type = 'text' | 122 content_type = 'text' |
123 if content_type == 'xhtml': | 123 if content_type == 'xhtml': |
124 # TODO: proper check of body namespace | 124 text = self.__decapsulateExtraNS(attr.text) |
125 microblog_data['%s_xhtml' % key] = yield self.host.plugins["TEXT-SYNTAXES"].clean_xhtml(attr.text) | 125 microblog_data['%s_xhtml' % key] = yield self.host.plugins["TEXT-SYNTAXES"].clean_xhtml(text) |
126 else: | 126 else: |
127 microblog_data[key] = attr.text | 127 microblog_data[key] = attr.text |
128 if key not in microblog_data and ('%s_xhtml' % key) in microblog_data: | 128 if key not in microblog_data and ('%s_xhtml' % key) in microblog_data: |
129 microblog_data[key] = yield self.__removeXHTMLMarkups(microblog_data['%s_xhtml' % key]) | 129 microblog_data[key] = yield self.__removeXHTMLMarkups(microblog_data['%s_xhtml' % key]) |
130 if 'title' not in microblog_data: | 130 if 'title' not in microblog_data: |
170 except: | 170 except: |
171 error(_('Cannot find author')) | 171 error(_('Cannot find author')) |
172 ##end workaround Jappix | 172 ##end workaround Jappix |
173 | 173 |
174 defer.returnValue(microblog_data) | 174 defer.returnValue(microblog_data) |
175 | |
176 def __decapsulateExtraNS(self, text): | |
177 """Check for XHTML namespace and decapsulate the content so the user | |
178 who wants to modify an entry will see the text that he entered. Also | |
179 this avoids successive encapsulation with a new <div>...</div> at | |
180 each modification (encapsulation is done in self.data2entry)""" | |
181 elt = ElementParser()(text) | |
182 if elt.uri != NS_XHTML: | |
183 raise exceptions.DataError(_('Content of type XHTML must declare its namespace!')) | |
184 return elt.firstChildElement().toXml() | |
175 | 185 |
176 def microblogCB(self, itemsEvent, profile): | 186 def microblogCB(self, itemsEvent, profile): |
177 d = defer.Deferred() | 187 d = defer.Deferred() |
178 | 188 |
179 def manageItem(microblog_data): | 189 def manageItem(microblog_data): |