executablebooks / mdformat-myst

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

conlict with mdformat-footnote #23

Closed Freed-Wu closed 1 year ago

Freed-Wu commented 1 year ago

Describe the bug

Here is a footnote reference,[^1] and another.[^longnote]

[^1]: Here is the footnote.

[^longnote]: Here's one with multiple blocks.
  - repo: https://github.com/executablebooks/mdformat
    rev: 0.7.16
    hooks:
      - id: mdformat
        args:
          - --number
        additional_dependencies:
          - mdformat-myst
          - mdformat-footnote
mdformat......................................................................Failed
- hook id: mdformat
- exit code: 1

Traceback (most recent call last):
  File "/home/wzy/.cache/pre-commit/repoqvm3k01b/py_env-python3.10/bin/mdformat", line 8, in <module>
    sys.exit(run())
  File "/home/wzy/.cache/pre-commit/repoqvm3k01b/py_env-python3.10/lib/python3.10/site-packages/mdformat/__main__.py", line 8, in run
    exit_code = mdformat._cli.run(sys.argv[1:])
  File "/home/wzy/.cache/pre-commit/repoqvm3k01b/py_env-python3.10/lib/python3.10/site-packages/mdformat/_cli.py", line 74, in run
    formatted_str = mdformat.text(
  File "/home/wzy/.cache/pre-commit/repoqvm3k01b/py_env-python3.10/lib/python3.10/site-packages/mdformat/_api.py", line 37, in text
    rendering = mdit.render(md)
  File "/home/wzy/.cache/pre-commit/repoqvm3k01b/py_env-python3.10/lib/python3.10/site-packages/markdown_it/main.py", line 267, in render
    return self.renderer.render(self.parse(src, env), self.options, env)
  File "/home/wzy/.cache/pre-commit/repoqvm3k01b/py_env-python3.10/lib/python3.10/site-packages/markdown_it/main.py", line 252, in parse
    self.core.process(state)
  File "/home/wzy/.cache/pre-commit/repoqvm3k01b/py_env-python3.10/lib/python3.10/site-packages/markdown_it/parser_core.py", line 32, in process
    rule(state)
  File "/home/wzy/.cache/pre-commit/repoqvm3k01b/py_env-python3.10/lib/python3.10/site-packages/mdit_py_plugins/footnote/index.py", line 321, in footnote_tail
    tokens = refTokens[":" + foot_note["label"]]
KeyError: ':1'

However, in myst and pandoc, they are correct syntax:

https://pandoc.org/MANUAL.html#footnotes

https://myst-parser.readthedocs.io/en/latest/syntax/syntax.html?highlight=footnote#footnotes

Reproduce the bug

See above

List your environment

No response

welcome[bot] commented 1 year 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 1 year ago

Hey there!

Yes, mdformat-myst version v0.1.5 and older are not compatible with mdformat-footnote. These versions ship their own footnote support, so you don't need mdformat-footnote with them. This has now changed in master branch -- the next version of mdformat-myst will depend on and behave nicely with mdformat-footnote.

To fix the issue, you can simply omit the explicit mdformat-footnote dependency.

Freed-Wu commented 1 year ago

Thanks!