Unknown field names without arguments are transformed with a trailing space

Rob Ruana avatarRob Ruana created an issue

When an unknown field name is encountered in a python docstring, a space is appended to the field name by the sphinx.util.docfields.DocFieldTransformer. The following docstring:

def func_with_unknown_field():
    """Demonstrate unknown field transformation

       :Field_Name: Field Value


Yields the following incorrect HTML for Field_Name:

<table rules="none" frame="void" class="docutils field-list">
    <col class="field-name">
    <col class="field-body">
  <tbody valign="top">
    <tr class="field-odd field">
      <th class="field-name">Field_name :</th>
      <td class="field-body">Field Value</td>

Note the extra space in Field_name :.

See the reStructuredText Markup Spec regarding field lists.

For examples of this bug in action, see the "Returns" and "Parameters" field names in the NumPy documentation.

Comments (4)

  1. Georg Brandl

    Fix #1203: Does not append space to unknown field names.

    If an unknown field name is encountered, a space is only appended if the field arguments are not empty. Also, only the first character of the field name is upper cased, and the case of the rest of the string remains unchanged.

    → <<cset 99289a20ecf3>>

  2. Log in to comment
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 ProjectModifiedEvent.java.
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.