|
From: <mi...@us...> - 2012-01-19 11:55:33
|
Revision: 7317
http://docutils.svn.sourceforge.net/docutils/?rev=7317&view=rev
Author: milde
Date: 2012-01-19 11:55:26 +0000 (Thu, 19 Jan 2012)
Log Message:
-----------
Fix handling of missing stylesheets. Updated and simplied tests.
Missing stylesheets are no reason to abort conversion:
Report as error and insert a comment in the output doc.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/docutils/writers/__init__.py
trunk/docutils/docutils/writers/html4css1/__init__.py
trunk/docutils/docutils/writers/latex2e/__init__.py
trunk/docutils/test/test_writers/test_latex2e.py
Added Paths:
-----------
trunk/docutils/test/functional/expected/stylesheet_path_html4css1.html
trunk/docutils/test/functional/tests/stylesheet_path_html4css1.py
Removed Paths:
-------------
trunk/docutils/test/data/hidden.css
trunk/docutils/test/data/spam.sty
trunk/docutils/test/functional/expected/multistyle_path_embed_rst_html4css1.html
trunk/docutils/test/functional/expected/multistyle_path_rst_html4css1.html
trunk/docutils/test/functional/expected/multistyle_rst_html4css1.html
trunk/docutils/test/functional/tests/multistyle_path_embedd_rst_html4css1.py
trunk/docutils/test/functional/tests/multistyle_path_rst_html4css1.py
trunk/docutils/test/functional/tests/multistyle_rst_html4css1.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2012-01-19 11:31:58 UTC (rev 7316)
+++ trunk/docutils/HISTORY.txt 2012-01-19 11:55:26 UTC (rev 7317)
@@ -13,17 +13,15 @@
.. contents::
-
Changes Since 0.8.1
===================
* General:
- - reStructuredText "code" role and directive with syntax highlighting
- by Pygments_.
- - "code" option of the "include" directive.
+ - New reStructuredText "code" role and directive and "code" option
+ of the "include" directive with syntax highlighting by Pygments_.
- Fix parse_option_marker for option arguments containing ``=``.
-
+
.. _Pygments: http://pygments.org/
* setup.py
@@ -61,16 +59,17 @@
- Support the `abbreviation` and `acronym` standard roles.
- Record only files required to generate the LaTeX source as dependencies.
+ - Fix handling of missing stylesheets.
* docutils/writers/html4css1/__init__.py
- Change default for `math-output` setting to MathJax.
+ - Fix handling of missing stylesheets.
* docutils/writers/docutils_xml.py
- - Use the visitor pattern with default methods instead of minidom
- to facilitate special handling of selected nodes.
-
+ - Use the visitor pattern with default_visit()/default_depart() methods
+ instead of minidom to facilitate special handling of selected nodes.
- Support raw XML (inserted as-is inside a <raw></raw> node).
Release 0.8.1 (2011-08-30)
Modified: trunk/docutils/docutils/writers/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/__init__.py 2012-01-19 11:31:58 UTC (rev 7316)
+++ trunk/docutils/docutils/writers/__init__.py 2012-01-19 11:55:26 UTC (rev 7317)
@@ -52,7 +52,7 @@
def __init__(self):
- # Used by HTML and LaTex writer for output fragments:
+ # Used by HTML and LaTeX writer for output fragments:
self.parts = {}
"""Mapping of document part names to fragments of `self.output`.
Values are Unicode strings; encoding is up to the client. The 'whole'
Modified: trunk/docutils/docutils/writers/html4css1/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/html4css1/__init__.py 2012-01-19 11:31:58 UTC (rev 7316)
+++ trunk/docutils/docutils/writers/html4css1/__init__.py 2012-01-19 11:55:26 UTC (rev 7317)
@@ -1,5 +1,6 @@
# $Id$
-# Author: David Goodger <go...@py...>
+# Author: David Goodger
+# Maintainer: doc...@li...
# Copyright: This module has been placed in the public domain.
"""
@@ -31,6 +32,7 @@
PIL = None
import docutils
from docutils import frontend, nodes, utils, writers, languages, io
+from docutils.error_reporting import SafeString
from docutils.transforms import writer_aux
from docutils.math import unichar2tex, pick_math_environment
from docutils.math.latex2mathml import parse_latex_math
@@ -286,19 +288,8 @@
# encoding not interpolated:
self.html_prolog.append(self.xml_declaration)
self.head = self.meta[:]
- # stylesheets
- styles = utils.get_stylesheet_list(settings)
- if settings.stylesheet_path and not(settings.embed_stylesheet):
- styles = [utils.relative_path(settings._destination, sheet)
- for sheet in styles]
- if settings.embed_stylesheet:
- self.stylesheet = [self.embedded_stylesheet %
- io.FileInput(source_path=sheet, encoding='utf-8').read()
- for sheet in styles]
- settings.record_dependencies.add(*styles)
- else: # link to stylesheets
- self.stylesheet = [self.stylesheet_link % self.encode(stylesheet)
- for stylesheet in styles]
+ self.stylesheet = [self.stylesheet_call(path)
+ for path in utils.get_stylesheet_list(settings)]
self.body_prefix = ['</head>\n<body>\n']
# document title, subtitle display
self.body_pre_docinfo = []
@@ -377,6 +368,26 @@
encoded = encoded.replace('.', '.')
return encoded
+ def stylesheet_call(self, path):
+ """Return code to reference or embed stylesheet file `path`"""
+ if self.settings.embed_stylesheet:
+ try:
+ content = io.FileInput(source_path=path,
+ encoding='utf-8',
+ handle_io_errors=False).read()
+ self.settings.record_dependencies.add(path)
+ except IOError, err:
+ msg = u"Cannot embed stylesheet '%s': %s." % (
+ path, SafeString(err.strerror))
+ self.document.reporter.error(msg)
+ return '<--- %s --->\n' % msg
+ return self.embedded_stylesheet % content
+ # else link to style file:
+ if self.settings.stylesheet_path:
+ # adapt path relative to output (cf. config.html#stylesheet-path)
+ path = utils.relative_path(self.settings._destination, path)
+ return self.stylesheet_link % self.encode(path)
+
def starttag(self, node, tagname, suffix='\n', empty=0, **attributes):
"""
Construct and return a start tag given a node (id & class attributes
Modified: trunk/docutils/docutils/writers/latex2e/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/latex2e/__init__.py 2012-01-19 11:31:58 UTC (rev 7316)
+++ trunk/docutils/docutils/writers/latex2e/__init__.py 2012-01-19 11:55:26 UTC (rev 7317)
@@ -1,6 +1,7 @@
# .. coding: utf8
# $Id$
-# Author: Engelbert Gruber <gr...@us...>
+# Author: Engelbert Gruber, Günter Milde
+# Maintainer: doc...@li...
# Copyright: This module has been placed in the public domain.
"""LaTeX2e document tree Writer."""
@@ -19,6 +20,7 @@
import string
import urllib
from docutils import frontend, nodes, languages, writers, utils, io
+from docutils.error_reporting import SafeString
from docutils.transforms import writer_aux
from docutils.math import pick_math_environment, unichar2tex
@@ -492,11 +494,6 @@
\DUprovidelength{\DUdocinfowidth}{0.9\textwidth}"""
# PreambleCmds.docinfo._depends = 'providelength'
-PreambleCmds.embedded_package_wrapper = r"""\makeatletter
-%% embedded stylesheet: %s
-%s
-\makeatother"""
-
PreambleCmds.dedication = r"""
% dedication topic
\providecommand{\DUtopicdedication}[1]{\begin{center}#1\end{center}}"""
@@ -970,7 +967,6 @@
self.use_latex_toc = settings.use_latex_toc
self.use_latex_docinfo = settings.use_latex_docinfo
self._use_latex_citations = settings.use_latex_citations
- self.embed_stylesheet = settings.embed_stylesheet
self._reference_label = settings.reference_label
self.hyperlink_color = settings.hyperlink_color
self.compound_enumerators = settings.compound_enumerators
@@ -1037,7 +1033,6 @@
self.requirements = SortableDict() # made a list in depart_document()
self.requirements['__static'] = r'\usepackage{ifthen}'
self.latex_preamble = [settings.latex_preamble]
- self.stylesheet = []
self.fallbacks = SortableDict() # made a list in depart_document()
self.pdfsetup = [] # PDF properties (hyperref package)
self.title = []
@@ -1109,30 +1104,10 @@
self.requirements['typearea'] = r'\usepackage{typearea}'
# Stylesheets
- # get list of style sheets from settings
- styles = utils.get_stylesheet_list(settings)
- # adapt path if --stylesheet_path is used
- if settings.stylesheet_path and not(self.embed_stylesheet):
- styles = [utils.relative_path(settings._destination, sheet)
- for sheet in styles]
- for sheet in styles:
- (base, ext) = os.path.splitext(sheet)
- is_package = ext in ['.sty', '']
- if self.embed_stylesheet:
- if is_package:
- sheet = base + '.sty' # adapt package name
- # wrap in \makeatletter, \makeatother
- wrapper = PreambleCmds.embedded_package_wrapper
- else:
- wrapper = '%% embedded stylesheet: %s\n%s'
- settings.record_dependencies.add(sheet)
- self.stylesheet.append(wrapper %
- (sheet, io.FileInput(source_path=sheet, encoding='utf-8').read()))
- else: # link to style sheet
- if is_package:
- self.stylesheet.append(r'\usepackage{%s}' % base)
- else:
- self.stylesheet.append(r'\input{%s}' % sheet)
+ # (the name `self.stylesheet` is singular because only one
+ # stylesheet was supported before Docutils 0.6).
+ self.stylesheet = [self.stylesheet_call(path)
+ for path in utils.get_stylesheet_list(settings)]
# PDF setup
if self.hyperlink_color in ('0', 'false', 'False', ''):
@@ -1150,7 +1125,11 @@
## self.requirements['tocdepth'] = (r'\setcounter{tocdepth}{%d}' %
## len(self.d_class.sections))
- # LaTeX section numbering
+ # Section numbering
+ # TODO: use \secnumdepth instead of starred commands
+ ## if self.settings.sectnum_xform: # section numbering by Docutils
+ ## sectnum_depth = 0
+ ## else:
if not self.settings.sectnum_xform: # section numbering by LaTeX:
# sectnum_depth:
# None "sectnum" directive without depth arg -> LaTeX default
@@ -1180,7 +1159,7 @@
self.requirements['sectnum_start'] = (
r'\setcounter{%s}{%d}' % (self.d_class.sections[0],
settings.sectnum_start-1))
- # currently ignored (configure in a stylesheet):
+ # TODO: currently ignored (configure in a stylesheet):
## settings.sectnum_prefix
## settings.sectnum_suffix
@@ -1188,6 +1167,41 @@
# Auxiliary Methods
# -----------------
+ def stylesheet_call(self, path):
+ """Return code to reference or embed stylesheet file `path`"""
+ # is it a package (no extension or *.sty) or "normal" tex code:
+ (base, ext) = os.path.splitext(path)
+ is_package = ext in ['.sty', '']
+ # Embed content of style file:
+ if self.settings.embed_stylesheet:
+ if is_package:
+ path = base + '.sty' # ensure extension
+ try:
+ content = io.FileInput(source_path=path,
+ encoding='utf-8',
+ handle_io_errors=False).read()
+ self.settings.record_dependencies.add(path)
+ except IOError, err:
+ msg = u"Cannot embed stylesheet '%s':\n %s." % (
+ path, SafeString(err.strerror))
+ self.document.reporter.error(msg)
+ return '% ' + msg.replace('\n', '\n% ')
+ if is_package:
+ content = '\n'.join([r'\makeatletter',
+ content,
+ r'\makeatother'])
+ return '%% embedded stylesheet: %s\n%s' % (path, content)
+ # Link to style file:
+ if is_package:
+ path = base # drop extension
+ cmd = r'\usepackage{%s}'
+ else:
+ cmd = r'\input{%s}'
+ if self.settings.stylesheet_path:
+ # adapt path relative to output (cf. config.html#stylesheet-path)
+ path = utils.relative_path(self.settings._destination, path)
+ return cmd % path
+
def to_latex_encoding(self,docutils_encoding):
"""Translate docutils encoding name into LaTeX's.
Deleted: trunk/docutils/test/data/hidden.css
===================================================================
--- trunk/docutils/test/data/hidden.css 2012-01-19 11:31:58 UTC (rev 7316)
+++ trunk/docutils/test/data/hidden.css 2012-01-19 11:55:26 UTC (rev 7317)
@@ -1,2 +0,0 @@
-.hidden {
- display: none }
Deleted: trunk/docutils/test/data/spam.sty
===================================================================
--- trunk/docutils/test/data/spam.sty 2012-01-19 11:31:58 UTC (rev 7316)
+++ trunk/docutils/test/data/spam.sty 2012-01-19 11:55:26 UTC (rev 7317)
@@ -1,3 +0,0 @@
-\ProvidesPackage{spam}
-[2008/12/09 v0.2 simple silly test package]
-\newcommand{\spam}{\@percentchar\ wonderfull spam}
Deleted: trunk/docutils/test/functional/expected/multistyle_path_embed_rst_html4css1.html
===================================================================
--- trunk/docutils/test/functional/expected/multistyle_path_embed_rst_html4css1.html 2012-01-19 11:31:58 UTC (rev 7316)
+++ trunk/docutils/test/functional/expected/multistyle_path_embed_rst_html4css1.html 2012-01-19 11:55:26 UTC (rev 7317)
@@ -1,28 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.9: http://docutils.sourceforge.net/" />
-<title></title>
-<style type="text/css">
-
-.hidden {
- display: none }
-
-</style>
-<style type="text/css">
-
-dl.docutils dd {
- margin-bottom: 0.5em }
-
-</style>
-</head>
-<body>
-<div class="document">
-
-
-<p>simple input</p>
-</div>
-</body>
-</html>
Deleted: trunk/docutils/test/functional/expected/multistyle_path_rst_html4css1.html
===================================================================
--- trunk/docutils/test/functional/expected/multistyle_path_rst_html4css1.html 2012-01-19 11:31:58 UTC (rev 7316)
+++ trunk/docutils/test/functional/expected/multistyle_path_rst_html4css1.html 2012-01-19 11:55:26 UTC (rev 7317)
@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.9: http://docutils.sourceforge.net/" />
-<title></title>
-<link rel="stylesheet" href="../../ham.css" type="text/css" />
-<link rel="stylesheet" href="../../path/to/spam.css" type="text/css" />
-</head>
-<body>
-<div class="document">
-
-
-<p>simple input</p>
-</div>
-</body>
-</html>
Deleted: trunk/docutils/test/functional/expected/multistyle_rst_html4css1.html
===================================================================
--- trunk/docutils/test/functional/expected/multistyle_rst_html4css1.html 2012-01-19 11:31:58 UTC (rev 7316)
+++ trunk/docutils/test/functional/expected/multistyle_rst_html4css1.html 2012-01-19 11:55:26 UTC (rev 7317)
@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.9: http://docutils.sourceforge.net/" />
-<title></title>
-<link rel="stylesheet" href="ham.css" type="text/css" />
-<link rel="stylesheet" href="/spam.css" type="text/css" />
-</head>
-<body>
-<div class="document">
-
-
-<p>simple input</p>
-</div>
-</body>
-</html>
Copied: trunk/docutils/test/functional/expected/stylesheet_path_html4css1.html (from rev 7307, trunk/docutils/test/functional/expected/multistyle_path_rst_html4css1.html)
===================================================================
--- trunk/docutils/test/functional/expected/stylesheet_path_html4css1.html (rev 0)
+++ trunk/docutils/test/functional/expected/stylesheet_path_html4css1.html 2012-01-19 11:55:26 UTC (rev 7317)
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<meta name="generator" content="Docutils 0.9: http://docutils.sourceforge.net/" />
+<title></title>
+<link rel="stylesheet" href="../../data/ham.css" type="text/css" />
+<link rel="stylesheet" href="/missing.css" type="text/css" />
+</head>
+<body>
+<div class="document">
+
+
+<p>simple input</p>
+</div>
+</body>
+</html>
Deleted: trunk/docutils/test/functional/tests/multistyle_path_embedd_rst_html4css1.py
===================================================================
--- trunk/docutils/test/functional/tests/multistyle_path_embedd_rst_html4css1.py 2012-01-19 11:31:58 UTC (rev 7316)
+++ trunk/docutils/test/functional/tests/multistyle_path_embedd_rst_html4css1.py 2012-01-19 11:55:26 UTC (rev 7317)
@@ -1,14 +0,0 @@
-# Source and destination file names.
-test_source = "simple.txt"
-test_destination = "multistyle_path_embed_rst_html4css1.html"
-
-# Keyword parameters passed to publish_file.
-reader_name = "standalone"
-parser_name = "rst"
-writer_name = "html4css1"
-
-# Settings
-# test for encoded attribute value:
-settings_overrides['stylesheet'] = ''
-settings_overrides['stylesheet_path'] = 'data/hidden.css,data/ham.css'
-settings_overrides['embed_stylesheet'] = 1
Deleted: trunk/docutils/test/functional/tests/multistyle_path_rst_html4css1.py
===================================================================
--- trunk/docutils/test/functional/tests/multistyle_path_rst_html4css1.py 2012-01-19 11:31:58 UTC (rev 7316)
+++ trunk/docutils/test/functional/tests/multistyle_path_rst_html4css1.py 2012-01-19 11:55:26 UTC (rev 7317)
@@ -1,14 +0,0 @@
-# Source and destination file names.
-test_source = "simple.txt"
-test_destination = "multistyle_path_rst_html4css1.html"
-
-# Keyword parameters passed to publish_file.
-reader_name = "standalone"
-parser_name = "rst"
-writer_name = "html4css1"
-
-# Settings
-# test for encoded attribute value:
-settings_overrides['stylesheet'] = ''
-settings_overrides['stylesheet_path'] = 'ham.css,path/to/spam.css'
-settings_overrides['embed_stylesheet'] = 0
Deleted: trunk/docutils/test/functional/tests/multistyle_rst_html4css1.py
===================================================================
--- trunk/docutils/test/functional/tests/multistyle_rst_html4css1.py 2012-01-19 11:31:58 UTC (rev 7316)
+++ trunk/docutils/test/functional/tests/multistyle_rst_html4css1.py 2012-01-19 11:55:26 UTC (rev 7317)
@@ -1,14 +0,0 @@
-# Source and destination file names.
-test_source = "simple.txt"
-test_destination = "multistyle_rst_html4css1.html"
-
-# Keyword parameters passed to publish_file.
-reader_name = "standalone"
-parser_name = "rst"
-writer_name = "html4css1"
-
-# Settings
-# test for encoded attribute value:
-settings_overrides['stylesheet'] = 'ham.css,/spam.css'
-settings_overrides['stylesheet_path'] = ''
-settings_overrides['embed_stylesheet'] = 0
Copied: trunk/docutils/test/functional/tests/stylesheet_path_html4css1.py (from rev 7307, trunk/docutils/test/functional/tests/multistyle_path_embedd_rst_html4css1.py)
===================================================================
--- trunk/docutils/test/functional/tests/stylesheet_path_html4css1.py (rev 0)
+++ trunk/docutils/test/functional/tests/stylesheet_path_html4css1.py 2012-01-19 11:55:26 UTC (rev 7317)
@@ -0,0 +1,15 @@
+# Test re-writing of stylesheet paths relative to output directory
+
+# Source and destination file names.
+test_source = "simple.txt"
+test_destination = "stylesheet_path_html4css1.html"
+
+# Keyword parameters passed to publish_file.
+reader_name = "standalone"
+parser_name = "rst"
+writer_name = "html4css1"
+
+# Settings
+settings_overrides['stylesheet'] = ''
+settings_overrides['stylesheet_path'] = 'data/ham.css,/missing.css'
+settings_overrides['embed_stylesheet'] = False
Modified: trunk/docutils/test/test_writers/test_latex2e.py
===================================================================
--- trunk/docutils/test/test_writers/test_latex2e.py 2012-01-19 11:31:58 UTC (rev 7316)
+++ trunk/docutils/test/test_writers/test_latex2e.py 2012-01-19 11:55:26 UTC (rev 7317)
@@ -17,23 +17,22 @@
from __init__ import DocutilsTestSupport
-from docutils._compat import b
-
def suite():
- settings = {'use_latex_toc': 0}
+ settings = {'use_latex_toc': False}
s = DocutilsTestSupport.PublishTestSuite('latex', suite_settings=settings)
s.generateTests(totest)
- settings['use_latex_toc'] = 1
+ settings['use_latex_toc'] = True
s.generateTests(totest_latex_toc)
- settings['use_latex_toc'] = 0
- settings['sectnum_xform'] = 0
+ settings['use_latex_toc'] = False
+ settings['sectnum_xform'] = False
s.generateTests(totest_latex_sectnum)
- settings['sectnum_xform'] = 1
- settings['use_latex_citations'] = 1
+ settings['sectnum_xform'] = True
+ settings['use_latex_citations'] = True
s.generateTests(totest_latex_citations)
settings['stylesheet_path'] = 'data/spam,data/ham.tex'
s.generateTests(totest_stylesheet)
- settings['embed_stylesheet'] = 1
+ settings['embed_stylesheet'] = True
+ settings['warning_stream'] = ''
s.generateTests(totest_stylesheet_embed)
return s
@@ -659,13 +658,8 @@
# input
["""two stylesheets embedded in the header""",
head_template.substitute(dict(parts, stylesheet =
-r"""\makeatletter
-% embedded stylesheet: data/spam.sty
-\ProvidesPackage{spam}
-[2008/12/09 v0.2 simple silly test package]
-\newcommand{\spam}{\@percentchar\ wonderfull spam}
-
-\makeatother
+r"""% Cannot embed stylesheet 'data/spam.sty':
+% No such file or directory.
% embedded stylesheet: data/ham.tex
\newcommand{\ham}{wonderful ham}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|