diff options
author | gbrandl <devnull@localhost> | 2009-03-05 11:08:21 +0100 |
---|---|---|
committer | gbrandl <devnull@localhost> | 2009-03-05 11:08:21 +0100 |
commit | a2763205e2333ec2f98f8de162246fb0b114f3f2 (patch) | |
tree | dc9b43df8fef8b9f0e3dc9e5badc72289cee79fa /pygments/formatters/html.py | |
parent | de3b7765ba0c934fe4da32353703cc941f6540a2 (diff) | |
download | pygments-a2763205e2333ec2f98f8de162246fb0b114f3f2.tar.gz |
Add "noclobber_cssfile" (#396) option to HTML formatter.
Diffstat (limited to 'pygments/formatters/html.py')
-rw-r--r-- | pygments/formatters/html.py | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/pygments/formatters/html.py b/pygments/formatters/html.py index 6e263a12..b99fdea2 100644 --- a/pygments/formatters/html.py +++ b/pygments/formatters/html.py @@ -186,7 +186,9 @@ class HtmlFormatter(Formatter): `style` The style to use, can be a string or a Style subclass (default: - ``'default'``). + ``'default'``). This option has no effect if the `cssfile` + and `noclobber_cssfile` option are given and the file specified in + `cssfile` exists. `noclasses` If set to true, token ``<span>`` tags will not use CSS classes, but @@ -223,6 +225,12 @@ class HtmlFormatter(Formatter): file's path, if the latter can be found. The stylesheet is then written to this file instead of the HTML file. *New in Pygments 0.6.* + `noclobber_cssfile' + If `cssfile` is given and the specified file exists, the css file will + not be overwritten. This allows the use of the `full` option in + combination with a user specified css file. Default is ``False``. + *New in Pygments 1.1.* + `linenos` If set to ``'table'``, output line numbers as a table with two cells, one containing the line numbers, the other the whole code. This is @@ -342,6 +350,8 @@ class HtmlFormatter(Formatter): self.cssstyles = self._encodeifneeded(options.get('cssstyles', '')) self.prestyles = self._encodeifneeded(options.get('prestyles', '')) self.cssfile = self._encodeifneeded(options.get('cssfile', '')) + self.noclobber_cssfile = get_bool_opt(options, 'noclobber_cssfile', False) + linenos = options.get('linenos', False) if linenos == 'inline': self.linenos = 2 @@ -460,12 +470,13 @@ class HtmlFormatter(Formatter): print >>sys.stderr, 'Note: Cannot determine output file name, ' \ 'using current directory as base for the CSS file name' cssfilename = self.cssfile - # write CSS file + # write CSS file only if noclobber_cssfile isn't given as an option. try: - cf = open(cssfilename, "w") - cf.write(CSSFILE_TEMPLATE % - {'styledefs': self.get_style_defs('body')}) - cf.close() + if not os.path.exists(cssfilename) or not self.noclobber_cssfile: + cf = open(cssfilename, "w") + cf.write(CSSFILE_TEMPLATE % + {'styledefs': self.get_style_defs('body')}) + cf.close() except IOError, err: err.strerror = 'Error writing CSS file: ' + err.strerror raise |