From d2953d7c3e68dfcce52ae67d13633cc26c9a12af Mon Sep 17 00:00:00 2001 From: milde Date: Fri, 12 Oct 2012 12:21:18 +0000 Subject: [PATCH] Use validate_comma_separated_string_list for stylesheet setting. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@7527 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/utils/__init__.py | 13 +++++-------- docutils/writers/html4css1/__init__.py | 15 ++++++++++++--- docutils/writers/latex2e/__init__.py | 15 +++++++-------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/docutils/utils/__init__.py b/docutils/utils/__init__.py index 6ab4ff8e2..ac2ad6edf 100644 --- a/docutils/utils/__init__.py +++ b/docutils/utils/__init__.py @@ -509,14 +509,11 @@ def get_stylesheet_list(settings): """ assert not (settings.stylesheet and settings.stylesheet_path), ( 'stylesheet and stylesheet_path are mutually exclusive.') - if settings.stylesheet_path: - sheets = settings.stylesheet_path.split(",") - elif settings.stylesheet: - sheets = settings.stylesheet.split(",") - else: - sheets = [] - # strip whitespace (frequently occuring in config files) - return [sheet.strip(u' \t\n') for sheet in sheets] + stylesheets = settings.stylesheet_path or settings.stylesheet or [] + # programmatically set default can be string or unicode: + if not isinstance(stylesheets, list): + stylesheets = [cls.strip() for cls in stylesheets.split(',')] + return stylesheets def get_trim_footnote_ref_space(settings): """ diff --git a/docutils/writers/html4css1/__init__.py b/docutils/writers/html4css1/__init__.py index fc762bc84..569c5a211 100644 --- a/docutils/writers/html4css1/__init__.py +++ b/docutils/writers/html4css1/__init__.py @@ -65,14 +65,16 @@ class Writer(writers.Writer): ('Specify comma separated list of stylesheet URLs. ' 'Overrides previous --stylesheet and --stylesheet-path settings.', ['--stylesheet'], - {'metavar': '', 'overrides': 'stylesheet_path'}), + {'metavar': '', 'overrides': 'stylesheet_path', + 'validator': frontend.validate_comma_separated_list}), ('Specify comma separated list of stylesheet paths. ' 'With --link-stylesheet, ' 'the path is rewritten relative to the output HTML file. ' 'Default: "%s"' % default_stylesheet_path, ['--stylesheet-path'], {'metavar': '', 'overrides': 'stylesheet', - 'default': default_stylesheet_path}), + 'validator': frontend.validate_comma_separated_list, + 'default': [default_stylesheet_path]}), ('Embed the stylesheet(s) in the output HTML file. The stylesheet ' 'files must be accessible during processing. This is the default.', ['--embed-stylesheet'], @@ -300,6 +302,7 @@ class HTMLTranslator(nodes.NodeVisitor): self.body_suffix = ['\n\n'] self.section_level = 0 self.initial_header_level = int(settings.initial_header_level) + self.math_output = settings.math_output.lower() # A heterogenous stack used in conjunction with the tree traversal. # Make sure that the pops correspond to the pushes: @@ -1164,10 +1167,16 @@ class HTMLTranslator(nodes.NodeVisitor): self.body.append('\n\n') def visit_math(self, node, math_env=''): + # If the method is called from visit_math_block(), math_env != ''. + # As there is no native HTML math support, we provide alternatives: # LaTeX and MathJax math_output modes simply wrap the content, # HTML and MathML math_output modes also convert the math_code. - # If the method is called from visit_math_block(), math_env != ''. + if self.math_output not in ('mathml', 'html', 'mathjax', 'latex'): + self.document.reporter.error( + 'math-output format "%s" not supported ' + 'falling back to "latex"'% self.math_output) + self.math_output = 'latex' # # HTML container tags = {# math_output: (block, inline, class-arguments) diff --git a/docutils/writers/latex2e/__init__.py b/docutils/writers/latex2e/__init__.py index 4c9af1325..a01a9c4d0 100644 --- a/docutils/writers/latex2e/__init__.py +++ b/docutils/writers/latex2e/__init__.py @@ -88,11 +88,13 @@ class Writer(writers.Writer): ' Overrides previous --stylesheet and --stylesheet-path settings.', ['--stylesheet'], {'default': '', 'metavar': '', - 'overrides': 'stylesheet_path'}), + 'overrides': 'stylesheet_path', + 'validator': frontend.validate_comma_separated_list}), ('Like --stylesheet, but the path is rewritten ' 'relative to the output file. ', ['--stylesheet-path'], - {'metavar': '', 'overrides': 'stylesheet'}), + {'metavar': '', 'overrides': 'stylesheet', + 'validator': frontend.validate_comma_separated_list}), ('Link to the stylesheet(s) in the output file. (default)', ['--link-stylesheet'], {'dest': 'embed_stylesheet', 'action': 'store_false'}), @@ -226,14 +228,11 @@ class Writer(writers.Writer): # Override parent method to add latex-specific transforms def get_transforms(self): - # call the parent class' method - transform_list = writers.Writer.get_transforms(self) - # print transform_list + return writers.Writer.get_transforms(self) + [ # Convert specific admonitions to generic one - transform_list.append(writer_aux.Admonitions) + writer_aux.Admonitions, # TODO: footnote collection transform - # transform_list.append(footnotes.collect) - return transform_list + ] def translate(self): visitor = self.translator_class(self.document) -- 2.11.4.GIT