Created
June 17, 2012 20:36
-
-
Save icholy/2945676 to your computer and use it in GitHub Desktop.
pygments html formatter with line wrapping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
pygments.formatters.htmlline | |
~~~~~~~~~~~~~~~~~~~~~~~~ | |
Formatter for HTML output which wraps each line in a span. | |
""" | |
__all__ = ['HtmlLineFormatter'] | |
from pygments.formatters import HtmlFormatter | |
class HtmlLineFormatter(HtmlFormatter): | |
""" | |
Output as html and wrap each line in a span | |
""" | |
name = 'Html wrap lines' | |
aliases = ['htmlline'] | |
def wrap(self, source, outfile): | |
return self._wrap_div(self._wrap_pre(self._wrap_lines(source))) | |
def _wrap_lines(self, source): | |
i = self.linenostart | |
for t, line in source: | |
if t == 1: | |
line = '<span id="LC%d">%s</span>' % (i, line) | |
i += 1 | |
yield t, line |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment