Exemplo n.º 1
0
    def _process(self, mo, text, wiki_elements,element_store):
        """Returns genshi Fragments (Elements and text)

        This is mainly for block level markup. See InlineElement
        for the other method.
        """

        processed = self._build(mo,element_store)
        if isinstance(processed, basestring):
            #print '_process', repr(processed)
            text = ''.join([text[:mo.start()],processed,
                        text[mo.end():]])
            frags = fragmentize(text,wiki_elements,element_store)
        else:
        
            frags = []
            # call again for leading text and extend the result list 
            if mo.start():
                frags.extend(fragmentize(text[:mo.start()],wiki_elements[1:],
                                         element_store))
            # append the found wiki element to the result list
            frags.append(processed)
            # make the source output easier to read
            if self.append_newline:
                frags.append('\n')
            # call again for trailing text and extend the result list
            if mo.end() < len(text):
                frags.extend(fragmentize(text[mo.end():],wiki_elements,
                                         element_store))
        return frags
Exemplo n.º 2
0
    def _process(self, mos, text, wiki_elements,element_store, environ):
        """Returns genshi Fragments (Elements and text)

        This is mainly for block level markup. See InlineElement
        for the other method.
        """
        frags = []
        end = 0
        for mo in mos:
            if end != mo.start():
            # call again for leading text and extend the result list 
                frags.extend(fragmentize(text[end:mo.start()],wiki_elements[1:],
                                         element_store, environ))
            # append the found wiki element to the result list
            built = self._build(mo,element_store, environ)
            if built is not None:
                frags.append(built)
            # make the source output easier to read
            if self.append_newline:
                frags.append('\n')
            end = mo.end()
        # call again for trailing text and extend the result list
        if end < len(text):
            if not isinstance(wiki_elements[0],(list,tuple)):
                wiki_elements = wiki_elements[1:]
            frags.extend(fragmentize(text[end:],wiki_elements,
                                         element_store, environ))

        return frags
Exemplo n.º 3
0
 def _build(self,mo):
     if self.tag:
         return bldr.tag.__getattr__(self.tag)(
                fragmentize(mo.group(1), self.child_tags,
                            remove_escapes=False))
     else:
         return bldr.tag(fragmentize(mo.group(1),self.child_tags,
                                     remove_escapes=False))
Exemplo n.º 4
0
 def _build(self,mo,element_store, environ):
     if self.tag:
         return bldr.tag.__getattr__(self.tag)(
                fragmentize(mo.group(1), self.child_elements,
                            element_store,environ,
                            remove_escapes=False))
     else:
         return bldr.tag(fragmentize(mo.group(1),self.child_elements,
                                     element_store, environ,
                                     remove_escapes=False))
Exemplo n.º 5
0
 def _build(self,mo,element_store, environ):
     content = fragmentize(mo.group(1), self.child_elements, element_store, environ)
     # Check each list item and record those that are block only
     block_only_frags = []
     for i,element in enumerate(content):
         if ((isinstance(element, bldr.Element) and
             element.tag in BLOCK_ONLY_TAGS) or
             isinstance(element,(Stream,Markup))):
             block_only_frags.append(i)
     # Build a new result list if needed
     if block_only_frags:
         new_content = []
         last_i = -1
         for i in block_only_frags:
             if content[last_i+1:i]:
                 if not (len(content[last_i+1:i])==1 and
                                             content[last_i+1] == '\n'):
                     new_content.append(bldr.tag.__getattr__(self.tag)(content[last_i+1:i]))
                 else:
                     new_content.append('\n')
             new_content.append(content[i])
             last_i = i
         if content[last_i+1:]:
             new_content.append(bldr.tag.__getattr__(self.tag)(content[last_i+1:]))
         return bldr.tag(new_content)
     else:
         return bldr.tag.__getattr__(self.tag)(content)
Exemplo n.º 6
0
    def _build(self,mo,element_store):

        link = fragmentize(mo.group(1),self.child_tags,element_store)

        if link:
            return bldr.tag(link)
        else:
            return token[0] + mo.group(0) + token[-1]
Exemplo n.º 7
0
 def _build(self,mo,element_store, environ):
    if mo.group('body') == '':
        value = ''
    else:
        frags = fragmentize(mo.group('body'),self.child_elements,element_store, environ)
        assert len(frags) == 1
        value = frags[0]
    return value
