Skip to content

Commit c0aa6de

Browse files
committed
identify example blocks in docstrings
1 parent 34be02a commit c0aa6de

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

pylsp/_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import logging
77
import os
88
import pathlib
9+
import re
910
import threading
1011

1112
import jedi
@@ -14,6 +15,7 @@
1415

1516
log = logging.getLogger(__name__)
1617

18+
EX_SNIPPET_RE = re.compile(r"\>\>\> .*(?:\r?\n(?!\r?\n).*)*")
1719

1820
def debounce(interval_s, keyed_by=None):
1921
"""Debounce calls to this function until interval_s seconds have passed."""
@@ -146,6 +148,9 @@ def format_docstring(contents):
146148
"""
147149
contents = contents.replace('\t', u'\u00A0' * 4)
148150
contents = contents.replace(' ', u'\u00A0' * 2)
151+
example_snippets = re.findall(EX_SNIPPET_RE, contents)
152+
for snippet in example_snippets:
153+
contents = contents.replace(snippet, f"```python\n{snippet}\n```")
149154
return contents
150155

151156

0 commit comments

Comments
 (0)