def run(self, parent, blocks):
     sibling = self.lastChild(parent)
     block = blocks.pop(0)
     theRest = ''
     if sibling and sibling.tag == "pre" and len(sibling) \
                 and sibling[0].tag == "code":
         # The previous block was a code block. As blank lines do not start
         # new code blocks, append this block to the previous, adding back
         # linebreaks removed from the split into a list.
         code = sibling[0]
         block, theRest = self.detab(block)
         code.text = markdown.AtomicString('%s\n%s\n' %
                                           (code.text, block.rstrip()))
     else:
         # This is a new codeblock. Create the elements and insert text.
         pre = markdown.etree.SubElement(parent, 'pre')
         code = markdown.etree.SubElement(pre, 'code')
         block, theRest = self.detab(block)
         code.text = markdown.AtomicString('%s\n' % block.rstrip())
         if code.text.startswith('.exec\n'):
             pre.set('class', 'exec')
             code.text = code.text.split(".exec\n", 1)[1]
     if theRest:
         # This block contained unindented line(s) after the first indented
         # line. Insert these lines as the first block of the master blocks
         # list for future processing.
         blocks.insert(0, theRest)
示例#2
0
 def handleMatch(self, m):
     subsc = m.group(3)
     
     text = subsc
     
     el = markdown.etree.Element("sub")
     el.text = markdown.AtomicString(text)
     return el
 def run(self, parent, blocks):
     block = blocks.pop(0)
     m = self.RE.match(block)
     if m:
         # Add remaining line to master blocks for later.
         blocks.insert(0, block[m.end():])
         sibling = self.lastChild(parent)
         if sibling and sibling.tag == 'pre' and sibling[0] and \
                 sibling[0].tag == 'code':
             # Last block is a codeblock. Append to preserve whitespace.
             sibling[0].text = markdown.AtomicString('%s/n/n/n' % sibling[0].text )
示例#4
0
    def handleMatch(self, m):

        text = m.group(3)

        if markdown.version_info < (2, 1, 0):
            el = markdown.etree.Element("sub")
            el.text = markdown.AtomicString(text)
        else:
            el = markdown.util.etree.Element("sub")
            el.text = markdown.util.AtomicString(text)

        return el
示例#5
0
 def handleMatch(self, m):
     if m.group(2).strip():
         base_url, end_url, html_class = self._getMeta()
         label = m.group(2).strip()
         url = '%s%s%s' % (base_url, label.replace(' ', '_'), end_url)
         a = markdown.etree.Element('a')
         a.text = markdown.AtomicString(label)
         a.set('href', url)
         if html_class:
             a.set('class', html_class)
     else:
         a = ''
     return a
示例#6
0
文件: urlize.py 项目: ng/tbonline
    def handleMatch(self, m):
        url = m.group(2)

        if url.startswith('<'):
            url = url[1:-1]

        text = url

        if not url.split('://')[0] in ('http', 'https', 'ftp'):
            if '@' in url and not '/' in url:
                url = 'mailto:' + url
            else:
                url = 'http://' + url

        el = markdown.etree.Element("a")
        el.set('href', url)
        el.text = markdown.AtomicString(text)
        return el
示例#7
0
    def handleMatch(self, m):
        url = m.group(2)

        text = url

        # If no http(s) prefix, assume http
        if re.match("www", url, re.I):
            url = "http://" + url

        if re.search(r"\.(jpg|jpeg|gif|png)$", url, flags=re.I):
            el = markdown.etree.Element("img")
            el.set("src", url)
            el.set("class", "autolink")
        else:
            el = markdown.etree.Element("a")
            el.set("href", url)
            el.set("class", "autolink")
            el.text = markdown.AtomicString(text)
        return el
示例#8
0
    def handleMatch(self, m):
        el = markdown.etree.Element('a')
        email = m.group(2)
        if email.startswith("mailto:"):
            email = email[len("mailto:"):]

        def codepoint2name(code):
            """Return entity definition by code, or the code if not defined."""
            entity = htmlentitydefs.codepoint2name.get(code)
            if entity:
                return "%s%s;" % (markdown.AMP_SUBSTITUTE, entity)
            else:
                return "%s#%d;" % (markdown.AMP_SUBSTITUTE, code)

        letters = [codepoint2name(ord(letter)) for letter in email]
        el.text = markdown.AtomicString(''.join(letters))

        mailto = "mailto:" + email
        mailto = "".join([markdown.AMP_SUBSTITUTE + '#%d;' %
                          ord(letter) for letter in mailto])
        el.set('href', mailto)
        return el
示例#9
0
    def __processCodeBlock(self, parentElem, lines, inList):
        """
        Given a list of document lines starting with a code block
        finds the end of the block, puts it into the ElementTree verbatim
        wrapped in ("<pre><code>") and recursively processes the
        the remainder of the text file.

        Keyword arguments:

        * parentElem: ElementTree element to which the content will be added
        * lines: a list of lines
        * inList: a level

        Returns: None

        """
        detabbed, theRest = self.detectTabbed(lines)
        pre = etree.SubElement(parentElem, "pre")
        code = etree.SubElement(pre, "code")
        text = "\n".join(detabbed).rstrip() + "\n"
        code.text = markdown.AtomicString(text)
        self.parseChunk(parentElem, theRest, inList)
示例#10
0
 def handleMatch(self, m):
     url = m.group(2)
     
     if url.startswith('<'):
         url = url[1:-1]
         
     text = url
     
     if not url.split('://')[0] in ('http','https','ftp'):
         if '@' in url and not '/' in url:
             url = 'mailto:' + url
         else:
             url = 'http://' + url
     mime_type = guess_type(url)
     if mime_type[0] and 'image' in mime_type[0]:
         el = etree.Element("img")
         el.set('src', process_image(url))
     else:
         el = etree.Element("a")
         el.set('href', url)
         el.text = markdown.AtomicString(text)
     return el
示例#11
0
 def handleMatch(self, m):
     el = markdown.etree.Element("a")
     el.set('href', url_for('.index') + '?search=%23' + m.group(2))
     el.text = '#' + markdown.AtomicString(m.group(2))
     return el
示例#12
0
 def handleMatch(self, m):
     return markdown.AtomicString(m.group(2))
示例#13
0
 def handleMatch(self, m):
     el = markdown.etree.Element("a")
     el.set('href', m.group(2))
     el.text = markdown.AtomicString(m.group(2))
     return el
示例#14
0
 def handleMatch(self, m):
     el = markdown.etree.Element(self.tag)
     el.text = markdown.AtomicString(m.group(3).strip())
     return el