Exemplo n.º 8
0
 def _process(self, mo, text, wiki_elements, element_store):
     """Returns genshi Fragments (Elements and text)"""
     processed = self._build(mo,element_store)
     store_id = str(id(processed)) 
     element_store[store_id] = processed
     text = ''.join([text[:mo.start()],'<<<',store_id,'>>>',
                     text[mo.end():]])
     frags = fragmentize(text,wiki_elements,element_store)
     return frags
Exemplo n.º 9
0
    def _process(self, mo, text, wiki_elements):
        """Returns genshi Fragments (Elements and text)

        This is mainly for block level markup. See InlineElement
        for the other method.
        """
        frags = []
        # call again for leading text and extend the result list 
        if mo.start():
            frags.extend(fragmentize(text[:mo.start()],wiki_elements[1:]))
        # append the found wiki element to the result list
        frags.append(self._build(mo))
        # make the source output easier to read
        if self.append_newline:
            frags.append('\n')
        # call again for trailing text and extend the result list
        if mo.end() < len(text):
            frags.extend(fragmentize(text[mo.end():],wiki_elements))
        return frags
Exemplo n.º 10
0
 def _process(self, mo, text, wiki_elements):
     """Returns genshi Fragments (Elements and text)"""
     global store_id_seq
     processed = self._build(mo)
     store_id = str(store_id_seq) # str(hash(processed))
     element_store[store_id] = processed
     store_id_seq = store_id_seq + 1
     text = ''.join([text[:mo.start()],'<<<',store_id,'>>>',
                     text[mo.end():]])
     frags = fragmentize(text,wiki_elements)
     return frags
Exemplo n.º 11
0
 def _build(self,mo,element_store, environ):
    if mo.group('body') == '':
       value = ''
    else:
       value = fragmentize(mo.group('body'),self.child_elements,
                           element_store, environ)
       if len(value) == 1:
           value = value[0]
       else:
           value = ImplicitList(value)
    name = mo.group('key')
    return (name, value)
Exemplo n.º 12
0
 def _process(self, mo, text, wiki_elements):
     """Returns genshi Fragments (Elements and text)"""
     processed = self._build(mo)
     if isinstance(processed, str):
         text = ''.join([text[:mo.start()],processed,
                     text[mo.end():]])
     else:
         store_id = str(id(processed)) # str(hash(processed))
         element_store.d[store_id] = processed
         text = ''.join([text[:mo.start()],'<<<',store_id,'>>>',
                     text[mo.end():]])
     frags = fragmentize(text,wiki_elements)
     return frags
Exemplo n.º 13
0
    def _build(self,mo):
        """Returns a genshi Element that has ``self.tag`` as the
        outermost tag.

        This methods if called exclusively by ``fragmentize``

        :parameters:
          mo
            match object, usually the one returned by
            self.regexp.search(s) 
        """
        return bldr.tag.__getattr__(self.tag)(fragmentize(mo.group(1),
                                                          self.child_tags))
Exemplo n.º 14
0
    def _process(self, mos, text, wiki_elements,element_store, environ):
        """Returns genshi Fragments (Elements and text)

        Custom _process method here just to avoid unnecessary calling of
        _build.
        """
        
        frags = []
        end = 0
        for mo in mos:
            if end != mo.start():
            # call again for leading text and extend the result list 
                frags.extend(fragmentize(text[end:mo.start()],wiki_elements[1:],
                                         element_store, environ))
            end = mo.end()
        # call again for trailing text and extend the result list
        if end < len(text):
            if not isinstance(wiki_elements[0],(list,tuple)):
                wiki_elements = wiki_elements[1:]
            frags.extend(fragmentize(text[end:],wiki_elements,
                 element_store, environ))

        return frags
Exemplo n.º 15
0
 def _process(self, mo, text, wiki_elements,element_store, environ):
     """Returns genshi Fragments (Elements and text)"""
     processed = self._build(mo,element_store, environ)
     if isinstance(processed, list):
         tail = processed[1]
         processed = processed[0]
     else:
         tail = ''
     if isinstance(processed, basestring) and not isinstance(processed,Markup):
         text = ''.join([text[:mo.start()],processed,tail,
                     text[mo.end():]])
     else:
         store_id = str(id(processed))
         element_store[store_id] = processed
         text = ''.join([text[:mo.start()],'<<<',store_id,'>>>',tail,
                     text[mo.end():]])
     frags = fragmentize(text,wiki_elements,element_store, environ)
     return frags
