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

https://github.com/jackdewinter/pymarkdown/issues/1267 #1279

Merged
merged 13 commits into from
Dec 8, 2024

Conversation

jackdewinter
Copy link
Owner

@jackdewinter jackdewinter commented Dec 8, 2024

#1267

Summary by Sourcery

Enhance markdown transformation logic to better handle nested block quotes and lists, addressing parsing issues. Fix a bug related to task lists causing errors in rule MD018. Update tests to cover new scenarios and ensure robustness.

Bug Fixes:

  • Fix issue with task lists causing an error in rule MD018 by adjusting the handling of task list tokens.

Enhancements:

  • Improve handling of block quotes and list tokens in the markdown transformation process to ensure correct parsing and rendering.

Tests:

  • Add new test cases to cover various scenarios involving nested block quotes and lists, ensuring proper handling of complex markdown structures.
  • Introduce a test for issue 1267 to verify that task lists do not cause errors in rule MD018.

Copy link
Contributor

sourcery-ai bot commented Dec 8, 2024

Reviewer's Guide by Sourcery

This pull request fixes several issues related to block quotes, lists, and fenced code blocks in the PyMarkdown parser. The main changes involve improving the handling of container blocks, fixing assertion errors, and addressing edge cases in the parsing logic.

Class diagram for MarkdownToken modifications

classDiagram
    class MarkdownToken {
        +is_task_list() bool
        +is_front_matter() bool
        +is_text() bool
        +_token_task_list : str
        +_token_front_matter : str
        +_token_block_quote : str
        +_token_unordered_list_start : str
        +_token_ordered_list_start : str
        +_token_new_list_item : str
    }
    note for MarkdownToken "Added is_task_list method and reorganized token constants"
Loading

Class diagram for TransformContainers modifications

classDiagram
    class TransformContainers {
        +__apply_line_transformation(..., ort: List<MarkdownToken>) str
        +__abcd(..., container_line: str) Optional<str>
        +__abcd_remaining(..., container_line: str, prefix: Optional<str>) Optional<str>
        +__abcd_final_list_second_half(...)
        +__abcd_final(...)
        +__apply_container_transformation_inner(..., ort: List<MarkdownToken>) str
        +__adjust_for_list(..., ort: List<MarkdownToken>) Tuple<str, bool>
    }
    note for TransformContainers "Added ort parameter and __abcd_remaining method"
Loading

Class diagram for InlineProcessor modifications

classDiagram
    class InlineProcessor {
        +__parse_inline_tracker_start(lsi_tracker: LeadingSpaceIndexTracker, token: MarkdownToken) void
        +__parse_inline_tracker_per_token(lsi_tracker: LeadingSpaceIndexTracker, token: MarkdownToken) void
        +parse_inline(coalesced_results: List<MarkdownToken>, ...) void
    }
    note for InlineProcessor "Refactored parse_inline method with new helper methods"
Loading

File-Level Changes

Change Details Files
Refactored container block handling logic to fix assertion errors and improve parsing
  • Added new __abcd_remaining method to handle remaining tokens in container transformations
  • Modified __apply_line_transformation to pass original removed tokens
  • Updated container index assertions and checks in transform_containers.py
  • Fixed leading space calculations in container block processing
pymarkdown/transform_markdown/transform_containers.py
pymarkdown/container_blocks/container_helper.py
Enhanced inline processing and token handling
  • Split inline tracker logic into separate methods for better organization
  • Added task list token handling in markdown_token.py
  • Fixed column number calculation in code block parsing
pymarkdown/inline/inline_processor.py
pymarkdown/tokens/markdown_token.py
Fixed test cases and improved test coverage
  • Added new test cases for block quotes and lists
  • Updated existing tests to handle new edge cases
  • Removed skipped tests that are now passing
  • Added test for task list handling (Issue 1267)
test/test_markdown_extra.py
test/rules/test_md018.py
test/rules/test_md031.py
test/nested_three/test_markdown_nested_three_block_unordered_block.py
test/nested_three/test_markdown_nested_three_ordered_block_block.py

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.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a 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. You can also use
    this command to specify where the summary should be inserted.

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

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @jackdewinter - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -179,7 +179,7 @@ def remove_last_leading_space(self) -> Optional[str]:
extracted_text = self.__leading_spaces
self.__leading_spaces = None
else:
extracted_text = self.__leading_spaces[last_separator_index:]
extracted_text = self.__leading_spaces[last_separator_index + 1 :]
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: Add bounds check for last_separator_index before adding 1

If last_separator_index is -1, adding 1 will still result in an invalid index. Consider adding a bounds check or handling this edge case explicitly.

Comment on lines 28 to 29
- Fixed remaining assert issues, leaving fixes that produce valid
Markdown, but not the intended Markdown.
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: The description of Issue 1274's fix could be clearer

Consider rewording to clarify what was fixed and what remains to be addressed. For example: 'Fixed assert issues while preserving Markdown validity, though some cases may still not produce the exact intended Markdown output.'

Suggested change
- Fixed remaining assert issues, leaving fixes that produce valid
Markdown, but not the intended Markdown.
- Fixed assert issues while preserving Markdown validity, though some cases may still not produce the exact intended Markdown output.

Copy link

codecov bot commented Dec 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (72523ad) to head (2b26b0f).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1279   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          191       191           
  Lines        21390     21393    +3     
  Branches      2751      2751           
=========================================
+ Hits         21390     21393    +3     

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

@jackdewinter jackdewinter merged commit f6c9f66 into main Dec 8, 2024
15 checks passed
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