How to use the markdown.util.etree 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 Python-Markdown / markdown / tests / test_apis.py View on Github external
def setUp(self):
        # Create comment node
        self.comment = markdown.util.etree.Comment('foo')
        if hasattr(markdown.util.etree, 'test_comment'):
            self.test_comment = markdown.util.etree.test_comment
        else:
            self.test_comment = markdown.util.etree.Comment
github firm1 / zest-writer / src / markdown / extensions / urlize.py View on Github external
def handleMatch(self, m):
        url = m.group(3)

        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.util.etree.Element("a")
        el.set('href', url)
        el.text = markdown.util.AtomicString(text)
        return el
github szaghi / MaTiSSe / release / MaTiSSe-v0.0.1 / matisse / utils / mdx_mathjax.py View on Github external
def handleMatch(self, m):
    node = etree.Element(None)
    text = ''
    for group in self.groups:
      text += m.group(group)
    node.text = AtomicString(text)
    return node
github jpfleury / gedit-markdown / python-markdown / python3 / extensions / footnotes.py View on Github external
def handleMatch(self, m):
        id = m.group(2)
        if id in list(self.footnotes.footnotes.keys()):
            sup = etree.Element("sup")
            a = etree.SubElement(sup, "a")
            sup.set('id', self.footnotes.makeFootnoteRefId(id))
            a.set('href', '#' + self.footnotes.makeFootnoteId(id))
            if self.footnotes.md.output_format not in ['html5', 'xhtml5']:
                a.set('rel', 'footnote') # invalid in HTML5
            a.set('class', 'footnote-ref')
            a.text = str(self.footnotes.footnotes.index(id) + 1)
            return sup
        else:
            return None
github RadhikaG / markdown-magic / magic / magic.py View on Github external
def handleMatch(self, m):
        """
        Handles user input into [magic] tag, processes it,
        and inserts the returned URL into an <img> tag
        through a Python ElementTree <img> Element.
        """
        userStr = m.group(3)
        # print(userStr)
        imgURL = processString(userStr)
        # print(imgURL)
        el = etree.Element('img')
        # Sets imgURL to 'src' attribute of <img> tag element
        el.set('src', imgURL)       
        el.set('alt', userStr)
        el.set('title', userStr)
        return el
github zulip / zulip / zerver / lib / bugdown / __init__.py View on Github external
def twitter_link(self, url: str) -> Optional[Element]:
        tweet_id = get_tweet_id(url)

        if tweet_id is None:
            return None

        try:
            res = fetch_tweet_data(tweet_id)
            if res is None:
                return None
            user = res['user']  # type: Dict[str, Any]
            tweet = markdown.util.etree.Element("div")
            tweet.set("class", "twitter-tweet")
            img_a = markdown.util.etree.SubElement(tweet, 'a')
            img_a.set("href", url)
            img_a.set("target", "_blank")
            profile_img = markdown.util.etree.SubElement(img_a, 'img')
            profile_img.set('class', 'twitter-avatar')
            # For some reason, for, e.g. tweet 285072525413724161,
            # python-twitter does not give us a
            # profile_image_url_https, but instead puts that URL in
            # profile_image_url. So use _https if available, but fall
            # back gracefully.
            image_url = user.get('profile_image_url_https', user['profile_image_url'])
            profile_img.set('src', image_url)

            text = html.unescape(res['full_text'])
            urls = res.get('urls', [])
github niwinz / Green-Mine / src / greenmine / scrum / templatetags / plugin_wikilinks.py View on Github external
def handleMatch(self, m):
        link, title = m.group(2).strip(), m.group(3).strip()

        if link and title:
            base_url, end_url, html_class = self._getMeta()
            url = self.config['build_url'](title, base_url, end_url)
            
            a = markdown.util.etree.Element('a')
            a.text = title
            a.set('href', link)
            
            if html_class:
                a.set('class', html_class)
        else:
            a = ''

        return a
github tdf / odftoolkit / src / site / cms / build / mdx_elementid.py View on Github external
def run(self, root):
        '''
        Find and remove all id specs references from the text,
        and add them as the id attribute of the element.
        
        ROOT is div#section_content.
        '''
        if isBlockLevel(root.tag) and root.tag not in ['code', 'pre']:
            self._parseID(root)
            child = etree.Element("style")
            for k,v in {
                          'type': 'text/css',
                       }.iteritems():
                child.set(k, v)
            # Note upstream doc bug: it's not called markdown.AtomicString().
            self.css += 'dt:hover > .elementid-permalink { visibility: visible }'
            child.text = markdown.util.AtomicString(self.css)
            root.insert(0, child)
            self.css = CSS
            self.seen_block_tag = {}
            # child.tail = root.text; root.text = None;
        return root
github bollwyvl / TangleDown / tangledown / apps / tangle / markdown / mdx_tangle.py View on Github external
def handleMatch(self, m):
        kwargs = {}
        children = []
        text = ""
        bits = m.groupdict()
        kwargs['var'] = bits['var']
        for op_text in [bits['op0'], bits['op1']]:
            op = markdown.util.etree.Element('span')
            op.text = op_text
            children.append(op)
        kwargs = bits
        return tk_span('TKToggle TKSwitch', children=children, ignore=['op0', 'op1'], **kwargs)