Example #1
0
 def role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
     if not extension.is_isolated:
         content = Element('span')
         content.text = utils.unescape(text)
     else:
         content = utils.unescape(text)
     element = extension.process({}, content)
     return [zeml(zeml=element)], []
Example #2
0
 def role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
     if not extension.is_isolated:
         content = Element('span')
         content.text = utils.unescape(text)
     else:
         content = utils.unescape(text)
     element = extension.process({}, content)
     return [zeml(zeml=element)], []
Example #3
0
 def run(self):
     if self.arguments:
         self.options[extension.argument_attribute] = self.arguments[0]
     content = '\n'.join(self.content)
     reason = self.state.document.settings.parsing_reason
     if not extension.is_isolated:
         content_tmp = RstParser(app).parse(content, reason)
         content = Element('div')
         content.children = content_tmp.children
         for child in content.children:
             child.parent = content
     element = extension.process(self.options, content, reason)
     return [zeml(zeml=element)]
Example #4
0
 def run(self):
     if self.arguments:
         self.options[extension.argument_attribute] = self.arguments[0]
     content = '\n'.join(self.content)
     reason = self.state.document.settings.parsing_reason
     if not extension.is_isolated:
         content_tmp = RstParser(app).parse(content, reason)
         content = Element('div')
         content.children = content_tmp.children
         for child in content.children:
             child.parent = content
     element = extension.process(self.options, content, reason)
     return [zeml(zeml=element)]
Example #5
0
        def convert(node, is_root):
            if is_root:
                result = RootElement()
            else:
                result = Element(node.name)
            if node._attributes:
                result.attributes.update(node._attributes)

            for item in node:
                if isinstance(item, (str, unicode, Token)):
                    add_text(result, self._to_text(item))
                else:
                    child = convert(item, False)
                    # remove the useless empty spans
                    if child.name == 'span' and not child.attributes:
                        add_text(result, child.text)
                        result.children.extend(child.children)
                        add_text(result, child.tail)
                    else:
                        result.children.append(child)

            # fixes an output bug from pottymouth
            if len(result.children) == 1 and node.name == 'p' and \
               result.children[0].name == 'blockquote':
                result = result.children[0]

            # untrusted posts get nofollow on links
            if untrusted and result.name == 'a':
                result.attributes['rel'] = 'nofollow'

            return result
Example #6
0
 def begin_node(self, node, tagname, **more_attributes):
     zeml_node = Element(tagname)
     attributes = zeml_node.attributes
     for name, value in more_attributes.iteritems():
         attributes[name.lower()] = value
     if node is not None:
         classes = node.get('classes', [])
         if 'class' in attributes:
             classes.append(attributes['class'])
         if classes:
             attributes['class'] = ' '.join(classes)
         if node.has_key('ids') and node['ids']:
             # support only one ID
             attributes['id'] = node['ids'][0]
     zeml_node.parent = self.curnode
     self.curnode.children.append(zeml_node)
     self.curnode = zeml_node
Example #7
0
 def begin_node(self, node, tagname, **more_attributes):
     zeml_node = Element(tagname)
     attributes = zeml_node.attributes
     for name, value in more_attributes.iteritems():
         attributes[name.lower()] = value
     if node is not None:
         classes = node.get('classes', [])
         if 'class' in attributes:
             classes.append(attributes['class'])
         if classes:
             attributes['class'] = ' '.join(classes)
         if node.has_key('ids') and node['ids']:
             # support only one ID
             attributes['id'] = node['ids'][0]
     zeml_node.parent = self.curnode
     self.curnode.children.append(zeml_node)
     self.curnode = zeml_node
Example #8
0
 def parse(self, input_data, reason):
     intro_t, body_t = htmlize_markup(input_data, reason)
     intro = sanitize(parse_zeml(intro_t))
     body = sanitize(parse_zeml(body_t))
     # The following complicated procedure is required only because
     # Zine provides no way to cast RootElement objects (which `intro`
     # and `body` are) into Element objects (which `intro` needs to become)
     if intro_t:
         newintro = Element('intro')
         newintro.children.extend(intro.children)
         newintro.text = intro.text
         for child in newintro.children:
             child.parent = newintro
         body.children.insert(0, newintro)
         newintro.parent = body
         newintro.tail = body.text
         body.text = u''
     return body
Example #9
0
 def parse(self, input_data, reason):
     result = RootElement()
     stack = [result]
     env = {'parser': self, 'reason': reason}
     for kind, data, pos in creole_parser.generate(input_data, environ=env):
         if kind is MACRO_SIGNAL:
             stack[-1].children.append(data)
         elif kind == START:
             tag, attrs = data
             element = Element(tag)
             for key, value in attrs:
                 element.attributes[key] = value
             stack[-1].children.append(element)
             stack.append(element)
         elif kind == END:
             stack.pop()
         elif kind == TEXT:
             if stack[-1].children:
                 stack[-1].children[-1].tail += data
             else:
                 stack[-1].text += data
     return result
Example #10
0
 def parse(self, input_data, reason):
     result = RootElement()
     stack = [result]
     for kind, data, pos in creole_parser.generate(input_data):
         if kind == START:
             tag, attrs = data
             # tt is deprecated but creoleparser is using it
             if tag == 'tt':
                 tag = 'code'
             element = Element(tag)
             for key, value in attrs:
                 element.attributes[key] = value
             stack[-1].children.append(element)
             stack.append(element)
         elif kind == END:
             stack.pop()
         elif kind == TEXT:
             if stack[-1].children:
                 stack[-1].children[-1].tail += data
             else:
                 stack[-1].text += data
     return result
Example #11
0
 def parse(self, input_data, reason):
     result = RootElement()
     stack = [result]
     env = {'parser': self, 'reason': reason}
     for kind, data, pos in creole_parser.generate(input_data, environ=env):
         if kind is MACRO_SIGNAL:
             stack[-1].children.append(data)
         elif kind == START:
             tag, attrs = data
             element = Element(tag)
             for key, value in attrs:
                 element.attributes[key] = value
             stack[-1].children.append(element)
             stack.append(element)
         elif kind == END:
             stack.pop()
         elif kind == TEXT:
             if stack[-1].children:
                 stack[-1].children[-1].tail += data
             else:
                 stack[-1].text += data
     return result
Example #12
0
 def convert(node, is_root):
     if is_root:
         result = RootElement()
     else:
         result = Element(node.name)
     if node._attributes:
         result.attributes.update(node._attributes)
     for item in node:
         if isinstance(item, (str, unicode, Token)):
             text = self._to_text(item)
             if result.children:
                 result.children[-1].tail += text
             else:
                 result.text += text
         else:
             result.children.append(convert(item, False))
     return result