Skip to content

Uncatched IndexError at mdformat_myst/_directives.py", line 104, in parse_opts_and_content #16

@landure

Description

@landure

Describe the problem

Using a fresh install of mdformat-myst (mdformat 0.7.11 (mdformat_frontmatter: 0.4.1, mdformat_myst: 0.1.4, mdformat_tables: 0.4.1)) on a complex and broken md file (see steps to reproduce bellow) throw this exception:

raceback (most recent call last):
  File "/home/biapy/.local/bin/mdformat", line 8, in <module>
    sys.exit(run())
  File "/home/biapy/.local/lib/python3.9/site-packages/mdformat/__main__.py", line 8, in run
    exit_code = mdformat._cli.run(sys.argv[1:])
  File "/home/biapy/.local/lib/python3.9/site-packages/mdformat/_cli.py", line 74, in run
    formatted_str = mdformat.text(
  File "/home/biapy/.local/lib/python3.9/site-packages/mdformat/_api.py", line 29, in text
    rendering = mdit.render(md)
  File "/home/biapy/.local/lib/python3.9/site-packages/markdown_it/main.py", line 275, in render
    return self.renderer.render(self.parse(src, env), self.options, env)
  File "/home/biapy/.local/lib/python3.9/site-packages/mdformat/renderer/__init__.py", line 56, in render
    return self.render_tree(tree, options, env, finalize=finalize)
  File "/home/biapy/.local/lib/python3.9/site-packages/mdformat/renderer/__init__.py", line 90, in render_tree
    text = tree.render(render_context)
  File "/home/biapy/.local/lib/python3.9/site-packages/mdformat/renderer/_tree.py", line 11, in render
    text = renderer(self, context)
  File "/home/biapy/.local/lib/python3.9/site-packages/mdformat/renderer/_context.py", line 48, in render_children
    return separator.join(child.render(context) for child in node.children)
  File "/home/biapy/.local/lib/python3.9/site-packages/mdformat/renderer/_context.py", line 48, in <genexpr>
    return separator.join(child.render(context) for child in node.children)
  File "/home/biapy/.local/lib/python3.9/site-packages/mdformat/renderer/_tree.py", line 11, in render
    text = renderer(self, context)
  File "/home/biapy/.local/lib/python3.9/site-packages/mdformat_myst/_directives.py", line 64, in fence
    code_block = format_directive_content(code_block)
  File "/home/biapy/.local/lib/python3.9/site-packages/mdformat_myst/_directives.py", line 75, in format_directive_content
    parse_result = parse_opts_and_content(raw_content)
  File "/home/biapy/.local/lib/python3.9/site-packages/mdformat_myst/_directives.py", line 104, in parse_opts_and_content
    line = lines.pop(0)
IndexError: pop from empty list

Link to your repository or website

No response

Steps to reproduce

Running this command with additions-to-a-default-ubuntu-install.md:

~/.local/bin/mdformat  'additions-to-a-default-ubuntu-install.md'

The version of Python you're using

3.9.7

Your operating system

Lubuntu 21.10

Versions of your packages

No response

Additional context

The markdown is partially generated using Clipboard 2 Markdown and copy pasting content from Compléments à l'installation d'Ubuntu

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions