summaryrefslogtreecommitdiff
path: root/pygments/formatters/html.py
diff options
context:
space:
mode:
Diffstat (limited to 'pygments/formatters/html.py')
-rw-r--r--pygments/formatters/html.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/pygments/formatters/html.py b/pygments/formatters/html.py
index b03a4bd5..12f2e83e 100644
--- a/pygments/formatters/html.py
+++ b/pygments/formatters/html.py
@@ -321,6 +321,12 @@ class HtmlFormatter(Formatter):
.. versionadded:: 1.6
+ `filename`
+ A string used to generate a filename when rendering <pre> blocks,
+ for example if displaying source code.
+
+ .. versionadded:: 2.1
+
**Subclassing the HTML formatter**
@@ -388,6 +394,7 @@ class HtmlFormatter(Formatter):
self.noclobber_cssfile = get_bool_opt(options, 'noclobber_cssfile', False)
self.tagsfile = self._decodeifneeded(options.get('tagsfile', ''))
self.tagurlformat = self._decodeifneeded(options.get('tagurlformat', ''))
+ self.filename = self._decodeifneeded(options.get('filename', ''))
if self.tagsfile:
if not ctags:
@@ -692,6 +699,9 @@ class HtmlFormatter(Formatter):
style.append('line-height: 125%')
style = '; '.join(style)
+ if self.filename:
+ yield 0, ('<span class="filename">' + self.filename + '</span>')
+
yield 0, ('<pre' + (style and ' style="%s"' % style) + '>')
for tup in inner:
yield tup