executablebooks / mdformat-myst

Mdformat plugin for MyST compatibility
MIT License
7 stars 2 forks source link

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

Closed landure closed 2 years ago

landure commented 2 years ago

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

welcome[bot] commented 2 years ago

Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.
If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).
Welcome to the EBP community! :tada:

welcome[bot] commented 2 years ago

Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.
If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).
Welcome to the EBP community! :tada:

hukkin commented 2 years ago

Thanks this is an issue with the mdformat-myst plugin so I've transferred the issue.

I'm fairly sure this will be fixed by https://github.com/executablebooks/mdformat-myst/pull/12

landure commented 2 years ago

Hi, i confirm #12 fix the issue.

hukkin commented 2 years ago

Fixed in https://github.com/executablebooks/mdformat-myst/pull/12