Exemplo n.º 16
0
 def _process(self, mos, text, wiki_elements, element_store, environ):
     """Returns genshi Fragments (Elements and text)"""
     parts = []
     end = 0
     for mo in mos:
         processed = self._build(mo,element_store, environ)
         store_id = str(id(processed)) 
         element_store[store_id] = processed
         parts.append(''.join([text[end:mo.start()],'<<<',store_id,'>>>']))
         end = mo.end()
     # call again for trailing text and extend the result list
     if end < len(text):
         parts.append(text[end:])
     new_text = ''.join(parts)
     if not isinstance(wiki_elements[0],(list,tuple)):
         wiki_elements = wiki_elements[1:]
     frags = fragmentize(new_text,wiki_elements,element_store, environ)
     return frags
Exemplo n.º 17
0
 def _build(self,mo):
     body = mo.group(1).split(self.delimiter, 1)
     link = body[0]
     if len(body) == 1:
         alias = None
     else:
         alias = body[1].strip()
     for link_type in self.link_types:
         link_mo = link_type.regexp.search(link)
         if link_mo:
             href = link_type.href(link_mo)
             break
     if not link_mo:
         return bldr.tag.span('Bad Link - ',link)
     if not alias:
         alias = link_type.alias(link_mo)
     else:
         alias = fragmentize(alias,self.child_tags)
     return bldr.tag.__getattr__(self.tag)(alias ,href=link_type.href(link_mo))
Exemplo n.º 18
0
 def _build(self,mo,element_store, environ):
    if mo.group('body') == '':
       value = []
    else:
       value = fragmentize(mo.group('body'),self.child_elements,element_store, environ)
    return value
Exemplo n.º 19
0
 def alias(self,mo,element_store, environ):
     """Returns the string for the content of the Element."""
     if not mo.group(4):
         return self.href(mo)
     else:
         return fragmentize(mo.group(4),self.child_elements,element_store, environ)
Exemplo n.º 20
0
 def _build(self,mo,element_store):
     return bldr.tag.__getattr__(self.tag)(style='background:yellow')(fragmentize(mo.group(1), self.child_tags, element_store))
Exemplo n.º 21
0
 def _build(self,mo):
     return bldr.tag.__getattr__(self.tag)(fragmentize(mo.group(2),
                                                       self.child_tags))
Exemplo n.º 22
0
 def alias(self,mo,element_store):
     """Returns the string for the content of the Element."""
     if not mo.group(3):
         return mo.group(1)
     else:
         return fragmentize(mo.group(4),self.child_tags,element_store)
Exemplo n.º 23
0
 def _build(self,mo,element_store):
     return bldr.tag.__getattr__(self.tag)(fragmentize(mo.group(3),
                                                       self.child_tags,
                                                       element_store))
Exemplo n.º 24
0
 def alias(self,mo,element_store):
     """Returns the string for the content of the Element."""
     if not mo.group(5):
         return ''.join([mo.group(1),self.delimiter1,mo.group(2)])
     else:
         return fragmentize(mo.group(5),self.child_tags,element_store)
Exemplo n.º 25
0
 def _build(self,mo,element_store, environ):
     return bldr.tag.__getattr__(self.token_dict[mo.group(1)])(fragmentize(mo.group(2),
                                                       self.child_elements,
                                                       element_store, environ))
Exemplo n.º 26
0
 def _build(self,mo):
     match = self.regexp2.sub(r'\1',mo.group(1))
     
     return bldr.tag.__getattr__(self.tag)(fragmentize(match,self.child_tags,remove_escapes=False))
Exemplo n.º 27
0
 def _build(self,mo,element_store):
     return bldr.tag(fragmentize(mo.group(0),[],element_store))
Exemplo n.º 28
0
 def _build(self,mo,element_store, environ):
     heading_tag = self.tags[len(mo.group(1))-1]
     return bldr.tag.__getattr__(heading_tag)(fragmentize(mo.group(2),
                                                       self.child_elements,
                                                       element_store, environ))
Exemplo n.º 29
0
 def alias(self,mo):
     """Returns the string for the content of the Element."""
     if not mo.group(4):
         return self.href(mo)
     else:
         return fragmentize(mo.group(4),self.child_tags)
Exemplo n.º 30
0
 def _build(self,mo,element_store, environ):
     match = self.regexp2.sub(r'\1',mo.group(1))
     
     return bldr.tag.__getattr__(self.tag)(
         fragmentize(match,self.child_elements,
                     element_store, environ,remove_escapes=False))