Example #1
0
 def render_block_code(self, token):
     template = '<pre><code{attr}>{inner}</code></pre>'
     if token.language:
         attr = ' class="{}"'.format('language-{}'.format(self.escape_html(token.language)))
     else:
         attr = ''
     inner = html.escape(token.children[0].content)
     return template.format(attr=attr, inner=inner)
 def render_block_code(self, token):
     el_pre = etree.Element('pre')
     el_code = etree.SubElement(el_pre, 'code')
     if token.language:
         el_code.set('class', 'language-{}'.format(self.escape_html(token.language)))
     # to comply with the format using in PythonMarkdown.
     # or it may break in plugins like codehilite!!
     code_text = (html.escape(token.children[0].content)
         .replace('&#x27;', "'")
         # FIXME: breaks commonmark test suite #176
         .replace('&quot;', '"'))
     # protect inside content from being interpreted
     el_code.text = AtomicString(code_text)
     return el_pre
Example #3
0
 def render_inline_code(self, token):
     template = "<code>{}</code>"
     inner = html.escape(token.children[0].content)
     return template.format(inner)
Example #4
0
 def escape_url(raw):
     """
     Escape urls to prevent code injection craziness. (Hopefully.)
     """
     return html.escape(quote(html.unescape(raw), safe="/#:()*?=%@+,&"))
Example #5
0
 def escape_html(raw):
     return html.escape(html.unescape(raw)).replace("&#x27;", "'")
 def render_inline_code(self, token):
     el = etree.Element('code')
     el.text = AtomicString(html.escape(token.children[0].content)
         .replace('&#x27;', "'"))
     return el