162162
163163
164164def description_to_list (
165- text : str ,
165+ description : str ,
166166 indentation : str ,
167167 wrap_length : int ,
168168) -> List [str ]:
169169 """Convert the description to a list of wrap length lines.
170170
171171 Parameters
172172 ----------
173- text : str
173+ description : str
174174 The docstring description.
175175 indentation : str
176176 The indentation (number of spaces or tabs) to place in front of each
@@ -180,38 +180,43 @@ def description_to_list(
180180
181181 Returns
182182 -------
183- _lines : list
184- A list containing each line of the description with any links put
185- back together.
183+ _wrapped_lines : list
184+ A list containing each line of the description wrapped at wrap_length.
186185 """
187186 # This is a description containing only one paragraph.
188- if len (re .findall (r"\n\n" , text )) <= 0 :
187+ if len (re .findall (r"\n\n" , description )) <= 0 :
189188 return textwrap .wrap (
190- textwrap .dedent (text ),
189+ textwrap .dedent (description ),
191190 width = wrap_length ,
192191 initial_indent = indentation ,
193192 subsequent_indent = indentation ,
194193 )
195194
196195 # This is a description containing multiple paragraphs.
197- _lines = []
198- for _line in text .split ("\n \n " ):
199- _text = textwrap .wrap (
196+ _wrapped_lines = []
197+ for _line in description .split ("\n \n " ):
198+ _wrapped_line = textwrap .wrap (
200199 textwrap .dedent (_line ),
201200 width = wrap_length ,
202201 initial_indent = indentation ,
203202 subsequent_indent = indentation ,
204203 )
205204
206- if _text :
207- _lines .extend (_text )
208- _lines .append ("" )
205+ if _wrapped_line :
206+ _wrapped_lines .extend (_wrapped_line )
207+ _wrapped_lines .append ("" )
209208
210209 with contextlib .suppress (IndexError ):
211- if not _lines [- 1 ] and not _lines [- 2 ]:
212- _lines .pop (- 1 )
210+ if not _wrapped_lines [- 1 ] and not _wrapped_lines [- 2 ]:
211+ _wrapped_lines .pop (- 1 )
213212
214- return _lines
213+ if (
214+ description [- len (indentation ) - 1 : - len (indentation )] == "\n "
215+ and description [- len (indentation ) - 2 : - len (indentation )] != "\n \n "
216+ ):
217+ _wrapped_lines .pop (- 1 )
218+
219+ return _wrapped_lines
215220
216221
217222def do_clean_url (url : str , indentation : str ) -> str :
@@ -479,13 +484,10 @@ def do_wrap_field_lists( # noqa: PLR0913
479484 text ,
480485 field_idx ,
481486 _idx ,
482- ). strip ()
487+ )
483488
484- if len (f"{ _field_name } { _field_body } " ) <= (wrap_length - len (indentation )):
485- if _field_body .startswith ("`" ) or not _field_body :
486- _field = f"{ _field_name } { _field_body } "
487- else :
488- _field = f"{ _field_name } { _field_body } "
489+ if len (f"{ _field_name } { _field_body } " ) <= (wrap_length - len (indentation )):
490+ _field = f"{ _field_name } { _field_body } "
489491 lines .append (f"{ indentation } { _field } " )
490492 else :
491493 lines .extend (
@@ -855,8 +857,10 @@ def _do_join_field_body(text, field_idx, idx):
855857 [_line .strip () for _line in _field_body .splitlines ()]
856858 ).strip ()
857859
858- if _field_body :
860+ if not _field_body . startswith ( "`" ) :
859861 _field_body = f" { _field_body } "
862+ if text [field_idx [idx ][1 ] : field_idx [idx ][1 ] + 1 ] == "\n " :
863+ _field_body = "\n "
860864
861865 return _field_body
862866
@@ -886,7 +890,7 @@ def _do_wrap_field(field_name, field_body, indentation, wrap_length):
886890 _subsequent = 2 * indentation
887891
888892 _wrapped_field = textwrap .wrap (
889- textwrap .dedent (f"{ field_name } { field_body . strip () } " ),
893+ textwrap .dedent (f"{ field_name } { field_body } " ),
890894 width = wrap_length ,
891895 initial_indent = indentation ,
892896 subsequent_indent = _subsequent ,
0 commit comments