Open ShawnHymel opened 1 year ago
I had a quick solution, which I didn't put as a pull request as it seemed a bit hacky and I didn't check the tests, but for me it worked. I simply added 4 lines to the google processor Hope this helps in resolving the issue.
def _process(self, node: docspec.ApiObject):
if not node.docstring:
return
lines = []
current_lines: t.List[str] = []
in_codeblock = False
keyword = None
def _commit():
if keyword:
generate_sections_markdown(lines, {keyword: current_lines})
else:
lines.extend(current_lines)
current_lines.clear()
for line in node.docstring.content.split("\n"):
if line.lstrip().startswith("```"):
in_codeblock = not in_codeblock
current_lines.append(line)
continue
if in_codeblock:
current_lines.append(line)
continue
line = line.strip()
if line in self._keywords_map:
_commit()
keyword = self._keywords_map[line]
if keyword == 'Examples' or keyword == 'Example':
current_lines.append('```python')
continue
if keyword is None:
lines.append(line)
continue
for param_re in self._param_res:
param_match = param_re.match(line)
if param_match:
if "type" in param_match.groupdict():
current_lines.append("- `{param}` _{type}_ - {desc}".format(**param_match.groupdict()))
else:
current_lines.append("- `{param}` - {desc}".format(**param_match.groupdict()))
break
if not param_match:
current_lines.append(" {line}".format(line=line))
if keyword == 'Examples' or keyword == 'Example':
current_lines.append('```')
_commit()
node.docstring.content = "\n".join(lines)
Environment
Describe the bug
Using a Google-style code block retains its indentation and does not render correctly in markdown (VS Code and GitHub rendering).
Simple Python example (in src/module-test.py):
if name == "main": text = str_test("hello", 2) print(text)
module-test.md has the following:
Prints something to the screen and adds 'something' to the end.
Arguments:
in_str
Any - any stringnum
- Number of times to add 'something' at the end in order to test how this darn thing worksReturns:
str
- String with 'something' addedRaises:
Example:
How to use: