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

Include directive cannot parse combinations of manual-integer-numbered and automatically-numbered footnotes #1025

Open
b-kamphorst opened this issue Feb 13, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@b-kamphorst
Copy link

What version of myst-parser are you using?

4.0.0

What version dependencies are you using?

Python==3.12.8
docutils==0.21.2
sphinx==8.1.3

Operating system: WSL2 on Windows, Ubuntu distribution.

What operating system are you using?

Linux

Describe the Bug

I have a markdown document with two footnotes as in the example in the v4.0.1 documentation. One of the footnotes has anchor [^3], one has anchor [^myref].

When parsing a markdown document with footnotes, this parses into a fine HTML. However, if that markdown is included in a .rst file, then the following exception occurs:

Exception occurred:
  File "/usr/local/lib/python3.12/site-packages/myst_parser/mdit_to_docutils/transforms.py", line 136, in apply
    for _, footnote in sorted(footnotes, key=_sort_key):
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '<' not supported between instances of 'str' and 'int'

May be related to #1024.

Expected Behavior

I would expect that the combination of manually-numbered and automatically-numbered footnotes poses no issue even when the markdown file is included in a .rst file. The result should be the same as the parsed markdown file.

To Reproduce

conf.py

extensions = [
    "myst_parser",
]

index.rst

.. include:: test.md
   :parser: myst_parser.sphinx_

test.md

# Example

Following the footnote example follows [the example in the v4.0.1 documentation](https://myst-parser.readthedocs.io/en/v4.0.1/syntax/typography.html#footnotes).

- This is a manually-numbered footnote reference.[^3]
- This is an auto-numbered footnote reference.[^myref]

[^myref]: This is an auto-numbered footnote definition.
[^3]: This is a manually-numbered footnote definition.

Then just run sphinx-build . public. The output will show

Exception occurred:
  File "/usr/local/lib/python3.12/site-packages/myst_parser/mdit_to_docutils/transforms.py", line 136, in apply
    for _, footnote in sorted(footnotes, key=_sort_key):
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '<' not supported between instances of 'str' and 'int'
The full traceback has been saved in /tmp/sphinx-err-896d819_.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
Click for full traceback.
# Platform:         linux; (Linux-5.15.167.4-microsoft-standard-WSL2-x86_64-with-glibc2.36)
# Sphinx version:   8.1.3
# Python version:   3.12.8 (CPython)
# Docutils version: 0.21.2
# Jinja2 version:   3.1.5
# Pygments version: 2.19.1

# Last messages:
#   building [mo]: targets for 0 po files that are out of date
#   writing output...
#   
#   building [html]: targets for 1 source files that are out of date
#   updating environment:
#   0 added, 1 changed, 0 removed
#   
#   reading sources... [100%]
#   index
#   

# Loaded extensions:
#   sphinx.ext.mathjax (8.1.3)
#   alabaster (1.0.0)
#   sphinxcontrib.applehelp (2.0.0)
#   sphinxcontrib.devhelp (2.0.0)
#   sphinxcontrib.htmlhelp (2.1.0)
#   sphinxcontrib.serializinghtml (2.0.0)
#   sphinxcontrib.qthelp (2.0.0)
#   myst_parser (4.0.0)

# Traceback:
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/sphinx/cmd/build.py", line 514, in build_main
    app.build(args.force_all, args.filenames)
  File "/usr/local/lib/python3.12/site-packages/sphinx/application.py", line 381, in build
    self.builder.build_update()
  File "/usr/local/lib/python3.12/site-packages/sphinx/builders/__init__.py", line 358, in build_update
    self.build(
  File "/usr/local/lib/python3.12/site-packages/sphinx/builders/__init__.py", line 385, in build
    updated_docnames = set(self.read())
                           ^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/sphinx/builders/__init__.py", line 502, in read
    self._read_serial(docnames)
  File "/usr/local/lib/python3.12/site-packages/sphinx/builders/__init__.py", line 567, in _read_serial
    self.read_doc(docname)
  File "/usr/local/lib/python3.12/site-packages/sphinx/builders/__init__.py", line 630, in read_doc
    publisher.publish()
  File "/usr/local/lib/python3.12/site-packages/docutils/core.py", line 234, in publish
    self.document = self.reader.read(self.source, self.parser,
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/sphinx/io.py", line 106, in read
    self.parse()
  File "/usr/local/lib/python3.12/site-packages/docutils/readers/__init__.py", line 76, in parse
    self.parser.parse(self.input, document)
  File "/usr/local/lib/python3.12/site-packages/sphinx/parsers.py", line 85, in parse
    self.statemachine.run(inputlines, document, inliner=self.inliner)
  File "/usr/local/lib/python3.12/site-packages/docutils/parsers/rst/states.py", line 169, in run
    results = StateMachineWS.run(self, input_lines, input_offset,
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/docutils/statemachine.py", line 233, in run
    context, next_state, result = self.check_line(
                                  ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/docutils/statemachine.py", line 445, in check_line
    return method(match, context, next_state)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/docutils/parsers/rst/states.py", line 2357, in explicit_markup
    nodelist, blank_finish = self.explicit_construct(match)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/docutils/parsers/rst/states.py", line 2369, in explicit_construct
    return method(self, expmatch)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/docutils/parsers/rst/states.py", line 2106, in directive
    return self.run_directive(
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/docutils/parsers/rst/states.py", line 2156, in run_directive
    result = directive_instance.run()
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/sphinx/directives/other.py", line 437, in run
    return super().run()
           ^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/docutils/parsers/rst/directives/misc.py", line 209, in run
    document.transformer.apply_transforms()
  File "/usr/local/lib/python3.12/site-packages/docutils/transforms/__init__.py", line 182, in apply_transforms
    transform.apply(**kwargs)
  File "/usr/local/lib/python3.12/site-packages/myst_parser/mdit_to_docutils/transforms.py", line 136, in apply
    for _, footnote in sorted(footnotes, key=_sort_key):
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '<' not supported between instances of 'str' and 'int'

The expected output can be produced by removing all content of index.rst and running the command again. It is then contained in public/test.html.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant