Skip to content

Commit 683d1cc

Browse files
committed
Skip line parsing in some sections
1 parent 4d8d55c commit 683d1cc

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

docstring_to_markdown/google.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from textwrap import dedent
33
from typing import Dict, List, Union
44

5-
_GOOGLE_SECTIONS: List[str] = [
5+
# All possible sections in Google style docstrings
6+
SECTION_HEADERS: List[str] = [
67
"Args",
78
"Returns",
89
"Raises",
@@ -14,6 +15,14 @@
1415
"Todo",
1516
]
1617

18+
# These sections will not be parsed as a list of arguments/return values/etc
19+
PLAIN_TEXT_SECTIONS: List[str] = [
20+
"Examples",
21+
"Example",
22+
"Note",
23+
"Todo",
24+
]
25+
1726
ESCAPE_RULES = {
1827
# Avoid Markdown in magic methods or filenames like __init__.py
1928
r"__(?P<text>\S+)__": r"\_\_\g<text>\_\_",
@@ -30,6 +39,10 @@ def __init__(self, name: str, content: str) -> None:
3039
def _parse(self, content: str) -> None:
3140
content = content.rstrip("\n")
3241

42+
if self.name in PLAIN_TEXT_SECTIONS:
43+
self.content = dedent(content)
44+
return
45+
3346
parts = []
3447
cur_part = []
3548

@@ -125,15 +138,15 @@ def as_markdown(self) -> str:
125138

126139

127140
def is_section(line: str) -> bool:
128-
for section in _GOOGLE_SECTIONS:
141+
for section in SECTION_HEADERS:
129142
if re.search(r"{}:".format(section), line):
130143
return True
131144

132145
return False
133146

134147

135148
def looks_like_google(value: str) -> bool:
136-
for section in _GOOGLE_SECTIONS:
149+
for section in SECTION_HEADERS:
137150
if re.search(r"{}:\n".format(section), value):
138151
return True
139152

0 commit comments

Comments
 (0)