22from textwrap import dedent
33from 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" ,
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+
1726ESCAPE_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
127140def 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
135148def 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