Commits

Georg Brandl committed e3041de

#209: Added :confval:`text_newlines` and :confval:`text_sectionchars` config values.

  • Participants
  • Parent commits c1da488

Comments (0)

Files changed (5)

 
 * #553: Added :rst:dir:`testcleanup` blocks in the doctest extension.
 
+* #209: Added :confval:`text_newlines` and :confval:`text_sectionchars`
+  config values.
+
 
 Release 1.0.6 (in development)
 ==============================
    a chapter, but can be confusing because it mixes entries of differnet
    depth in one list.  The default value is ``True``.
 
+
 .. _latex-options:
 
 Options for LaTeX output
       Use the ``'pointsize'`` key in the :confval:`latex_elements` value.
 
 
+.. _text-options:
+
+Options for text output
+-----------------------
+
+These options influence text output.
+
+.. confval:: text_newlines
+
+   Determines which end-of-line character(s) are used in text output.
+
+   * ``'unix'``: use Unix-style line endings (``\n``)
+   * ``'windows'``: use Windows-style line endings (``\r\n``)
+   * ``'native'``: use the line ending style of the platform the documentation
+     is built on
+
+   Default: ``'unix'``.
+
+   .. versionadded:: 1.1
+
+.. confval:: text_sectionchars
+
+   A string of 7 characters that should be used for underlining sections.
+   The first character is used for first-level headings, the second for
+   second-level headings and so on.
+
+   The default is ``'*=-~"+`'``.
+
+   .. versionadded:: 1.1
+
+
 .. _man-options:
 
 Options for manual page output
         latex_preamble = ('', None),
 
         # text options
-        text_sectionchars = ('*=-~"+`', 'text'),
-        text_windows_newlines = (False, 'text'),
+        text_sectionchars = ('*=-~"+`', 'env'),
+        text_newlines = ('unix', 'env'),
 
         # manpage options
         man_pages = ([], None),

sphinx/environment.py

                 continue
             parser.parse(msgstr, patch)
             patch = patch[0]
-            #XXX doctest and other block markup
+            # XXX doctest and other block markup
             if not isinstance(patch, nodes.paragraph):
                 continue # skip for now
             for child in patch.children: # update leaves

sphinx/writers/text.py

     :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS.
     :license: BSD, see LICENSE for details.
 """
-
+import os
 import re
 import textwrap
 
     def __init__(self, document, builder):
         nodes.NodeVisitor.__init__(self, document)
 
+        newlines = builder.config.text_newlines
+        if newlines == 'windows':
+            self.nl = '\r\n'
+        elif newlines == 'native':
+            self.nl = os.linesep
+        else:
+            self.nl = '\n'
+        self.sectionchars = builder.config.text_sectionchars
         self.states = [[]]
         self.stateindent = [0]
         self.list_counter = []
         self.new_state(0)
     def depart_document(self, node):
         self.end_state()
-        self.body = '\n'.join(line and (' '*indent + line)
-                              for indent, lines in self.states[0]
-                              for line in lines)
+        self.body = self.nl.join(line and (' '*indent + line)
+                                 for indent, lines in self.states[0]
+                                 for line in lines)
         # XXX header/footer?
 
     def visit_highlightlang(self, node):
 
     def visit_desc_content(self, node):
         self.new_state()
-        self.add_text('\n')
+        self.add_text(self.nl)
     def depart_desc_content(self, node):
         self.end_state()
 
                 lastname = production['tokenname']
             else:
                 self.add_text('%s    ' % (' '*len(lastname)))
-            self.add_text(production.astext() + '\n')
+            self.add_text(production.astext() + self.nl)
         self.end_state(wrap=False)
         raise nodes.SkipNode
 
                                       'not implemented.')
         self.new_state(0)
     def depart_entry(self, node):
-        text = '\n'.join('\n'.join(x[1]) for x in self.states.pop())
+        text = self.nl.join(self.nl.join(x[1]) for x in self.states.pop())
         self.stateindent.pop()
         self.table[-1].append(text)
 
             for width in realwidths:
                 out.append(char * (width+2))
                 out.append('+')
-            self.add_text(''.join(out) + '\n')
+            self.add_text(''.join(out) + self.nl)
 
         def writerow(row):
             lines = zip(*row)
                     else:
                         out.append(' ' * (realwidths[i] + 2))
                     out.append('|')
-                self.add_text(''.join(out) + '\n')
+                self.add_text(''.join(out) + self.nl)
 
         for i, row in enumerate(fmted_rows):
             if separator and i == separator: