Skip to content

Traceback when formatting an empty directive #24

@paugier

Description

@paugier

Describe the bug

Formatting an empty directive seems broken. For example formatting this

```{graphviz} ../figs/undo-simple.dot
```

leads to this:

Traceback (most recent call last):
  File "/home/pierre/.cache/pypoetry/virtualenvs/mercurial-jupyterbook-MIlaqlFz-py3.10/bin/mdformat", line 8, in <module>
    sys.exit(run())
  File "/home/pierre/.cache/pypoetry/virtualenvs/mercurial-jupyterbook-MIlaqlFz-py3.10/lib/python3.10/site-packages/mdformat/__main__.py", line 8, in run
    exit_code = mdformat._cli.run(sys.argv[1:])
  File "/home/pierre/.cache/pypoetry/virtualenvs/mercurial-jupyterbook-MIlaqlFz-py3.10/lib/python3.10/site-packages/mdformat/_cli.py", line 74, in run
    formatted_str = mdformat.text(
  File "/home/pierre/.cache/pypoetry/virtualenvs/mercurial-jupyterbook-MIlaqlFz-py3.10/lib/python3.10/site-packages/mdformat/_api.py", line 37, in text
    rendering = mdit.render(md)
  File "/home/pierre/.cache/pypoetry/virtualenvs/mercurial-jupyterbook-MIlaqlFz-py3.10/lib/python3.10/site-packages/markdown_it/main.py", line 275, in render
    return self.renderer.render(self.parse(src, env), self.options, env)
  File "/home/pierre/.cache/pypoetry/virtualenvs/mercurial-jupyterbook-MIlaqlFz-py3.10/lib/python3.10/site-packages/mdformat/renderer/__init__.py", line 57, in render
    return self.render_tree(tree, options, env, finalize=finalize)
  File "/home/pierre/.cache/pypoetry/virtualenvs/mercurial-jupyterbook-MIlaqlFz-py3.10/lib/python3.10/site-packages/mdformat/renderer/__init__.py", line 91, in render_tree
    text = tree.render(render_context)
  File "/home/pierre/.cache/pypoetry/virtualenvs/mercurial-jupyterbook-MIlaqlFz-py3.10/lib/python3.10/site-packages/mdformat/renderer/_tree.py", line 11, in render
    text = renderer(self, context)
  File "/home/pierre/.cache/pypoetry/virtualenvs/mercurial-jupyterbook-MIlaqlFz-py3.10/lib/python3.10/site-packages/mdformat/renderer/_context.py", line 50, in render_children
    return separator.join(out for out in render_outputs if out)
  File "/home/pierre/.cache/pypoetry/virtualenvs/mercurial-jupyterbook-MIlaqlFz-py3.10/lib/python3.10/site-packages/mdformat/renderer/_context.py", line 50, in <genexpr>
    return separator.join(out for out in render_outputs if out)
  File "/home/pierre/.cache/pypoetry/virtualenvs/mercurial-jupyterbook-MIlaqlFz-py3.10/lib/python3.10/site-packages/mdformat/renderer/_context.py", line 49, in <genexpr>
    render_outputs = (child.render(context) for child in node.children)
  File "/home/pierre/.cache/pypoetry/virtualenvs/mercurial-jupyterbook-MIlaqlFz-py3.10/lib/python3.10/site-packages/mdformat/renderer/_tree.py", line 11, in render
    text = renderer(self, context)
  File "/home/pierre/.cache/pypoetry/virtualenvs/mercurial-jupyterbook-MIlaqlFz-py3.10/lib/python3.10/site-packages/mdformat_myst/_directives.py", line 64, in fence
    code_block = format_directive_content(code_block)
  File "/home/pierre/.cache/pypoetry/virtualenvs/mercurial-jupyterbook-MIlaqlFz-py3.10/lib/python3.10/site-packages/mdformat_myst/_directives.py", line 75, in format_directive_content
    parse_result = parse_opts_and_content(raw_content)
  File "/home/pierre/.cache/pypoetry/virtualenvs/mercurial-jupyterbook-MIlaqlFz-py3.10/lib/python3.10/site-packages/mdformat_myst/_directives.py", line 104, in parse_opts_and_content
    line = lines.pop(0)
IndexError: pop from empty list

Reproduce the bug

Format a file with an empty directive...

List your environment

> jupyter-book --version
Jupyter Book      : 0.13.2
External ToC      : 0.3.1
MyST-Parser       : 0.15.2
MyST-NB           : 0.13.2
Sphinx Book Theme : 0.3.3
Jupyter-Cache     : 0.4.3
NbClient          : 0.5.13

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions