Skip to content

With markdown-tables enabled, character | in nested list causes crash #1706

Closed

Description

@pjljvandelaar

Prerequisites

  • Are you running the latest version of this application?
    • Tested with pymarkdownlnt 0.9.40.
  • Have you checked the Frequently Asked Questions document?
  • Have you simplified the bug report to the essential details?
    • Do you have a distinct command line to report?
    • Can you clearly state the configuration for this bug report?
    • Do you have a minimal document that highlights this bug?
    • Are any required files (configuration or Markdown document) attached to the issue?
      • No separate files needed: the document is 4 lines (inlined below) and the
        configuration is supplied entirely on the command line.
  • Did you perform a cursory search of other issues to look for related issues?

Bug Report

Bug Type

  • Assertion Failure
  • Documentation
  • Scan/Rule not working as expected
  • Fix/Rule not working as expected
  • Other

Description

With the markdown-tables extension enabled, scanning a document that contains a |
character anywhere inside a nested (sub-)list item aborts the entire run with
BadTokenizationError, caused by ValueError: list.index(x): x not in list in
ParserState.mark_start_information.

The same | at the top list level parses fine. The | does not have to form a table:
the crash also occurs when the pipe is backslash-escaped or inside a code span, which
suggests that table-start detection fires before those cases are considered and then
leaves the container stack inconsistent.

Command Line

pymarkdown --enable-extensions markdown-tables scan repro.md

With --stack-trace to obtain the traceback below:

pymarkdown --stack-trace --enable-extensions markdown-tables scan repro.md

Configuration

No configuration file is used. The run is performed in an empty directory so that no
.pymarkdown* or pyproject.toml file is picked up. The only configuration is the
command-line flag --enable-extensions markdown-tables.

The equivalent pyproject.toml configuration reproduces it identically:

[tool.pymarkdown]
extensions.markdown-tables.enabled = true

Markdown Document

repro.md:

# T

- a
    - b | c

Expected Behavior

The document is scanned without an unhandled error. - b | c is an ordinary paragraph
inside a nested list item and is not a table (there is no delimiter row), so it should
be treated as text.

Observed Behavior

Unexpected Error(BadTokenizationError): An unhandled error occurred processing the document.

Traceback with --stack-trace:

Traceback (most recent call last):
  File ".../pymarkdown/general/tokenized_markdown.py", line 136, in __transform
    first_pass_results = self.__parse_blocks_pass(do_add_end_of_stream_token)
  File ".../pymarkdown/general/tokenized_markdown.py", line 210, in __parse_blocks_pass
    ) = self.__parse_blocks_pass_next_line(
  File ".../pymarkdown/general/tokenized_markdown.py", line 277, in __parse_blocks_pass_next_line
    ) = self.__main_pass_did_not_start_close(
  File ".../pymarkdown/general/tokenized_markdown.py", line 401, in __main_pass_did_not_start_close
    ) = ContainerBlockProcessor.parse_line_for_container_blocks(
  File ".../pymarkdown/container_blocks/container_block_processor.py", line 135, in parse_line_for_container_blocks
    ) = ContainerBlockProcessor.__setup(
  File ".../pymarkdown/container_blocks/container_block_processor.py", line 58, in __setup
    position_marker = ContainerBlockProcessor.__prepare_container_start_variables(
  File ".../pymarkdown/container_blocks/container_block_processor.py", line 254, in __prepare_container_start_variables
    parser_state.mark_start_information(position_marker)
  File ".../pymarkdown/general/parser_state.py", line 449, in mark_start_information
    self.__x1_token_index = self.token_document.index(self.__x1_token)
ValueError: list.index(x): x not in list

The above exception was the direct cause of the following exception:

...
  File ".../pymarkdown/general/tokenized_markdown.py", line 157, in __transform
    raise BadTokenizationError(
        "An unhandled error occurred processing the document."
    ) from this_exception
pymarkdown.general.bad_tokenization_error.BadTokenizationError: An unhandled error occurred processing the document.

Environment

pymarkdownlnt 0.9.40
Python 3.14.7 (MSC v.1944 64 bit (AMD64))
Windows 11

Additional Context

Variants tested

All runs use --enable-extensions markdown-tables unless stated otherwise.

Input Result
- a / - b | c (4-space nested) crash
- a / - b | c (2-space nested) crash
- a / - b \\| c (backslash-escaped pipe) crash
- a / - b `X | Y` c (pipe inside code span) crash
1. a / 1. b | c (ordered list) crash
> - a / > - b | c (list inside block quote) crash
- a / - b | c (pipe at top level only) ok
- a / blank line / - b | c ok
- a / - b | c ok
- a / - b | c with markdown-tables disabled ok

Workarounds

  • Replace | with |.
  • Insert a blank line before the nested list (this changes the rendering to a loose list).
  • Disable markdown-tables — not viable for projects that contain real tables and rely
    on plugins.md013.tables = false, since those table rows then get reported as MD013
    line-length violations.

Secondary request: name the failing file

scan -r stops at the first unhandled error and the Unexpected Error(...) message does
not mention which document was being processed. Locating the offending file in a
repository-wide scan required bisecting the corpus. Including the file name (and, if
possible, the line number) in that message would make such reports much easier to produce.

Activity

  1. jackdewinter commented on Oct 31, 2026

    @jackdewinter
    Owner

    Most of this was taken care of with Issue 1679, but added extra tests.

  2. added a commit that references this issue on Nov 1, 2026
  3. jackdewinter commented on Nov 1, 2026

    @jackdewinter
    Owner

    this will be in the next release.

  4. jackdewinter commented on Nov 15, 2026

    @jackdewinter
    Owner

    can you please verify that this is fixed from your end?

  5. pjljvandelaar commented on Nov 16, 2026

    @pjljvandelaar
    Author

    How can I instruct my builder in pyproject.toml to use the beta version with this solution?
    I am currently using:

    lint = [
        "codespell>=2.4",
        "pyright>=1.1",
        "pymarkdownlnt>=0.9",
        "import-linter>=2.15",
    ]
    

    Or, where can I download the beta version of the next release?

  6. glennmatthews commented on Nov 16, 2026

    @glennmatthews

    If I understand things correctly v0.9.42 has the fixes for this issue - trying it out locally I don't see this crash any more, FWIW.

  7. pjljvandelaar commented on Nov 16, 2026

    @pjljvandelaar
    Author

    Bug solved with 0.9.42!

  8. jackdewinter commented on Nov 17, 2026

    @jackdewinter
    Owner

    verified as no longer reproducible. closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions