Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>> s = """
- [code]
- for i in var:
- print(var[i])
- [/code]
- """
- from pygments import highlight
- from pygments.lexers import PythonLexer
- from pygments.formatters import HtmlFormatter
- class PygmentsBBCodeTag(BBCodeTag):
- name = 'code'
- class Options:
- strip = False
- replace_links = False
- render_embedded = False
- transform_newlines = False
- escape_html = False
- def render(self, value, option=None, parent=None):
- print(value)
- return highlight(value, PythonLexer(), HtmlFormatter())
- tag_pool.register_tag(PygmentsBBCodeTag)
- if previous_tag_options.end_tag_closes:
- opening_tags.pop()
- if not tag_options.render_embedded:
- opening_tags = []
- elif previous_tag_options.end_tag_closes:
- opening_tags.pop()
Add Comment
Please, Sign In to add comment