|
From: <mi...@us...> - 2021-11-17 19:04:18
|
Revision: 8891
http://sourceforge.net/p/docutils/code/8891
Author: milde
Date: 2021-11-17 19:04:15 +0000 (Wed, 17 Nov 2021)
Log Message:
-----------
Fix behaviour of get_stylesheet_list()
Do not look up stylesheets given as "stylesheet" setting.
Cf. bug #434.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/docutils/utils/__init__.py
trunk/docutils/docutils/writers/_html_base.py
trunk/docutils/test/functional/expected/misc_rst_html4css1.html
trunk/docutils/test/functional/tests/misc_rst_html4css1.py
trunk/docutils/test/test_parsers/test_rst/test_section_headers.py
trunk/docutils/test/test_parsers/test_rst/test_targets.py
trunk/docutils/test/test_utils.py
trunk/docutils/test/test_writers/test_latex2e.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2021-11-16 22:20:43 UTC (rev 8890)
+++ trunk/docutils/HISTORY.txt 2021-11-17 19:04:15 UTC (rev 8891)
@@ -18,10 +18,15 @@
- Node.traverse() returns a list again to restore backwards
compatibility. Fixes bug #431.
-
+
- New method Node.findall(): like Node.traverse() but returns an
iterator. Obsoletes Node.traverse().
+* docutils/utils/__init__.py:
+
+ - Fix behaviour of get_stylesheet_list(): do not look up stylesheets
+ given as "stylesheet" setting. Cf. bug #434.
+
* docutils/writers/_html_base.py
- Fix handling of ``footnote_backlinks==False`` (report Alan G Isaac).
@@ -32,9 +37,9 @@
* docutils/writers/odf_odt/__init__.py:
- - Fix spurious output with Windows (bug #350).
+ - Fix spurious output with Windows (bug #350).
-* test\test_error_reporting.py
+* test/test_error_reporting.py
- Fix a false positive (bug #434).
Modified: trunk/docutils/docutils/utils/__init__.py
===================================================================
--- trunk/docutils/docutils/utils/__init__.py 2021-11-16 22:20:43 UTC (rev 8890)
+++ trunk/docutils/docutils/utils/__init__.py 2021-11-17 19:04:15 UTC (rev 8891)
@@ -492,6 +492,10 @@
enable specification of multiple stylesheets as a comma-separated
list.
"""
+ warnings.warn('utils.get_stylesheet_reference()'
+ ' is obsoleted by utils.get_stylesheet_list()'
+ ' and will be removed in Docutils 1.2.',
+ DeprecationWarning, stacklevel=2)
if settings.stylesheet_path:
assert not settings.stylesheet, (
'stylesheet and stylesheet_path are mutually exclusive.')
@@ -518,12 +522,14 @@
assert not (settings.stylesheet and settings.stylesheet_path), (
'stylesheet and stylesheet_path are mutually exclusive.')
stylesheets = settings.stylesheet_path or settings.stylesheet or []
- # programmatically set default can be string or unicode:
+ # programmatically set default may be string with comma separated list:
if not isinstance(stylesheets, list):
stylesheets = [path.strip() for path in stylesheets.split(',')]
- # expand relative paths if found in stylesheet-dirs:
- return [find_file_in_dirs(path, settings.stylesheet_dirs)
- for path in stylesheets]
+ if settings.stylesheet_path:
+ # expand relative paths if found in stylesheet-dirs:
+ stylesheets = [find_file_in_dirs(path, settings.stylesheet_dirs)
+ for path in stylesheets]
+ return stylesheets
def find_file_in_dirs(path, dirs):
"""
Modified: trunk/docutils/docutils/writers/_html_base.py
===================================================================
--- trunk/docutils/docutils/writers/_html_base.py 2021-11-16 22:20:43 UTC (rev 8890)
+++ trunk/docutils/docutils/writers/_html_base.py 2021-11-17 19:04:15 UTC (rev 8891)
@@ -393,8 +393,10 @@
encoded = encoded.replace('.', '.')
return encoded
- def stylesheet_call(self, path):
+ def stylesheet_call(self, path, adjust_path=None):
"""Return code to reference or embed stylesheet file `path`"""
+ if adjust_path is None:
+ adjust_path = bool(self.settings.stylesheet_path)
if self.settings.embed_stylesheet:
try:
content = docutils.io.FileInput(source_path=path,
@@ -407,8 +409,8 @@
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)
+ if adjust_path:
+ # rewrite path relative to output (cf. config.html#stylesheet-path)
path = utils.relative_path(self.settings._destination, path)
return self.stylesheet_link % self.encode(path)
@@ -1237,7 +1239,8 @@
elif self.math_output == 'html':
if self.math_output_options and not self.math_header:
self.math_header = [self.stylesheet_call(
- utils.find_file_in_dirs(s, self.settings.stylesheet_dirs))
+ utils.find_file_in_dirs(s, self.settings.stylesheet_dirs),
+ adjust_path=True)
for s in self.math_output_options[0].split(',')]
# TODO: fix display mode in matrices and fractions
math2html.DocumentParameters.displaymode = (math_env != '')
Modified: trunk/docutils/test/functional/expected/misc_rst_html4css1.html
===================================================================
--- trunk/docutils/test/functional/expected/misc_rst_html4css1.html 2021-11-16 22:20:43 UTC (rev 8890)
+++ trunk/docutils/test/functional/expected/misc_rst_html4css1.html 2021-11-17 19:04:15 UTC (rev 8891)
@@ -6,8 +6,8 @@
<meta name="generator" content="Docutils 0.18.1b.dev: http://docutils.sourceforge.net/" />
<title>Additional tests with html4css1</title>
<link rel="stylesheet" href="foo&bar.css" type="text/css" />
-<link rel="stylesheet" href="functional/input/data/html4css1.css" type="text/css" />
-<link rel="stylesheet" href="functional/input/data/math.css" type="text/css" />
+<link rel="stylesheet" href="../input/data/html4css1.css" type="text/css" />
+<link rel="stylesheet" href="../input/data/math.css" type="text/css" />
</head>
<body>
<div class="document" id="additional-tests-with-html4css1">
Modified: trunk/docutils/test/functional/tests/misc_rst_html4css1.py
===================================================================
--- trunk/docutils/test/functional/tests/misc_rst_html4css1.py 2021-11-16 22:20:43 UTC (rev 8890)
+++ trunk/docutils/test/functional/tests/misc_rst_html4css1.py 2021-11-17 19:04:15 UTC (rev 8891)
@@ -8,9 +8,10 @@
writer_name = "html4css1"
# Settings
-# test for encoded attribute value in optional stylesheet name:
-settings_overrides['stylesheet'] = 'foo&bar.css, html4css1.css'
+# test for encoded attribute value in optional stylesheet name,
+# 'stylesheet' setting, values are used verbatim
+settings_overrides['stylesheet'] = 'foo&bar.css, ../input/data/html4css1.css'
+# reset to avoid conflict with 'stylesheet'
settings_overrides['stylesheet_path'] = ''
-# local copy of stylesheets:
-# (Test runs in ``docutils/test/``, we need relative path from there.)
+# stylesheet_dirs not used with 'stylesheet'
settings_overrides['stylesheet_dirs'] = ('.', 'functional/input/data')
Modified: trunk/docutils/test/test_parsers/test_rst/test_section_headers.py
===================================================================
--- trunk/docutils/test/test_parsers/test_rst/test_section_headers.py 2021-11-16 22:20:43 UTC (rev 8890)
+++ trunk/docutils/test/test_parsers/test_rst/test_section_headers.py 2021-11-17 19:04:15 UTC (rev 8891)
@@ -1,5 +1,5 @@
+#! /usr/bin/env python
# -*- coding: utf-8 -*-
-#! /usr/bin/env python
# $Id$
# Author: David Goodger <go...@py...>
Modified: trunk/docutils/test/test_parsers/test_rst/test_targets.py
===================================================================
--- trunk/docutils/test/test_parsers/test_rst/test_targets.py 2021-11-16 22:20:43 UTC (rev 8890)
+++ trunk/docutils/test/test_parsers/test_rst/test_targets.py 2021-11-17 19:04:15 UTC (rev 8891)
@@ -1,4 +1,3 @@
-
#! /usr/bin/env python
# $Id$
Modified: trunk/docutils/test/test_utils.py
===================================================================
--- trunk/docutils/test/test_utils.py 2021-11-16 22:20:43 UTC (rev 8890)
+++ trunk/docutils/test/test_utils.py 2021-11-17 19:04:15 UTC (rev 8891)
@@ -354,7 +354,38 @@
self.assertEqual(unescaped, self.unescaped)
restored = utils.unescape(self.nulled, restore_backslashes=True)
self.assertEqual(restored, self.escaped)
-
+
+class StylesheetFunctionTests(unittest.TestCase):
+
+ stylesheet_dirs = ['.', 'data']
+
+ def test_get_stylesheet_list_stylesheet_path(self):
+ # look for stylesheets in stylesheet_dirs
+ self.stylesheet = None
+ self.stylesheet_path = 'ham.css, missing.css'
+
+ self.assertEqual(utils.get_stylesheet_list(self),
+ ['data/ham.css', 'missing.css'])
+
+ def test_get_stylesheet_list_stylesheet(self):
+ # use stylesheet paths verbatim
+ self.stylesheet = 'ham.css, missing.css'
+ self.stylesheet_path = None
+
+ self.assertEqual(utils.get_stylesheet_list(self),
+ ['ham.css', 'missing.css'])
+
+ def test_get_stylesheet_list_conflict(self):
+ # settings "stylesheet_path" and "stylesheet"
+ # must not be used together
+ self.stylesheet = 'ham.css, missing.css'
+ self.stylesheet_path = 'man.css, miss2.css'
+ self.assertRaises(AssertionError,
+ utils.get_stylesheet_list, self)
+
+
+
+
if __name__ == '__main__':
unittest.main()
Modified: trunk/docutils/test/test_writers/test_latex2e.py
===================================================================
--- trunk/docutils/test/test_writers/test_latex2e.py 2021-11-16 22:20:43 UTC (rev 8890)
+++ trunk/docutils/test/test_writers/test_latex2e.py 2021-11-17 19:04:15 UTC (rev 8891)
@@ -1,5 +1,5 @@
+#! /usr/bin/env python
# -*- coding: utf-8 -*-
-#! /usr/bin/env python
# $Id$
# Author: engelbert gruber <gr...@us...>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|