Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

markdown: _uniform_outdent fails for empty text #535

Closed
martingabelmann opened this issue Apr 5, 2023 · 1 comment · Fixed by #537
Closed

markdown: _uniform_outdent fails for empty text #535

martingabelmann opened this issue Apr 5, 2023 · 1 comment · Fixed by #537

Comments

@martingabelmann
Copy link

Problem Description

Short: pdoc fails for empty markdown codeblocks.

We use jupyter-nbconvert to convert Jupyter notebooks into markdown and embed them as examples into the pdoc documentation. This is why empty codeblocks may appear in our markdown, since empty Jupyter input cells are converted into empty code blocks... With pdoc-13.0.1 this worked flawlessly but seemed to got broken by any of the changes towards pdoc-13.1.0 (I suspect in the course of #525).

Steps to reproduce the behavior:

  1. add empty code block to markdown docs
  2. run pdoc
Traceback (most recent call last):
  File "/home/martin/.local/lib/python3.10/site-packages/pdoc/render_helpers.py", line 177, in to_html
    return pdoc.markdown2.markdown(  # type: ignore
  File "/home/martin/.local/lib/python3.10/site-packages/pdoc/markdown2/__init__.py", line 175, in markdown
    use_file_vars=use_file_vars, cli=cli).convert(text)
  File "/home/martin/.local/lib/python3.10/site-packages/pdoc/markdown2/__init__.py", line 360, in convert
    text = self._do_fenced_code_blocks(text)
  File "/home/martin/.local/lib/python3.10/site-packages/pdoc/markdown2/__init__.py", line 2098, in _do_fenced_code_blocks
    return self._fenced_code_block_re.sub(self._fenced_code_block_sub, text)
  File "/home/martin/.local/lib/python3.10/site-packages/pdoc/markdown2/__init__.py", line 2094, in _fenced_code_block_sub
    return self._code_block_sub(match, is_fenced_code_block=True)
  File "/home/martin/.local/lib/python3.10/site-packages/pdoc/markdown2/__init__.py", line 1994, in _code_block_sub
    return self._code_block_with_lexer_sub(codeblock, leading_indent, lexer, is_fenced_code_block)
  File "/home/martin/.local/lib/python3.10/site-packages/pdoc/markdown2/__init__.py", line 2043, in _code_block_with_lexer_sub
    _, codeblock = self._uniform_outdent(codeblock, max_outdent=leading_indent)
  File "/home/martin/.local/lib/python3.10/site-packages/pdoc/markdown2/__init__.py", line 2621, in _uniform_outdent
    outdent = min(i for i in whitespace if i is not None)
ValueError: min() arg is an empty sequence

System Information

pdoc: 13.1.0
Python: 3.10.10
Platform: Linux-6.2.9-arch1-1-x86_64-with-glibc2.37

Fix

I was able to fix it by adding a

        if not text:
            return text, text

at the top of the definition of _uniform_outdent in pdoc/markdown2/__init__.py. The result looks good to me, though I'm not familiar with the pdoc codebase and don't know whether this might break other stuff....

@mhils
Copy link
Member

mhils commented Apr 5, 2023

Thanks! This seems to be a regression in markdown2, I'll file a bug upstream. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants