How to correctly include other ReST-files in a sphinx-project?

时间:2017-06-15 09:25:18

标签: python-sphinx restructuredtext

My hand-written documentation/user-guide (written in ReStructuredText with sphinx) has become quite big so I started organize my .rst-files in sub-directories.

In the index.rst I'm including a subindex.rst of each sub-directory which itselfs includes other .rst-files for further sub-directories.

index.rst:

.. include:: subdir1/subindex.rst
.. include:: subdir2/subindex.rst

subdir1/subindex.rst:

.. include:: file1.rst
.. include:: file2.rst

In principle this works well, except that sphinx is recursively looking for .rst-files which it tries to parse. without changing the current-working dir. So, it fails when seeing include:: file1.rst inside subdir1.

I'm working around this issue by setting exclude_pattern to ignore my subdirs. This seems not right.

What would be the right way to include a .rst-file of a subdir?

1 个答案:

答案 0 :(得分:4)

toctree directive应该做你想做的事。

<?php
    if (isset($_POST['submit'])) {
        echo print_r($_POST);
    }
?> 

// other stuff

<form class="form-horizontal form-label-left" method="post" action="#" >


  <span class="section">Info</span>

  <div class="item form-group">
    <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Name <span class="required">*</span>
    </label>
    <div class="col-md-6 col-sm-6 col-xs-12">
      <input id="name" class="form-control col-md-7 col-xs-12" data-validate-length-range="6" data-validate-words="2" name="name" placeholder="both name(s) e.g Jon Doe" required="required" type="text">
    </div>
  </div>
  <div class="item form-group">
    <label class="control-label col-md-3 col-sm-3 col-xs-12" for="textarea">Description <span class="required">*</span>
    </label>
    <div class="col-md-6 col-sm-6 col-xs-12">
      <textarea id="description" required="required" name="description" class="form-control col-md-7 col-xs-12"></textarea>
    </div>
  </div>
  <div class="item form-group">
    <label class="control-label col-md-3 col-sm-3 col-xs-12" for="textarea">Type <span class="required">*</span>
    </label>
    <div class="col-md-6 col-sm-6 col-xs-12">
      <select id="type" name="type" required="required" class="selectpicker form-control col-md-7 col-xs-12">
        <option title="Combo 1">Weekly</option>
        <option title="Combo 2">Monthly</option>
        <option title="Combo 3">Annually</option>
      </select>
    </div>
  </div>

  <div class="ln_solid"></div>
  <div class="form-group">
    <div class="col-md-6 col-md-offset-3">
      <button  type="submit" value="submit" name="submit" class="btn btn-success">Submit</button>
    </div>
  </div>
</form>

glob .. toctree:: :glob: subdir1/* subdir2/* 将按字母顺序对*内的文件进行排序。为了避免排序,您可以指定没有通配的订单。

subdir

如果您不想要单个页面而只需要一个大页面,则可以调用make singlehtml