|
110 | 110 |
|
111 | 111 | # This is the regex used to find URL links: |
112 | 112 | # |
113 | | -# (`{{2}}|`\w[\w. :\n]*|\.\. _?[\w. :]+|')? is used to find in-line links that |
| 113 | +# (__ |`{{2}}|`\w[\w. :\n]*|\.\. _?[\w. :]+|')? is used to find in-line links that |
114 | 114 | # should remain on a single line even if it exceeds the wrap length. |
| 115 | +# __ is used to find to underscores followed by a single space. |
| 116 | +# This finds patterns like: __ https://sw.kovidgoyal.net/kitty/graphics-protocol/ |
| 117 | +# |
115 | 118 | # `{{2}} is used to find two back-tick characters. |
116 | 119 | # This finds patterns like: ``http://www.example.com`` |
117 | 120 | # |
118 | | -# `\w[\w. :#\n]* matches the back-tick character immediately followed by one |
119 | | -# letter, then followed by any number of letters, periods, spaces, colons, |
| 121 | +# `\w[a-zA-Z0-9. :#\n]* matches the back-tick character immediately followed by one |
| 122 | +# letter, then followed by any number of letters, numbers, periods, spaces, colons, |
120 | 123 | # hash marks or newlines. |
121 | 124 | # This finds patterns like: `Link text <https://domain.invalid/>`_ |
122 | 125 | # |
|
137 | 140 | # (//)? matches two forward slashes zero or one time. |
138 | 141 | # (\S*) matches any non-whitespace character between zero and infinity times. |
139 | 142 | # >? matches the character > between zero and one times. |
140 | | -URL_REGEX = rf"(`{{2}}|`\w[\w. :#\n]*|\.\. _?[\w. :]+|')?<?({URL_PATTERNS}):(\ |
141 | | -//)?(\S*)>?" |
| 143 | +URL_REGEX = ( |
| 144 | + rf"(__ |`{{2}}|`\w[\w :#\n]*[.|\.\. _?[\w. :]+|')?<?" |
| 145 | + rf"({URL_PATTERNS}):(\//)?(\S*)>?" |
| 146 | +) |
142 | 147 |
|
143 | 148 | URL_SKIP_REGEX = rf"({URL_PATTERNS}):(/){{0,2}}(``|')" |
144 | 149 | """The regex used to ignore found hyperlinks. |
@@ -195,9 +200,11 @@ def description_to_list( |
195 | 200 | initial_indent=indentation, |
196 | 201 | subsequent_indent=indentation, |
197 | 202 | ) |
| 203 | + |
198 | 204 | if _text: |
199 | 205 | _lines.extend(_text) |
200 | 206 | _lines.append("") |
| 207 | + |
201 | 208 | with contextlib.suppress(IndexError): |
202 | 209 | if not _lines[-1] and not _lines[-2]: |
203 | 210 | _lines.pop(-1) |
@@ -530,9 +537,8 @@ def do_wrap_urls( |
530 | 537 | wrap_length, |
531 | 538 | ) |
532 | 539 | ) |
533 | | - |
534 | 540 | with contextlib.suppress(IndexError): |
535 | | - if not _lines[-1]: |
| 541 | + if not text[_url[0] - len(indentation) - 2] == "\n" and not _lines[-1]: |
536 | 542 | _lines.pop(-1) |
537 | 543 |
|
538 | 544 | # Add the URL. |
|
0 commit comments