Repository navigation
https://github.com/jackdewinter/pymarkdown/issues/1274 - #1278
Conversation
Reviewer's Guide by SourceryThe changes focus on fixing issues with fenced code blocks (FCB) in Markdown parsing, particularly around indentation and column position reporting. The main changes involve correcting text token positions within code blocks and removing assert statements while preserving functionality that produces valid Markdown. Class diagram for LeadingSpaceIndexTracker and MarkdownToken changesclassDiagram
class LeadingSpaceIndexTracker {
+open_container(token: MarkdownToken)
+track_since_last_non_end_token(token: MarkdownToken)
+have_any_registered_container_ends() bool
+process_container_end(token: MarkdownToken)
+get_tokens_block_quote_bleading_space_index(text_token: TextMarkdownToken) int
+get_tokens_list_leading_space_index(text_token: TextMarkdownToken) int
}
class MarkdownToken {
+is_block_quote_start bool
+is_list_start bool
+is_block_quote_end bool
+is_list_end bool
+is_end_token bool
+is_end_of_stream bool
}
LeadingSpaceIndexTracker --> MarkdownToken : uses
note for LeadingSpaceIndexTracker "Handles tracking of leading spaces in Markdown tokens"
note for MarkdownToken "Represents a token in Markdown parsing"
Class diagram for FencedCodeBlockMarkdownToken changesclassDiagram
class FencedCodeBlockMarkdownToken {
+fence_character char
+fence_count int
+extracted_text string
+pre_extracted_text string
+text_after_extracted_text string
+pre_text_after_extracted_text string
+extracted_whitespace string
+extracted_whitespace_before_info_string string
+position_marker PositionMarker
+is_fenced_code_block bool
}
class PositionMarker {
+line_number int
+index_number int
+text_to_parse string
+index_indent int
}
FencedCodeBlockMarkdownToken --> PositionMarker : uses
note for FencedCodeBlockMarkdownToken "Represents a fenced code block in Markdown"
note for PositionMarker "Tracks position information for tokens"
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey @jackdewinter - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| - Fixed issue with Md027 not reporting line numbers properly within | ||
| anything except the first paragraph. | ||
| - [Issue 1272](https://github.com/jackdewinter/pymarkdown/issues/1272) | ||
| - Parsing of the FCB in certain cases was off, as was the text token |
There was a problem hiding this comment.
suggestion: Consider expanding the abbreviation 'FCB' for clarity
While experienced developers might be familiar with this abbreviation, expanding it on first use would improve documentation clarity for all readers.
| - Parsing of the FCB in certain cases was off, as was the text token | |
| - Parsing of the Fenced Code Block (FCB) in certain cases was off, as was the text token |
| # pylint: enable=too-many-arguments, too-many-boolean-expressions | ||
|
|
||
| @staticmethod | ||
| def __abcd_remaining( |
There was a problem hiding this comment.
issue (complexity): Consider refactoring the whitespace handling logic into smaller, well-named methods with clear responsibilities
The __abcd_remaining method introduces unnecessary complexity. Consider refactoring to:
- Rename methods to describe their purpose:
def __adjust_container_leading_spaces(self, ...) -> Optional[str]: # instead of __abcd
def __process_remaining_whitespace(self, ...) -> Optional[str]: # instead of __abcd_remaining- Extract whitespace handling logic:
def __get_token_leading_spaces(token: MarkdownToken) -> Tuple[List[str], int]:
if token.is_block_quote_start:
bq_token = cast(BlockQuoteMarkdownToken, token)
spaces = bq_token.bleading_spaces.split("\n")
return spaces, len(spaces) if bq_token.weird_kludge_five else 0
else:
list_token = cast(ListStartMarkdownToken, token)
spaces = list_token.leading_spaces.split("\n")
return spaces, len(spaces)
def __process_remaining_whitespace(self, removed_tokens: List[MarkdownToken],
removed_indices: List[int],
container_line: str,
prefix: str) -> str:
while removed_tokens:
spaces, space_count = self.__get_token_leading_spaces(removed_tokens[0])
if not self.__validate_token_spacing(spaces, space_count, removed_indices[0]):
break
removed_tokens.pop(0)
removed_indices.pop(0)
return "" if container_line.startswith(prefix) else prefixThis improves readability while maintaining the same functionality and edge case handling.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1278 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 191 191
Lines 21362 21390 +28
Branches 2744 2751 +7
=========================================
+ Hits 21362 21390 +28 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Work to eliminate asserts, leaving Fixes for Md031 that produce the wrong Markdown.
Summary by Sourcery
Fix issues with Md031 rule handling of fenced code blocks and resolve remaining assert issues. Enhance inline processing logic for better handling of leading spaces and container tokens. Add new test cases to improve coverage and ensure correct behavior.
Bug Fixes:
Enhancements:
Tests: