Guest User

Untitled

a guest
Jun 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. >>> s = """
  2. [code]
  3. for i in var:
  4. print(var[i])
  5. [/code]
  6. """
  7.  
  8. from pygments import highlight
  9. from pygments.lexers import PythonLexer
  10. from pygments.formatters import HtmlFormatter
  11.  
  12. class PygmentsBBCodeTag(BBCodeTag):
  13. name = 'code'
  14.  
  15. class Options:
  16. strip = False
  17. replace_links = False
  18. render_embedded = False
  19. transform_newlines = False
  20. escape_html = False
  21.  
  22. def render(self, value, option=None, parent=None):
  23. print(value)
  24. return highlight(value, PythonLexer(), HtmlFormatter())
  25.  
  26. tag_pool.register_tag(PygmentsBBCodeTag)
  27.  
  28. if previous_tag_options.end_tag_closes:
  29. opening_tags.pop()
  30.  
  31. if not tag_options.render_embedded:
  32. opening_tags = []
  33. elif previous_tag_options.end_tag_closes:
  34. opening_tags.pop()
Add Comment
Please, Sign In to add comment