How to use the mistune.escape function in mistune

To help you get started, we’ve selected a few mistune 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 nitely / Spirit / spirit / core / utils / markdown / parsers / poll.py View on Github external
def _clean_choices(self):
        choices_raw = self.data['choices']
        choices = []

        for choice in choices_raw.splitlines()[:self.choices_limit + 1]:
            number, description = choice.split('.', 1)
            description = mistune.escape(description.strip(), quote=True)
            choices.append({
                'number': int(number),
                'description': description[:self._field_description.max_length]
                # 'poll_name': ...  # Added in clean() method
            })

        self.cleaned_data['choices'] = choices
github xalanq / ITree / imarkdown.py View on Github external
word = word.split(':', 1)
				if len(word) == 1:
					word = word[0].split('x', 1)
					if len(word) == 2:
						if word[0].isdigit() and word[1].isdigit():
							width = word[0] + 'px'
							height = word[1] + 'px'
				elif len(word) == 2:
					name, value = word
					if name == 'height':
						height = value
					if name == 'width':
						width = value
		src = mistune.escape(src.replace('"', '"')) if src else ''
		text = mistune.escape(text) if text else ''
		title = mistune.escape(title.replace('"', '"')) if title else ''
		cmd = ' src="#" link="{}"'.format(src)
		cmd += ' alt="{}"'.format(text) if text else ''
		cmd += ' title="{}"'.format(title) if title else ''
		cmd += ' width="{}"'.format(width) if width else ''
		cmd += ' height="{}"'.format(height) if height else ''
		# print(cmd)
		# return '<img>'.format(cmd)
                # if compile QtWebKit with Qt5, use assignTo; Otherwise use assignToHTMLImageElement
		# return '<img>'.format(cmd)
		return '<img>'.format(cmd)
github mrjbq7 / ta-lib / docs / generate_html_pages.py View on Github external
def block_code(self, code, lang=None):
            if not lang:
                return '\n<pre><code>%s</code></pre>\n' % mistune.escape(code)
            lexer = get_lexer_by_name(lang, stripall=True)
            formatter = HtmlFormatter(classprefix='highlight ')
            return highlight(code, lexer, formatter)
    return mistune.Markdown(renderer=PygmentsHighlighter())
github liangliangyy / DjangoBlog / DjangoBlog / utils.py View on Github external
if not lang:
        text = text.strip()
        return u'<pre><code>%s</code></pre>\n' % mistune.escape(text)

    try:
        lexer = get_lexer_by_name(lang, stripall=True)
        formatter = html.HtmlFormatter(
            noclasses=inlinestyles, linenos=linenos
        )
        code = highlight(text, lexer, formatter)
        if linenos:
            return '<div class="highlight">%s</div>\n' % code
        return code
    except:
        return '<pre class="%s"><code>%s</code></pre>\n' % (
            lang, mistune.escape(text)
        )
github liangliangyy / DjangoBlog / DjangoBlog / utils.py View on Github external
def autolink(self, link, is_email=False):
        text = link = escape(link)

        if is_email:
            link = 'mailto:%s' % link
        if not link:
            link = "#"
        site = get_current_site()
        nofollow = "" if link.find(site.domain) &gt; 0 else "rel='nofollow'"
        return '<a href="%s">%s</a>' % (link, nofollow, text)
github crossbario / crossbar / docs-old / markdown.py View on Github external
def block_code(self, code, lang):
      if self.debug:
         print("CODE", lang, len(code))

      lexer = None
      if lang:
         try:
            lexer = get_lexer_by_name(lang, stripall = True)
         except:
            print("failed to load lexer for language '{}'".format(lang))

      if not lexer:
         return "\n<pre><code>{}</code></pre>\n".format(mistune.escape(code))

      formatter = HtmlFormatter()
      return '\n<div class="highlight-code">{}</div>\n'.format(highlight(code, lexer, formatter))
github quokkaproject / quokka / quokka / core / content / parsers.py View on Github external
def block_code(text, lang, inlinestyles=False, linenos=False):
    if not lang:
        text = text.strip()
        return u'<pre><code>%s</code></pre>\n' % mistune.escape(text)

    try:
        lexer = get_lexer_by_name(lang, stripall=True)
        formatter = html.HtmlFormatter(
            noclasses=inlinestyles, linenos=linenos
        )
        code = highlight(text, lexer, formatter)
        if linenos:
            return '<div class="highlight-wrapper">%s</div>\n' % code
        return code
    except BaseException:
        return '<pre class="%s"><code>%s</code></pre>\n' % (
            lang, mistune.escape(text)
        )
github 30-seconds / 30-seconds-of-python / website / main.py View on Github external
def block_code(self, code, lang):
        if not lang:
            return f'\n<pre>{mistune.escape(code.strip())}</pre>\n'
        else:
            return f'\n<pre class="language-{lang}">{mistune.escape(code.strip())}</pre>\n'
github naspeh / pusto / pusto.py View on Github external
def block_code(self, code, lang):
            if not lang:
                return '\n<pre><code>%s</code></pre>\n' % escape(code)
            lexer = get_lexer_by_name(lang, stripall=True, startinline=True)
            formatter = HtmlFormatter()
            return highlight(code, lexer, formatter)