Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdewinter authored Jul 8, 2024
1 parent 8a8fb01 commit 5d2b0c8
Show file tree
Hide file tree
Showing 11 changed files with 1,703 additions and 49 deletions.
6 changes: 5 additions & 1 deletion newdocs/src/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

### Added

- None
- [Issue 818](https://github.com/jackdewinter/pymarkdown/issues/818)
- Adding Fix Mode for Md031.

### Fixed

Expand All @@ -26,6 +27,9 @@
the block quote to close
- [Issue 1127](https://github.com/jackdewinter/pymarkdown/issues/1127)
- rehydration can be wrong with indented blocks in Bq-List-Bq
- [Issue 1130](https://github.com/jackdewinter/pymarkdown/issues/1130)
- check for adding extra line to list with blank line in *-List-Bq
not flexible enough

### Changed

Expand Down
8 changes: 4 additions & 4 deletions publish/coverage.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"projectName": "pymarkdown",
"reportSource": "pytest",
"branchLevel": {
"totalMeasured": 5023,
"totalCovered": 5023
"totalMeasured": 5035,
"totalCovered": 5035
},
"lineLevel": {
"totalMeasured": 19960,
"totalCovered": 19960
"totalMeasured": 19986,
"totalCovered": 19986
}
}

8 changes: 4 additions & 4 deletions publish/pylint_suppression.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"pymarkdown/block_quotes/block_quote_data.py": {},
"pymarkdown/block_quotes/block_quote_non_fenced_helper.py": {
"too-few-public-methods": 1,
"too-many-arguments": 6,
"too-many-locals": 1
"too-many-arguments": 7,
"too-many-locals": 3
},
"pymarkdown/block_quotes/block_quote_processor.py": {
"too-many-arguments": 5,
Expand Down Expand Up @@ -502,8 +502,8 @@
"too-many-instance-attributes": 25,
"too-many-public-methods": 4,
"too-few-public-methods": 39,
"too-many-arguments": 231,
"too-many-locals": 42,
"too-many-arguments": 232,
"too-many-locals": 44,
"chained-comparison": 1,
"too-many-boolean-expressions": 2,
"protected-access": 25,
Expand Down
14 changes: 7 additions & 7 deletions publish/test-results.json
Original file line number Diff line number Diff line change
Expand Up @@ -868,10 +868,10 @@
},
{
"name": "test.nested_three.test_markdown_nested_three_ordered_block_block",
"totalTests": 48,
"totalTests": 51,
"failedTests": 0,
"errorTests": 0,
"skippedTests": 0,
"skippedTests": 1,
"elapsedTimeInMilliseconds": 0
},
{
Expand Down Expand Up @@ -948,10 +948,10 @@
},
{
"name": "test.nested_three.test_markdown_nested_three_unordered_block_ordered",
"totalTests": 47,
"totalTests": 52,
"failedTests": 0,
"errorTests": 0,
"skippedTests": 0,
"skippedTests": 6,
"elapsedTimeInMilliseconds": 0
},
{
Expand Down Expand Up @@ -1364,7 +1364,7 @@
},
{
"name": "test.rules.test_md031",
"totalTests": 110,
"totalTests": 126,
"failedTests": 0,
"errorTests": 0,
"skippedTests": 0,
Expand Down Expand Up @@ -1620,10 +1620,10 @@
},
{
"name": "test.test_markdown_extra",
"totalTests": 163,
"totalTests": 180,
"failedTests": 0,
"errorTests": 0,
"skippedTests": 1,
"skippedTests": 2,
"elapsedTimeInMilliseconds": 0
},
{
Expand Down
56 changes: 39 additions & 17 deletions pymarkdown/block_quotes/block_quote_non_fenced_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def handle_non_fenced_code_section(

# pylint: enable=too-many-arguments, too-many-locals

# pylint: disable=too-many-arguments
# pylint: disable=too-many-arguments,too-many-locals
@staticmethod
def __handle_non_fenced_code_section_no_requeue(
parser_state: ParserState,
Expand Down Expand Up @@ -182,6 +182,7 @@ def __handle_non_fenced_code_section_no_requeue(
found_bq_stack_token = cast(
BlockQuoteStackToken, parser_state.token_stack[stack_index]
)
is_not_blank_line = bool(line_to_parse.strip(Constants.ascii_whitespace))

BlockQuoteNonFencedHelper.__do_block_quote_leading_spaces_adjustments(
parser_state,
Expand All @@ -195,10 +196,12 @@ def __handle_non_fenced_code_section_no_requeue(
extra_consumed_whitespace,
container_level_tokens,
original_line,
is_not_blank_line,
position_marker,
)
POGGER.debug("text_removed_by_container=[$]", removed_text)
POGGER.debug("removed_text=[$]", removed_text)
if line_to_parse.strip(Constants.ascii_whitespace):
if is_not_blank_line:
return (
line_to_parse,
start_index,
Expand All @@ -221,9 +224,9 @@ def __handle_non_fenced_code_section_no_requeue(
leaf_tokens,
)

# pylint: enable=too-many-arguments
# pylint: enable=too-many-arguments,too-many-locals

# pylint: disable=too-many-arguments
# pylint: disable=too-many-arguments,too-many-locals
@staticmethod
def __do_block_quote_leading_spaces_adjustments(
parser_state: ParserState,
Expand All @@ -237,6 +240,8 @@ def __do_block_quote_leading_spaces_adjustments(
extra_consumed_whitespace: Optional[int],
container_level_tokens: List[MarkdownToken],
original_line: str,
is_not_blank_line: bool,
position_marker: PositionMarker,
) -> None:
POGGER.debug("__hbqs>>removed_text>>:$:<", removed_text)
POGGER.debug("__hbqs>>container_start_bq_count>>$", container_start_bq_count)
Expand Down Expand Up @@ -287,13 +292,17 @@ def __do_block_quote_leading_spaces_adjustments(
POGGER.debug("dbqlsa>>special_case>>$", special_case)

BlockQuoteNonFencedHelper.__do_block_quote_leading_spaces_adjustments_adjust_bleading(
parser_state,
found_bq_stack_token,
tabbed_removed_text,
adjusted_removed_text,
special_case,
is_not_blank_line,
stack_index,
position_marker,
)

# pylint: enable=too-many-arguments
# pylint: enable=too-many-arguments,too-many-locals

@staticmethod
def __handle_normal_blank_line(
Expand Down Expand Up @@ -329,18 +338,6 @@ def __handle_normal_blank_line(
requeue_line_info and requeue_line_info.lines_to_requeue
), "No handling of requeuing available here."

# KLUDGE!
if (
len(parser_state.token_stack) == 3
and parser_state.token_stack[1].is_list
and parser_state.token_stack[2].is_block_quote
):
list_token = cast(
ListStartMarkdownToken,
parser_state.token_stack[1].matching_markdown_token,
)
list_token.add_leading_spaces("")

return True, leaf_tokens

# pylint: disable=too-many-arguments
Expand Down Expand Up @@ -491,12 +488,17 @@ def __block_quote_start_adjust(
original_start_index -= indent_delta
return original_start_index

# pylint: disable=too-many-arguments
@staticmethod
def __do_block_quote_leading_spaces_adjustments_adjust_bleading(
parser_state: ParserState,
found_bq_stack_token: BlockQuoteStackToken,
tabbed_removed_text: Optional[str],
adjusted_removed_text: str,
special_case: bool,
is_not_blank_line: bool,
stack_index: int,
position_marker: PositionMarker,
) -> None:
assert (
found_bq_stack_token.matching_markdown_token is not None
Expand All @@ -521,9 +523,29 @@ def __do_block_quote_leading_spaces_adjustments_adjust_bleading(
POGGER.debug(
"dbqlsa>>leading_text_index>>$", block_quote_token.leading_text_index
)
if not is_not_blank_line:
assert parser_state.token_stack[stack_index] == found_bq_stack_token
found_list_stack_index = 0
for search_index in range(stack_index, 0, -1):
if (
parser_state.token_stack[search_index].is_list
and not found_list_stack_index
):
found_list_stack_index = search_index
if found_list_stack_index:
list_token = cast(
ListStartMarkdownToken,
parser_state.token_stack[
found_list_stack_index
].matching_markdown_token,
)
if position_marker.line_number != list_token.line_number:
list_token.add_leading_spaces("")

POGGER.debug("__hbqs>>bq>>$", block_quote_token)

# pylint: enable=too-many-arguments

# pylint: disable=too-many-arguments
@staticmethod
def __adjust_2(
Expand Down
4 changes: 0 additions & 4 deletions pymarkdown/block_quotes/block_quote_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,9 +676,6 @@ def __handle_existing_block_quote_fenced_special_part_two(
block_markdown_token = cast(
BlockQuoteMarkdownToken, block_stack_token.matching_markdown_token
)
list_markdown_token = cast(
ListStartMarkdownToken, embedded_list_stack_token.matching_markdown_token
)
assert parser_state.original_line_to_parse is not None
character_after_list = parser_state.original_line_to_parse[
start_index : embedded_list_stack_token.indent_level
Expand All @@ -703,7 +700,6 @@ def __handle_existing_block_quote_fenced_special_part_two(
block_markdown_token.weird_kludge_one += 1
else:
block_markdown_token.weird_kludge_one = 1
list_markdown_token.add_leading_spaces("")
block_quote_data = BlockQuoteData(
block_quote_data.current_count + 1, block_quote_data.stack_count
)
Expand Down
49 changes: 48 additions & 1 deletion pymarkdown/transform_markdown/transform_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ def __adjust_for_list_end(
removed_tokens,
applied_leading_spaces_to_start_of_container_line,
previous_token,
container_line,
):
previous_block_token = cast(BlockQuoteMarkdownToken, previous_token)
assert (
Expand Down Expand Up @@ -527,6 +528,7 @@ def __adjust_for_list_check(
removed_tokens: List[MarkdownToken],
applied_leading_spaces_to_start_of_container_line: bool,
previous_token: MarkdownToken,
container_line: str,
) -> bool:
if not token_stack[-1].is_new_list_item:
return (
Expand Down Expand Up @@ -556,11 +558,52 @@ def __adjust_for_list_check(
)
POGGER.debug(f"new_list_item_adjust:{new_list_item_adjust}")

if new_list_item_adjust:
new_list_item_adjust = TransformContainers.__look_for_container_prefix(
token_stack, container_line
)
return (
token_stack[-1].line_number != previous_token.line_number
and new_list_item_adjust
)

@staticmethod
def __look_for_container_prefix(
token_stack: List[MarkdownToken], container_line: str
) -> bool:
end_stack_index = len(token_stack) - 1
assert token_stack[end_stack_index].is_new_list_item
end_stack_index -= 1
assert token_stack[end_stack_index].is_list_start

stack_index = 0
container_lindex_index, _ = ParserHelper.collect_while_spaces_verified(
container_line, 0
)
is_tracking = True
while stack_index < end_stack_index and is_tracking:
if token_stack[stack_index].is_block_quote_start: # pragma: no cover
is_tracking = ParserHelper.is_character_at_index(
container_line, container_lindex_index, ">"
)
container_lindex_index, _ = ParserHelper.collect_while_spaces_verified(
container_line, container_lindex_index + 1
)
stack_index += 1
assert is_tracking
list_token = cast(ListStartMarkdownToken, token_stack[end_stack_index])
if not list_token.is_unordered_list_start:
container_lindex_index, numeric_prefix = (
ParserHelper.collect_while_one_of_characters_verified(
container_line, container_lindex_index, "0123456789"
)
)
assert len(numeric_prefix) > 0
is_tracking = ParserHelper.is_character_at_index(
container_line, container_lindex_index, list_token.list_start_sequence
)
return not is_tracking

@staticmethod
def __find_last_block_quote_on_stack(token_stack: List[MarkdownToken]) -> int:
POGGER.debug(" looking for nested block start")
Expand Down Expand Up @@ -738,7 +781,11 @@ def __apply_primary_transformation_adjust_container_line(
last_container_token_index
]
else:
prev_list_token = cast(ListStartMarkdownToken, token_stack[-1])
prev_list_token = (
cast(ListStartMarkdownToken, token_stack[-2])
if token_stack[-1].is_new_list_item
else cast(ListStartMarkdownToken, token_stack[-1])
)
assert (
prev_list_token.leading_spaces is not None
), "Leading spaces must be defined by this point."
Expand Down
Loading

0 comments on commit 5d2b0c8

Please sign in to comment.