diff options
author | Anteru <bitbucket@ca.sh13.net> | 2019-05-09 05:06:00 +0000 |
---|---|---|
committer | Anteru <bitbucket@ca.sh13.net> | 2019-05-09 05:06:00 +0000 |
commit | dba5f50da1218be160cf0de5d07c4febf28eafe2 (patch) | |
tree | ecde56931e857612345e82146081d945851b6153 /pygments/formatters/html.py | |
parent | 8f733ca887f216cdcf1b1e5f9b70954811bcfc17 (diff) | |
parent | 2461ec34c6aac22c0600b3e0e32a9f802765e9de (diff) | |
download | pygments-dba5f50da1218be160cf0de5d07c4febf28eafe2.tar.gz |
Merged in SylvainCorlay/pygments-main/css-variables (pull request #814)
Allow for CSS variable in pygments stylesheets
Approved-by: Anteru <bitbucket@ca.sh13.net>
Diffstat (limited to 'pygments/formatters/html.py')
-rw-r--r-- | pygments/formatters/html.py | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/pygments/formatters/html.py b/pygments/formatters/html.py index bbddf507..d65c09ce 100644 --- a/pygments/formatters/html.py +++ b/pygments/formatters/html.py @@ -5,7 +5,7 @@ Formatter for HTML output. - :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ @@ -60,6 +60,11 @@ def _get_ttype_class(ttype): CSSFILE_TEMPLATE = '''\ +/* +generated by Pygments <http://pygments.org> +Copyright 2006-2019 by the Pygments team. +Licensed under the BSD license, see LICENSE for details. +*/ td.linenos { background-color: #f0f0f0; padding-right: 10px; } span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; } pre { line-height: 125%%; } @@ -69,7 +74,11 @@ pre { line-height: 125%%; } DOC_HEADER = '''\ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> - +<!-- +generated by Pygments <http://pygments.org> +Copyright 2006-2019 by the Pygments team. +Licensed under the BSD license, see LICENSE for details. +--> <html> <head> <title>%(title)s</title> @@ -327,11 +336,17 @@ class HtmlFormatter(Formatter): .. versionadded:: 1.6 `filename` - A string used to generate a filename when rendering <pre> blocks, + A string used to generate a filename when rendering ``<pre>`` blocks, for example if displaying source code. .. versionadded:: 2.1 + `wrapcode` + Wrap the code inside ``<pre>`` blocks using ``<code>``, as recommended + by the HTML5 specification. + + .. versionadded:: 2.4 + **Subclassing the HTML formatter** @@ -400,6 +415,7 @@ class HtmlFormatter(Formatter): self.tagsfile = self._decodeifneeded(options.get('tagsfile', '')) self.tagurlformat = self._decodeifneeded(options.get('tagurlformat', '')) self.filename = self._decodeifneeded(options.get('filename', '')) + self.wrapcode = get_bool_opt(options, 'wrapcode', False) if self.tagsfile: if not ctags: @@ -713,6 +729,12 @@ class HtmlFormatter(Formatter): yield tup yield 0, '</pre>' + def _wrap_code(self, inner): + yield 0, '<code>' + for tup in inner: + yield tup + yield 0, '</code>' + def _format_lines(self, tokensource): """ Just format the tokens, without any wrapping tags. @@ -819,7 +841,10 @@ class HtmlFormatter(Formatter): individual lines, in custom generators. See docstring for `format`. Can be overridden. """ - return self._wrap_div(self._wrap_pre(source)) + if self.wrapcode: + return self._wrap_div(self._wrap_pre(self._wrap_code(source))) + else: + return self._wrap_div(self._wrap_pre(source)) def format_unencoded(self, tokensource, outfile): """ |