Georg Brandl avatar Georg Brandl committed 39c514a

Added ``tab-width`` option to ``literalinclude`` directive.

Comments (0)

Files changed (6)

 Release 1.0 (in development)
+* Added ``tab-width`` option to ``literalinclude`` directive.
 * The ``html_sidebars`` config value can now contain patterns as
   keys, and the values can be lists that explicitly select which
   sidebar templates should be rendered.  That means that the builtin


    is absolute (starting with ``/``), it is relative to the top source
+   Tabs in the input are expanded if you give a ``tab-width`` option with the
+   desired tab width.
    The directive also supports the ``linenos`` flag option to switch on line
    numbers, and a ``language`` option to select a language different from the
    current file's standard language.  Example with options::
       The ``pyobject``, ``lines``, ``start-after`` and ``end-before`` options,
       as well as support for absolute filenames.
    .. versionadded:: 1.0
-      The ``prepend`` and ``append`` options.
+      The ``prepend`` and ``append`` options, as well as ``tab-width``.
 .. rubric:: Footnotes


     final_argument_whitespace = False
     option_spec = {
         'linenos': directives.flag,
+        'tab-width': int,
         'language': directives.unchanged_required,
         'encoding': directives.encoding,
         'pyobject': directives.unchanged_required,
            lines.append(append + '\n')
         text = ''.join(lines)
+        if self.options.get('tab-width'):
+            text = text.expandtabs(self.options['tab-width'])
         retnode = nodes.literal_block(text, text, source=fn)
         retnode.line = 1
         if self.options.get('language', ''):


    :prepend: START CODE
    :append: END CODE
+.. cssclass:: inc-tab3
+.. literalinclude::
+   :tab-width: 3
+   :language: text
+.. cssclass:: inc-tab8
+.. literalinclude::
+   :tab-width: 8
+   :language: python
 Test if dedenting before parsing works.
 .. highlight:: python


+Tabs include file test
+The next line has a tab:
+-|	|-


 if pygments:
         ".//pre/span[@class='s']": u'üöä',
-        ".//div[@class='inc-pyobj1 highlight-text']/div/pre":
+        ".//div[@class='inc-pyobj1 highlight-text']//pre":
             r'^class Foo:\n    pass\n\s*$',
-        ".//div[@class='inc-pyobj2 highlight-text']/div/pre":
+        ".//div[@class='inc-pyobj2 highlight-text']//pre":
             r'^    def baz\(\):\n        pass\n\s*$',
-        ".//div[@class='inc-lines highlight-text']/div/pre":
+        ".//div[@class='inc-lines highlight-text']//pre":
             r'^class Foo:\n    pass\nclass Bar:\n$',
-        ".//div[@class='inc-startend highlight-text']/div/pre":
+        ".//div[@class='inc-startend highlight-text']//pre":
             ur'^foo = u"Including Unicode characters: üöä"\n$',
-        ".//div[@class='inc-preappend highlight-text']/div/pre":
+        ".//div[@class='inc-preappend highlight-text']//pre":
             r'(?m)^START CODE$',
-        ".//div[@class='inc-pyobj-dedent highlight-python']/div/pre/span":
+        ".//div[@class='inc-pyobj-dedent highlight-python']//span":
+        ".//div[@class='inc-tab3 highlight-text']//pre":
+            r'-| |-',
+        ".//div[@class='inc-tab8 highlight-python']//pre":
+            r'-|      |-',
         ".//pre/span": 'line 1',
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.