def convert(self, context): if hasattr(self, 'should_be_removed') and self.should_be_removed: return Frag() children = [] lastchild = None for child in self.find(): if child.name() == 'dt': if lastchild is not None and lastchild.name() == 'dt': children.append(silva.dd(Text(' '))) children.append(silva.dt(child.content.convert(context))) lastchild = child elif child.name() == 'dd': if lastchild is not None and lastchild.name() == 'dd': children.append(silva.dt(Text(' '))) children.append(silva.dd(child.content.convert(context))) lastchild = child if lastchild is not None and lastchild.name() == 'dt': children.append(silva.dd(Text(' '))) return silva.dlist(Frag(children))
def convert(self, context, parentislist=0): if not parentislist: return Frag() # remove all top-level divs, IE seems to place them for some # unknown reason and they screw stuff up in add_paragraphes children = [] for child in self.find(): if child.name() == 'div': for cchild in child.find(): children.append(cchild) else: children.append(child) if context.listtype == 'nlist': content = fix_structure(self.find(), context) return silva.li(Frag(content)) else: content = [] for child in children: content.append(child.convert(context)) return silva.li(content)
def convert(self, context): """This only gets called if the user erroneously used h6 somewhere. """ if hasattr(self, 'should_be_removed') and self.should_be_removed: return Frag() fixedcontent = fix_allowed_items_in_heading(self.find(), context) if (hasattr(self, 'attr') and self.hasattr('_silva_type') and self.getattr('_silva_type') == 'sub'): self.header_type = 'subparagraph' result = silva.heading( fixedcontent, type=self.header_type) return result
def mixin_paragraphs(container): """ wrap silva.p node around text""" content = Frag() breaks = 'heading','p','list','nlist','table' pre, tag, post = container.find_and_partition(breaks) if pre: content.append(p(*pre)) if tag: content.append(tag) if post: content.extend(mixin_paragraphs(post)) return content
def convert(self, context): children = [] lastchild = None for child in self.find(): if child.name() == 'dt': if lastchild is not None and lastchild.name() == 'dt': children.append(html.dd(Text(' '))) children.append(html.dt(child.content.convert(context))) lastchild = child elif child.name() == 'dd': if lastchild is not None and lastchild.name() == 'dd': children.append(html.dt(Text(' '))) children.append(html.dd(child.content.convert(context))) lastchild = child return html.dl(Frag(children))
def convert(self, context): if hasattr(self, 'should_be_removed') and self.should_be_removed: return Frag() if self.is_nlist(context): curlisttype = getattr(context, 'listtype', None) context.listtype = 'nlist' result = self.convert_nlist(context) if curlisttype is not None: context.listtype = curlisttype else: del context.listtype else: curlisttype = getattr(context, 'listtype', None) context.listtype = 'list' result = self.convert_list(context) if curlisttype is not None: context.listtype = curlisttype else: del context.listtype return result
def convert(self, context): if hasattr(self, 'should_be_removed') and self.should_be_removed: return Frag() return Frag(extract_texts(self.content, context))
def convert(self, context, parentistable=0): if not parentistable: return Frag() return silva.row( [cell.convert(context, 1) for cell in self.find(('td','th'))])
def convert(self, context): if hasattr(self, 'should_be_removed') and self.should_be_removed: return Frag() title = self.getattr('alt', '') alignment = self.getattr('alignment', 'default') if alignment == 'default': alignment = '' if self.hasattr('_silva_reference'): reference_name = str(self.getattr('_silva_reference')) reference_name, reference = context.get_reference(reference_name) if reference is not None: target_id = self.getattr('_silva_target', '0') try: target_id = int(str(target_id)) except ValueError: target_id = 0 else: reference_name, reference = context.get_reference('new') target_id = 0 # The target changed, update it if target_id != reference.target_id: reference.set_target_id(target_id) return silva.image( self.content.convert(context), reference=reference_name, alignment=alignment, title=title) # This is an old url-based image link src = getattr(self.attr, 'src', None) if src is None: src = 'unknown' elif hasattr(src, 'content'): src = src.content src = urlparse(str(src))[2] src = IPath(context.request).urlToPath(str(src)) if src.endswith('/image'): src = src[:-len('/image')] # turn path into relative if possible, traverse to the object to # fix an IE problem that adds the current location in front of paths # in an attempt to make them absolute, which leads to nasty paths # such as '/silva/index/edit/index/edit/foo.jpg' try: obj = context.model.unrestrictedTraverse(src.split('/')) # bail out if obj is not a Silva Image, otherwise the old # href value would be lost if not IImage.providedBy(obj): raise NotFound(src) except (KeyError, NotFound): pass else: modelpath = context.model.aq_parent.getPhysicalPath() src = '/'.join(Path(modelpath, obj.getPhysicalPath())) return silva.image( self.content.convert(context), path=src, alignment=alignment, title=title)
def convert(self, context): title = self.getattr('title', default='') name = self.getattr('name', default=None) href = self.getattr('href', default='#') anchor = self.getattr('_silva_anchor', default=None) window_target = self.getattr('target', default='') link_attributes = {'target': window_target, 'title': title, 'anchor': anchor} if name is not None and href == '#': # Case one, we are an anchor if self.getattr('class', None) == 'index': # index item text = ''.join([t.convert(context).asBytes('UTF-8') for t in extract_texts(self, context)]) textnode = Frag() if text and (text[0] != '[' or text[-1] != ']'): textnode = Text(text) return Frag( textnode, silva.index(name=name, title=title)) else: # named anchor, probably pasted from some other page return Frag(self.content.convert(context)) elif self.hasattr('_silva_reference'): # Case of a Silva reference used reference_name = str(self.getattr('_silva_reference')) reference_name, reference = context.get_reference(reference_name) if reference is not None: target_id = self.getattr('_silva_target', '0') try: target_id = int(str(target_id)) assert get_content_from_id(target_id) is not None except (ValueError, AssertionError): # Invalid target id, set it as zero (broken) target_id = 0 else: # Invalid reference. We create a new one and mark the # target as broken reference_name, reference = context.get_reference('new') target_id = 0 # If the target changed, update it if target_id != reference.target_id: reference.set_target_id(target_id) link_attributes['reference'] = reference_name return silva.link( self.content.convert(context), **link_attributes) elif self.hasattr('href'): # External links url = self.getattr('_silva_href', None) if url is None: url = self.getattr('href', '') if unicode(url).startswith('/'): # convert to physical path before storing url = Text(IPath(context.request).urlToPath(unicode(url))) if url: link_attributes['url'] = url return silva.link( self.content.convert(context), **link_attributes) elif anchor is not None: # Link to an anchor on the same page return silva.link( self.content.convert(context), **link_attributes) else: return Frag()
def convert(self, context): if hasattr(self, 'should_be_removed') and self.should_be_removed: return Frag() fixedcontent = fix_allowed_items_in_heading(self.find(), context) return silva.heading(fixedcontent, type=self.header_type)
def convert(self, context): return Frag()
def convert(self): return Frag()
def convert(self, context): # external source element id = self.attr.id params = {} attrparams = {} divcontent = [] source = getSourceForId(context.model, str(id)) if source is not None: meta_type = source.meta_type source_title = source.get_title() or id source_form = source.get_parameters_form() header = html.h4(Text(u'%s \xab%s\xbb' % (meta_type, source_title)), title=u'source id: %s'%id) description = source.get_description() if description: divcontent.append( html.p(description, class_="externalsource-description")) else: source_title = '' source_form = None header = html.h4( Text('[%s]' % _('external source element is broken'))) for child in self.find(): if child.name() == 'parameter': vtype = child.getattr('type', 'string').convert(context).extract_text() value = child.content.convert(context).asBytes('utf-8') key = child.attr.key.convert(context).extract_text() attrkey = '%s__type__%s' % (key,vtype) if vtype == 'list': value = [unicode(x, 'utf-8') for x in eval(value)] else: value = unicode(value, 'utf-8') params[key] = (value,attrkey) divpar = [] for key in params: value, attrkey = params[key] display_key = key if source_form is not None: try: display_key = source_form.get_field(key).title() except AttributeError: pass # Field is gone divpar.append(html.strong("%s: " % display_key)) if '__type__list' in attrkey: for v in value: divpar.append(html.span( Text(xml_unescape(v)), {'key': attrkey})) divpar.append(Text(', ')) divpar.pop() else: divpar.append(html.span( Text(xml_unescape(value)), {'key': attrkey})) divpar.append(html.br()); par = html.div(Frag(divpar), {'class': 'parameters'}) divcontent.append(par) content = Frag(header, divcontent); return html.div(content, source_id=id, source_title = source_title, class_='externalsource', **attrparams)