Skip to content

https://github.com/jackdewinter/pymarkdown/issues/1679 - #1695

Merged
jackdewinter merged 2 commits into
mainfrom
issue-1679
Sep 16, 2026
Merged

jackdewinter merged 2 commits into
mainfrom
issue-1679

Conversation

@jackdewinter

@jackdewinter jackdewinter commented Sep 16, 2026 •

Copy link
Copy Markdown
Owner

Summary by Sourcery

Fix block parsing so table-like and link-reference list content is handled as ordinary list items without disrupting surrounding Markdown.

Bug Fixes:

  • Fix parsing of list items whose first content line resembles a table row, including cases following paragraphs and other block types.
  • Prevent list parsing from incorrectly consuming link reference definitions and preserve subsequent list items correctly.

Enhancements:

  • Add regression coverage for table-like list items and link reference definitions across surrounding Markdown block constructs.
  • Add parser diagnostics to aid investigation of block-stack and table requeue state.

Documentation:

  • Document the fix for issue 1679 in the changelog.

Tests:

  • Add extensive GFM regression tests covering table-like list content, link reference definitions, and list continuation behavior.

@sourcery-ai

sourcery-ai Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Fix GFM parsing regressions around table continuation and list items containing pipe characters by making parser stack/document requeue cleanup token-aware, preventing an unsafe list-token replacement, and adding extensive regression tests across surrounding block constructs.

Sequence diagram for token-aware table requeue cleanup

sequenceDiagram
    participant TableProcessor
    participant ParserState
    participant TokenStack
    participant TokenDocument

    TableProcessor->>ParserState: process_table_rows(...)
    TableProcessor->>TableProcessor: __prepare_for_requeue_reset_document_and_stack(...)
    TableProcessor->>TokenStack: Remove tokens beyond original_stack_depth
    alt stack was cleared below original depth
        TableProcessor->>TokenStack: Restore copy_of_token_stack
        TableProcessor->>TokenDocument: Remove trailing non-block-quote tokens
    else matching token was removed
        TableProcessor->>TokenDocument: Remove tokens through last_removed_token
    end
    TableProcessor-->>ParserState: Requeue with synchronized stack and document
Loading

Sequence diagram for safe list-item replacement

sequenceDiagram
    participant ListHandler
    participant ParserState
    participant TokenDocument

    ListHandler->>ParserState: __post_list_use_new_list_item(...)
    ListHandler->>TokenDocument: Check final token with is_list_start
    alt top-level list already ends with a list-start token
        ListHandler-->>ListHandler: Return without replacement
    else replacement is safe
        ListHandler->>ListHandler: Create NewListItemMarkdownToken
    end
Loading

File-Level Changes

Change Details Files
Adjust table continuation cleanup so requeued table parsing removes only the corresponding parser stack/document tokens.
  • Track the final removed stack token and whether the stack required a full reset.
  • Conditionally trim the token document to the matching token instead of always removing through the original depth.
  • Add parser-state, table-processing, and requeue diagnostics to trace stack/document depth and cleanup paths.
pymarkdown/general/parser_state.py
pymarkdown/general/tokenized_markdown.py
pymarkdown/leaf_blocks/table_block_continuation_helper.py
pymarkdown/leaf_blocks/table_block_processor.py
Prevent list parsing from replacing a list-start token when no container-level tokens are available.
  • Return early when the document already ends in a list-start token and a new container cannot be created.
pymarkdown/list_blocks/list_block_create_new_handler.py
Add broad GFM regression coverage for pipe-containing list items and list/reference-definition interactions.
  • Verify pipe text remains a list item rather than becoming a table across surrounding paragraphs, headings, thematic breaks, code blocks, HTML, link definitions, block quotes, and existing tables.
  • Verify reference definitions inside list items and subsequent list items produce the expected HTML and token streams.
test/test_markdown_extra.py
Refresh generated publication reports after the parser and test changes.
  • Update coverage, lint suppression, and test-result artifacts.
