How to use the markdown.etree.Element function in Markdown

To help you get started, we’ve selected a few Markdown examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github andymckay / arecibo / listener / lib / markdown / inlinepatterns.py View on Github external
def handleMatch(self, m):
        el = markdown.etree.Element("img")
        src_parts = m.group(9).split()
        if src_parts:
            src = src_parts[0]
            if src[0] == "<" and src[-1] == ">":
                src = src[1:-1]
            el.set('src', self.sanitize_url(src))
        else:
            el.set('src', "")
        if len(src_parts) > 1:
            el.set('title', dequote(" ".join(src_parts[1:])))

        if markdown.ENABLE_ATTRIBUTES:
            truealt = handleAttributes(m.group(2), el)
        else:
            truealt = m.group(2)
github levskaya / OW / markdown_extensions / superscript.py View on Github external
def handleMatch(self, m):

        tagname = "sup" if m.group(2)=="^" else "sub"
        supr = m.group(3)
        text = supr

        el = markdown.etree.Element(tagname)
        el.text = markdown.AtomicString(text)
        return el
github lucuma / Clay / clay / libs / markdown / inlinepatterns.py View on Github external
def handleMatch(self, m):
        el = markdown.etree.Element("a")
        el.text = m.group(2)
        title = m.group(11)
        href = m.group(9)

        if href:
            if href[0] == "<":
                href = href[1:-1]
            el.set("href", self.sanitize_url(href.strip()))
        else:
            el.set("href", "")

        if title:
            title = dequote(title) #.replace('"', """)
            el.set("title", title)
        return el
github andymckay / arecibo / listener / lib / markdown / inlinepatterns.py View on Github external
def handleMatch (self, m):
        return markdown.etree.Element(self.tag)
github aleray / mdx_semanticwikilinks / mdx_semanticwikilinks.py View on Github external
def make_link(md, rel, target, label):
    a = etree.Element('a')
    a.set('href', target)
    if rel:
        a.set('rel', rel)
    a.text = label or target
    return a
github andymckay / arecibo / listener / lib / markdown / inlinepatterns.py View on Github external
def handleMatch(self, m):
        el = markdown.etree.Element(self.tag)
        el.text = m.group(3)
        return el
github dellsystem / wikinotes / mdx_wiki_footnotes.py View on Github external
def makeFootnotesDiv(self, root):
		""" Return div of footnotes as et Element. """

		if not self.footnotes.keys():
			return None

		div = etree.Element("div")
		div.set('class', 'footnote')
		hr = etree.SubElement(div, "hr")
		ol = etree.SubElement(div, "ol")

		for id in self.footnotes.keys():
			li = etree.SubElement(ol, "li")
			li.set("id", self.makeFootnoteId(id))
			self.parser.parseChunk(li, self.footnotes[id])
			backlink = etree.Element("a")
			backlink.set("href", "#" + self.makeFootnoteRefId(id))
			backlink.set("rev", "footnote")
			backlink.set("title", "Jump back to footnote %d in the text" % \
							(self.footnotes.index(id)+1))
			backlink.text = FN_BACKLINK_TEXT

			if li.getchildren():
				node = li[-1]
				if node.tag == "p":
					node.text = node.text + NBSP_PLACEHOLDER
					node.append(backlink)
				else:
					p = etree.SubElement(li, "p")
					p.append(backlink)
		return div
github airtonix / python-markdown-qrcode / mdx_qrcode / extension.py View on Github external
if match :

      pixel_size = 2
      qrcodeSourceData = str(match.group(1))
      qrCodeObject = QRCode(pixel_size, QRErrorCorrectLevel.L)
      qrCodeObject.addData( qrcodeSourceData )
      qrCodeObject.make()
      qrCodeImage = qrCodeObject.makeImage(
        pixel_size = pixel_size,
        dark_colour = "#000000"
      )
      qrCodeImage_File = StringIO.StringIO()
      qrCodeImage.save( qrCodeImage_File , format= 'PNG')

      element = markdown.etree.Element('img')
      element.set("src", "data:image/png;base64,%s" % b64encode( qrCodeImage_File.getvalue()) )
      element.set("title", "qrcode for : %s " % qrcodeSourceData )

      qrCodeImage_File.close()

      return element
    else :
      return ""
github tornadoweb / tornado / website / markdown / extensions / toc.py View on Github external
# Do not override pre-existing ids 
                if not "id" in c.attrib:
                    id = self.config["slugify"][0](c.text)
                    if id in used_ids:
                        ctr = 1
                        while "%s_%d" % (id, ctr) in used_ids:
                            ctr += 1
                        id = "%s_%d" % (id, ctr)
                    used_ids.append(id)
                    c.attrib["id"] = id
                else:
                    id = c.attrib["id"]

                # List item link, to be inserted into the toc div
                last_li = etree.Element("li")
                link = etree.SubElement(last_li, "a")
                link.text = c.text
                link.attrib["href"] = '#' + id

                if int(self.config["anchorlink"][0]):
                    anchor = etree.SubElement(c, "a")
                    anchor.text = c.text
                    anchor.attrib["href"] = "#" + id
                    anchor.attrib["class"] = "toclink"
                    c.text = ""

                list_stack[-1].append(last_li)