How to use the markdown.util.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 zestedesavoir / zds-site / zds / utils / templatetags / mkd_ext / smartLegend.py View on Github external
while Restart:
                Restart = False
                i=0
                for nelem in elem:
                    if nelem.tag in self.configs["PARENTS"] and nelem not in elemsToInspect:
                        elemsToInspect.append(nelem)
                    #Auto Legend for image
                    if nelem.tag == 'p'  and len(list(nelem.itertext())) == 0 :
                        lelems = list(nelem.iter())
                        if     (len(lelems) == 1 or (len(lelems)==2 and lelems[0] is nelem)) \
                                 and lelems[-1].tag == "img" \
                                 and lelems[-1].attrib["alt"] != "" \
                                 and not (lelems[-1].attrib["src"] in self.configs["IGNORING_IMG"]):
                            oldImg = lelems[-1]
                            nelem.remove(oldImg)
                            nFig = util.etree.Element("figure")
                            nFigCaption = util.etree.Element("figurecaption")
                            nFigCaption.text = oldImg.attrib["alt"]
                            oldImg.attrib["alt"]=""
                            nFig.append(oldImg)
                            nFig.append(nFigCaption)
                            nelem.insert(i-1, nFig)
                            Restart = True
                            break
                    i+=1
        return root
github lucuma / Clay / clay / libs / md_toc.py View on Github external
# Do not override pre-existing ids 
                    if not "id" in c.attrib:
                        id = unique(self.config["slugify"](text, '-'), used_ids)
                        c.attrib["id"] = id
                    else:
                        id = c.attrib["id"]

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

                    if self.config["anchorlink"]:
                        anchor = etree.Element("a")
                        anchor.text = c.text
                        anchor.attrib["href"] = "#" + id
                        anchor.attrib["class"] = "toclink"
                        c.text = ""
                        for elem in c.getchildren():
                            anchor.append(elem)
                            c.remove(elem)
                        c.append(anchor)

                    list_stack[-1].append(last_li)
                except IndexError:
                    # We have bad ordering of headers. Just move on.
                    pass
        
        # searialize and attach to markdown instance.
        ul = div.find('ul')
github jpfleury / gedit-markdown / python-markdown / python3 / extensions / footnotes.py View on Github external
def makeFootnotesDiv(self, root):
        """ Return div of footnotes as et Element. """

        if not list(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 list(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))
            if self.md.output_format not in ['html5', 'xhtml5']:
                backlink.set("rev", "footnote") # Invalid in HTML5
            backlink.set("class", "footnote-backref")
            backlink.set("title", "Jump back to footnote %d in the text" % \
                            (self.footnotes.index(id)+1))
            backlink.text = FN_BACKLINK_TEXT
github LMFDB / lmfdb / lmfdb / knowledge / main.py View on Github external
def handleMatch(self, m):
        el = markdown.util.etree.Element("a")
        el.set('href', url_for('knowledge.index') + '?search=%23' + m.group(2))
        el.text = '#' + m.group(2)
        return el
github zestedesavoir / zds-site / zds / utils / templatetags / mkd_ext / mathjax.py View on Github external
def handleMatch(self, m):
        if m.group(2) == "$" and "\n" in m.group(3):
            node = markdown.util.etree.Element('span')
            node.text = "\\" + m.group(2) + m.group(3) + "\\" + m.group(2)
        else:
            node = markdown.util.etree.Element('mathjax')
            node.text = markdown.util.AtomicString(m.group(2) + m.group(3) + m.group(2))
        return node
github zulip / zulip / zerver / lib / bugdown / __init__.py View on Github external
def handleMatch(self, match: Match[str]) -> Optional[Element]:
        img = markdown.util.etree.Element('img')
        email_address = match.group('email')
        email = email_address.strip().lower()
        profile_id = None

        db_data = self.markdown.zulip_db_data
        if db_data is not None:
            user_dict = db_data['email_info'].get(email)
            if user_dict is not None:
                profile_id = user_dict['id']

        img.set('class', 'message_body_gravatar')
        img.set('src', '/avatar/{0}?s=30'.format(profile_id or email))
        img.set('title', email)
        img.set('alt', email)
        return img
github zulip / zulip / zerver / lib / bugdown / __init__.py View on Github external
def make_emoji(emoji_name, src, display_string):
    elt = markdown.util.etree.Element('img')
    elt.set('src', src)
    elt.set('class', 'emoji')
    elt.set("alt", display_string)
    elt.set("title", display_string)
    return elt
github zestedesavoir / zds-site / zds / utils / templatetags / mkd_ext / video.py View on Github external
def flash_object(url, width, height):
    obj = etree.Element('object')
    obj.set('type', 'application/x-shockwave-flash')
    obj.set('width', width)
    obj.set('height', height)
    obj.set('data', url)
    param = etree.Element('param')
    param.set('name', 'movie')
    param.set('value', url)
    obj.append(param)
    param = etree.Element('param')
    param.set('name', 'allowFullScreen')
    param.set('value', 'true')
    obj.append(param)
    return obj
github F0RE1GNERS / eoj3 / utils / markdown3 / mdx_math.py View on Github external
def handle_match(m):
      node = etree.Element('script')
      node.set('type', 'math/tex; mode=display')
      if '\\begin' in m.group(2):
        node.text = AtomicString(''.join(m.group(2, 4, 5)))
        return _wrap_node(node, ''.join(m.group(1, 2, 4, 5, 6)), 'div')
      else:
        node.text = AtomicString(m.group(3))
        return _wrap_node(node, ''.join(m.group(2, 3, 4)), 'div')
github szaghi / MaTiSSe / src / main / python / matisse / mdx_mathjax.py View on Github external
def handleMatch(self, m):
    node = markdown.util.etree.Element('mathjax')
    node.text = markdown.util.AtomicString(m.group(2) + m.group(3) + m.group(2))
    return node