publish/coverage.json
publish/pylint_suppression.json
publish/test-results.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="pymarkdown/general/parser_state.py" line_range="411-417" />
<code_context>
             False,
         )

+        POGGER.debug(f"self.token_stack = {self.token_stack}")
+        POGGER.debug(
+            f"parser_state.original_stack_depth = {self.__original_stack_depth}"
+        )
+        POGGER.debug(f"self.token_document = {self.token_document}")
+        POGGER.debug(
+            f"parser_state.original_document_depth, = {self.__original_document_depth}"
+        )
+
</code_context>
<issue_to_address>
**nitpick (performance):** The new debug calls eagerly interpolate complete parser stacks and token documents into f-strings even when debug logging is disabled. Every parsed line therefore pays the cost of constructing potentially large string representations, degrading parser performance on large documents.

**Triggers:** During normal parsing with debug logging disabled, especially for documents with large token stacks or token documents.

**Suggested fix:** Use the logger's deferred `$` substitution interface instead of f-string interpolation.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment on lines +411 to +417
POGGER.debug(f"self.token_stack = {self.token_stack}")
POGGER.debug(
f"parser_state.original_stack_depth = {self.__original_stack_depth}"
)
POGGER.debug(f"self.token_document = {self.token_document}")
POGGER.debug(
f"parser_state.original_document_depth, = {self.__original_document_depth}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick (performance): The new debug calls eagerly interpolate complete parser stacks and token documents into f-strings even when debug logging is disabled. Every parsed line therefore pays the cost of constructing potentially large string representations, degrading parser performance on large documents.

Triggers: During normal parsing with debug logging disabled, especially for documents with large token stacks or token documents.

Suggested fix: Use the logger's deferred $ substitution interface instead of f-string interpolation.

@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Coverage

Coverage Report
FileStmtsMissBranchBrPartCoverMissing
__init__.py1000100% 
__main__.py3000100% 
api.py3300600100% 
application_configuration_helper.py21040100% 
application_logging.py850160100% 
file_scan_helper.py47301640100% 
main.py1950340100% 
my_application_properties_facade.py23000100% 
return_code_helper.py65060100% 
version.py3000100% 
block_quotes
   __init__.py0000100% 
   block_quote_count_helper.py2980760100% 
   block_quote_data.py7000100% 
   block_quote_non_fenced_helper.py2410700100% 
   block_quote_processor.py2990600100% 
coalesce
   __init__.py0000100% 
   coalesce_processor.py640240100% 
container_blocks
   __init__.py0000100% 
   container_block_leaf_processor.py62001560100% 
   container_block_nested_processor.py2290560100% 
   container_block_non_leaf_processor.py34501060100% 
   container_block_processor.py1840500100% 
   container_grab_bag.py3650540100% 
   container_helper.py990240100% 
   container_indices.py8000100% 
   parse_block_pass_properties.py28020100% 
extension_manager
   __init__.py0000100% 
   extension_impl.py12000100% 
   extension_manager.py1750340100% 
   extension_manager_constants.py3000100% 
   parser_extension.py10000100% 
extensions
   __init__.py0000100% 
   disallowed_raw_html.py370120100% 
   extended_autolinks.py2600820100% 
   extension_one.py19040100% 
   extension_token_types.py9000100% 
   front_matter_extension.py910180100% 
   front_matter_markdown_token.py60000100% 
   markdown_strikethrough.py10000100% 
   markdown_tables.py10000100% 
   pragma_token.py1740480100% 
   task_list_items.py52040100% 
general
   __init__.py0000100% 
   bad_tokenization_error.py3000100% 
   constants.py38000100% 
   main_presentation.py24060100% 
   parser_helper.py4220980100% 
   parser_logger.py670220100% 
   parser_state.py1790380100% 
   position_marker.py7000100% 
   requeue_line_info.py8000100% 
   source_providers.py500120100% 
   tab_helper.py2820640100% 
   tokenized_markdown.py49401280100% 
html_helpers
   __init__.py0000100% 
   html_helper.py33801220100% 
   html_raw_helper.py1450620100% 
inline
   __init__.py0000100% 
   emphasis_helper.py2140780100% 
   inline_autolink_helper.py710200100% 
   inline_backslash_helper.py490100100% 
   inline_backtick_helper.py2220500100% 
   inline_character_reference_helper.py1190180100% 
   inline_handler_helper.py3340760100% 
   inline_helper.py1200280100% 
   inline_line_end_helper.py1500340100% 
   inline_processor.py2020540100% 
   inline_request.py23000100% 
   inline_response.py15000100% 
   inline_tabified_text_block_helper.py940140100% 
   inline_text_block_helper.py2390640100% 
leaf_blocks
   __init__.py0000100% 
   atx_leaf_block_processor.py1670380100% 
   fenced_leaf_block_processor.py3970820100% 
   indented_leaf_block_processor.py2430480100% 
   leaf_block_helper.py2130580100% 
   leaf_block_processor.py670140100% 
   leaf_block_processor_paragraph.py1900360100% 
   setext_leaf_block_processor.py1000140100% 
   table_block_continuation_helper.py2980640100% 
   table_block_parse_helper.py1670640100% 
   table_block_processor.py1780360100% 
   table_block_tuple.py30000100% 
   thematic_leaf_block_processor.py1310380100% 
links
   __init__.py0000100% 
   link_create_helper.py1220260100% 
   link_helper_properties.py27000100% 
   link_parse_helper.py3870920100% 
   link_reference_definition_continuation_helper.py2340540100% 
   link_reference_definition_helper.py1810360100% 
   link_reference_definition_parse_helper.py810240100% 
   link_reference_info.py10000100% 
   link_reference_titles.py6000100% 
   link_reference_tuple.py9000100% 
   link_search_helper.py2360600100% 
list_blocks
   __init__.py0000100% 
   list_block_can_close_helper.py720180100% 
   list_block_create_new_handler.py3100580100% 
   list_block_pre_list_helper.py1080200100% 
   list_block_processor.py3160580100% 
   list_block_starts_helper.py1550420100% 
plugin_manager
   __init__.py0000100% 
   bad_plugin_error.py390180100% 
   bad_plugin_fix_error.py3000100% 
   fix_line_record.py6000100% 
   fix_token_record.py10000100% 
   found_plugin.py18000100% 
   plugin_details.py36000100% 
   plugin_manager.py55002380100% 
   plugin_modify_context.py6000100% 
   plugin_scan_context.py1230340100% 
   plugin_scan_failure.py18040100% 
   replace_tokens_record.py9000100% 
   rule_plugin.py67040100% 
plugins
   __init__.py0000100% 
   plugin_one.py41060100% 
   rule_md_001.py390140100% 
   rule_md_002.py33080100% 
   rule_md_003.py770220100% 
   rule_md_004.py640240100% 
   rule_md_005.py3200980100% 
   rule_md_006.py500220100% 
   rule_md_007.py1020380100% 
   rule_md_009.py980340100% 
   rule_md_010.py640160100% 
   rule_md_011.py39080100% 
   rule_md_012.py1220460100% 
   rule_md_013.py790200100% 
   rule_md_014.py25080100% 
   rule_md_018.py1160340100% 
   rule_md_019.py390160100% 
   rule_md_020.py420120100% 
   rule_md_021.py700260100% 
   rule_md_022.py800300100% 
   rule_md_023.py1500640100% 
   rule_md_024.py640180100% 
   rule_md_025.py440160100% 
   rule_md_026.py510180100% 
   rule_md_027.py53901980100% 
   rule_md_028.py400160100% 
   rule_md_029.py1050420100% 
   rule_md_030.py1040380100% 
   rule_md_031.py57501720100% 
   rule_md_032.py790300100% 
   rule_md_033.py700260100% 
   rule_md_034.py480220100% 
   rule_md_035.py550300100% 
   rule_md_036.py640160100% 
   rule_md_037.py1260440100% 
   rule_md_038.py270120100% 
   rule_md_039.py270120100% 
   rule_md_040.py15040100% 
   rule_md_041.py890340100% 
   rule_md_042.py16040100% 
   rule_md_043.py2010860100% 
   rule_md_044.py2200880100% 
   rule_md_045.py15040100% 
   rule_md_046.py930240100% 
   rule_md_047.py26080100% 
   rule_md_048.py400100100% 
   rule_md_049.py430140100% 
   rule_md_050.py430140100% 
   rule_md_051.py1830640100% 
   rule_md_053.py670260100% 
   rule_md_054.py510180100% 
   rule_md_059.py360120100% 
   rule_md_060.py47101480100% 
   rule_pml_100.py1000400100% 
   rule_pml_101.py620180100% 
   rule_pml_102.py670180100% 
plugins/utils
   __init__.py0000100% 
   container_token_manager.py1050420100% 
   leading_space_index_tracker.py1140240100% 
   list_tracker.py1010180100% 
tokens
   __init__.py0000100% 
   atx_heading_markdown_token.py820100100% 
   blank_line_markdown_token.py38040100% 
   block_quote_markdown_token.py1240220100% 
   container_markdown_token.py9000100% 
   email_autolink_markdown_token.py46020100% 
   emphasis_markdown_token.py63080100% 
   end_of_stream_token.py27000100% 
   fenced_code_block_markdown_token.py1480280100% 
   hard_break_markdown_token.py41020100% 
   html_block_markdown_token.py60080100% 
   html_items.py92040100% 
   image_start_markdown_token.py54040100% 
   indented_code_block_markdown_token.py770100100% 
   inline_code_span_markdown_token.py850120100% 
   inline_markdown_token.py9000100% 
   leaf_markdown_token.py17020100% 
   link_reference_definition_markdown_token.py1210160100% 
   link_start_markdown_token.py990180100% 
   list_start_markdown_token.py1070200100% 
   list_start_markdown_token_helper.py46080100% 
   markdown_token.py3490300100% 
   new_list_item_markdown_token.py650100100% 
   ordered_list_start_markdown_token.py15000100% 
   paragraph_markdown_token.py930140100% 
   raw_html_markdown_token.py58060100% 
   reference_markdown_token.py94080100% 
   setext_heading_markdown_token.py1040120100% 
   special_text_markdown_token.py28020100% 
   stack_token.py213000100% 
   table_markdown_tokens.py3850280100% 
   text_markdown_token.py2980680100% 
   thematic_break_markdown_token.py62080100% 
   token_types.py42000100% 
   unordered_list_start_markdown_token.py15000100% 
   uri_autolink_markdown_token.py640100100% 
transform_gfm
   __init__.py0000100% 
   transform_state.py89000100% 
   transform_to_gfm.py870200100% 
   transform_to_gfm_list_looseness.py2090760100% 
   transform_to_gfm_token_handlers.py55080100% 
transform_markdown
   __init__.py0000100% 
   markdown_transform_context.py26000100% 
   transform_block_quote.py1110260100% 
   transform_containers.py75502460100% 
   transform_list_block.py2870440100% 
   transform_new_list_item.py1000160100% 
   transform_to_markdown.py1440360100% 
TOTAL25056062600100% 

Test Execution

Tests Skipped Failures Errors Time
9871 28 💤 0 ❌ 0 🔥 6m 43s ⏱️

@codecov

codecov Bot commented Sep 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (a5244c8) to head (087d2e7).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1695   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          205       205           
  Lines        25026     25056   +30     
  Branches      3127      3130    +3     
=========================================
+ Hits         25026     25056   +30     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jackdewinter
jackdewinter merged commit 6010874 into main Sep 16, 2026
24 checks passed
@jackdewinter
jackdewinter deleted the issue-1679 branch November 1, 2026 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant