Skip to content

Commit 5d2b0c8

Browse files
authored
1 parent 8a8fb01 commit 5d2b0c8

File tree

11 files changed

+1703
-49
lines changed

11 files changed

+1703
-49
lines changed

newdocs/src/changelog.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
### Added
66

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

910
### Fixed
1011

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

3034
### Changed
3135

publish/coverage.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
"projectName": "pymarkdown",
33
"reportSource": "pytest",
44
"branchLevel": {
5-
"totalMeasured": 5023,
6-
"totalCovered": 5023
5+
"totalMeasured": 5035,
6+
"totalCovered": 5035
77
},
88
"lineLevel": {
9-
"totalMeasured": 19960,
10-
"totalCovered": 19960
9+
"totalMeasured": 19986,
10+
"totalCovered": 19986
1111
}
1212
}
1313

publish/pylint_suppression.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"pymarkdown/block_quotes/block_quote_data.py": {},
2121
"pymarkdown/block_quotes/block_quote_non_fenced_helper.py": {
2222
"too-few-public-methods": 1,
23-
"too-many-arguments": 6,
24-
"too-many-locals": 1
23+
"too-many-arguments": 7,
24+
"too-many-locals": 3
2525
},
2626
"pymarkdown/block_quotes/block_quote_processor.py": {
2727
"too-many-arguments": 5,
@@ -502,8 +502,8 @@
502502
"too-many-instance-attributes": 25,
503503
"too-many-public-methods": 4,
504504
"too-few-public-methods": 39,
505-
"too-many-arguments": 231,
506-
"too-many-locals": 42,
505+
"too-many-arguments": 232,
506+
"too-many-locals": 44,
507507
"chained-comparison": 1,
508508
"too-many-boolean-expressions": 2,
509509
"protected-access": 25,

publish/test-results.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -868,10 +868,10 @@
868868
},
869869
{
870870
"name": "test.nested_three.test_markdown_nested_three_ordered_block_block",
871-
"totalTests": 48,
871+
"totalTests": 51,
872872
"failedTests": 0,
873873
"errorTests": 0,
874-
"skippedTests": 0,
874+
"skippedTests": 1,
875875
"elapsedTimeInMilliseconds": 0
876876
},
877877
{
@@ -948,10 +948,10 @@
948948
},
949949
{
950950
"name": "test.nested_three.test_markdown_nested_three_unordered_block_ordered",
951-
"totalTests": 47,
951+
"totalTests": 52,
952952
"failedTests": 0,
953953
"errorTests": 0,
954-
"skippedTests": 0,
954+
"skippedTests": 6,
955955
"elapsedTimeInMilliseconds": 0
956956
},
957957
{
@@ -1364,7 +1364,7 @@
13641364
},
13651365
{
13661366
"name": "test.rules.test_md031",
1367-
"totalTests": 110,
1367+
"totalTests": 126,
13681368
"failedTests": 0,
13691369
"errorTests": 0,
13701370
"skippedTests": 0,
@@ -1620,10 +1620,10 @@
16201620
},
16211621
{
16221622
"name": "test.test_markdown_extra",
1623-
"totalTests": 163,
1623+
"totalTests": 180,
16241624
"failedTests": 0,
16251625
"errorTests": 0,
1626-
"skippedTests": 1,
1626+
"skippedTests": 2,
16271627
"elapsedTimeInMilliseconds": 0
16281628
},
16291629
{

pymarkdown/block_quotes/block_quote_non_fenced_helper.py

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def handle_non_fenced_code_section(
152152

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

155-
# pylint: disable=too-many-arguments
155+
# pylint: disable=too-many-arguments,too-many-locals
156156
@staticmethod
157157
def __handle_non_fenced_code_section_no_requeue(
158158
parser_state: ParserState,
@@ -182,6 +182,7 @@ def __handle_non_fenced_code_section_no_requeue(
182182
found_bq_stack_token = cast(
183183
BlockQuoteStackToken, parser_state.token_stack[stack_index]
184184
)
185+
is_not_blank_line = bool(line_to_parse.strip(Constants.ascii_whitespace))
185186

186187
BlockQuoteNonFencedHelper.__do_block_quote_leading_spaces_adjustments(
187188
parser_state,
@@ -195,10 +196,12 @@ def __handle_non_fenced_code_section_no_requeue(
195196
extra_consumed_whitespace,
196197
container_level_tokens,
197198
original_line,
199+
is_not_blank_line,
200+
position_marker,
198201
)
199202
POGGER.debug("text_removed_by_container=[$]", removed_text)
200203
POGGER.debug("removed_text=[$]", removed_text)
201-
if line_to_parse.strip(Constants.ascii_whitespace):
204+
if is_not_blank_line:
202205
return (
203206
line_to_parse,
204207
start_index,
@@ -221,9 +224,9 @@ def __handle_non_fenced_code_section_no_requeue(
221224
leaf_tokens,
222225
)
223226

224-
# pylint: enable=too-many-arguments
227+
# pylint: enable=too-many-arguments,too-many-locals
225228

226-
# pylint: disable=too-many-arguments
229+
# pylint: disable=too-many-arguments,too-many-locals
227230
@staticmethod
228231
def __do_block_quote_leading_spaces_adjustments(
229232
parser_state: ParserState,
@@ -237,6 +240,8 @@ def __do_block_quote_leading_spaces_adjustments(
237240
extra_consumed_whitespace: Optional[int],
238241
container_level_tokens: List[MarkdownToken],
239242
original_line: str,
243+
is_not_blank_line: bool,
244+
position_marker: PositionMarker,
240245
) -> None:
241246
POGGER.debug("__hbqs>>removed_text>>:$:<", removed_text)
242247
POGGER.debug("__hbqs>>container_start_bq_count>>$", container_start_bq_count)
@@ -287,13 +292,17 @@ def __do_block_quote_leading_spaces_adjustments(
287292
POGGER.debug("dbqlsa>>special_case>>$", special_case)
288293

289294
BlockQuoteNonFencedHelper.__do_block_quote_leading_spaces_adjustments_adjust_bleading(
295+
parser_state,
290296
found_bq_stack_token,
291297
tabbed_removed_text,
292298
adjusted_removed_text,
293299
special_case,
300+
is_not_blank_line,
301+
stack_index,
302+
position_marker,
294303
)
295304

296-
# pylint: enable=too-many-arguments
305+
# pylint: enable=too-many-arguments,too-many-locals
297306

298307
@staticmethod
299308
def __handle_normal_blank_line(
@@ -329,18 +338,6 @@ def __handle_normal_blank_line(
329338
requeue_line_info and requeue_line_info.lines_to_requeue
330339
), "No handling of requeuing available here."
331340

332-
# KLUDGE!
333-
if (
334-
len(parser_state.token_stack) == 3
335-
and parser_state.token_stack[1].is_list
336-
and parser_state.token_stack[2].is_block_quote
337-
):
338-
list_token = cast(
339-
ListStartMarkdownToken,
340-
parser_state.token_stack[1].matching_markdown_token,
341-
)
342-
list_token.add_leading_spaces("")
343-
344341
return True, leaf_tokens
345342

346343
# pylint: disable=too-many-arguments
@@ -491,12 +488,17 @@ def __block_quote_start_adjust(
491488
original_start_index -= indent_delta
492489
return original_start_index
493490

491+
# pylint: disable=too-many-arguments
494492
@staticmethod
495493
def __do_block_quote_leading_spaces_adjustments_adjust_bleading(
494+
parser_state: ParserState,
496495
found_bq_stack_token: BlockQuoteStackToken,
497496
tabbed_removed_text: Optional[str],
498497
adjusted_removed_text: str,
499498
special_case: bool,
499+
is_not_blank_line: bool,
500+
stack_index: int,
501+
position_marker: PositionMarker,
500502
) -> None:
501503
assert (
502504
found_bq_stack_token.matching_markdown_token is not None
@@ -521,9 +523,29 @@ def __do_block_quote_leading_spaces_adjustments_adjust_bleading(
521523
POGGER.debug(
522524
"dbqlsa>>leading_text_index>>$", block_quote_token.leading_text_index
523525
)
526+
if not is_not_blank_line:
527+
assert parser_state.token_stack[stack_index] == found_bq_stack_token
528+
found_list_stack_index = 0
529+
for search_index in range(stack_index, 0, -1):
530+
if (
531+
parser_state.token_stack[search_index].is_list
532+
and not found_list_stack_index
533+
):
534+
found_list_stack_index = search_index
535+
if found_list_stack_index:
536+
list_token = cast(
537+
ListStartMarkdownToken,
538+
parser_state.token_stack[
539+
found_list_stack_index
540+
].matching_markdown_token,
541+
)
542+
if position_marker.line_number != list_token.line_number:
543+
list_token.add_leading_spaces("")
524544

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

547+
# pylint: enable=too-many-arguments
548+
527549
# pylint: disable=too-many-arguments
528550
@staticmethod
529551
def __adjust_2(

pymarkdown/block_quotes/block_quote_processor.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -676,9 +676,6 @@ def __handle_existing_block_quote_fenced_special_part_two(
676676
block_markdown_token = cast(
677677
BlockQuoteMarkdownToken, block_stack_token.matching_markdown_token
678678
)
679-
list_markdown_token = cast(
680-
ListStartMarkdownToken, embedded_list_stack_token.matching_markdown_token
681-
)
682679
assert parser_state.original_line_to_parse is not None
683680
character_after_list = parser_state.original_line_to_parse[
684681
start_index : embedded_list_stack_token.indent_level
@@ -703,7 +700,6 @@ def __handle_existing_block_quote_fenced_special_part_two(
703700
block_markdown_token.weird_kludge_one += 1
704701
else:
705702
block_markdown_token.weird_kludge_one = 1
706-
list_markdown_token.add_leading_spaces("")
707703
block_quote_data = BlockQuoteData(
708704
block_quote_data.current_count + 1, block_quote_data.stack_count
709705
)

pymarkdown/transform_markdown/transform_containers.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ def __adjust_for_list_end(
492492
removed_tokens,
493493
applied_leading_spaces_to_start_of_container_line,
494494
previous_token,
495+
container_line,
495496
):
496497
previous_block_token = cast(BlockQuoteMarkdownToken, previous_token)
497498
assert (
@@ -527,6 +528,7 @@ def __adjust_for_list_check(
527528
removed_tokens: List[MarkdownToken],
528529
applied_leading_spaces_to_start_of_container_line: bool,
529530
previous_token: MarkdownToken,
531+
container_line: str,
530532
) -> bool:
531533
if not token_stack[-1].is_new_list_item:
532534
return (
@@ -556,11 +558,52 @@ def __adjust_for_list_check(
556558
)
557559
POGGER.debug(f"new_list_item_adjust:{new_list_item_adjust}")
558560

561+
if new_list_item_adjust:
562+
new_list_item_adjust = TransformContainers.__look_for_container_prefix(
563+
token_stack, container_line
564+
)
559565
return (
560566
token_stack[-1].line_number != previous_token.line_number
561567
and new_list_item_adjust
562568
)
563569

570+
@staticmethod
571+
def __look_for_container_prefix(
572+
token_stack: List[MarkdownToken], container_line: str
573+
) -> bool:
574+
end_stack_index = len(token_stack) - 1
575+
assert token_stack[end_stack_index].is_new_list_item
576+
end_stack_index -= 1
577+
assert token_stack[end_stack_index].is_list_start
578+
579+
stack_index = 0
580+
container_lindex_index, _ = ParserHelper.collect_while_spaces_verified(
581+
container_line, 0
582+
)
583+
is_tracking = True
584+
while stack_index < end_stack_index and is_tracking:
585+
if token_stack[stack_index].is_block_quote_start: # pragma: no cover
586+
is_tracking = ParserHelper.is_character_at_index(
587+
container_line, container_lindex_index, ">"
588+
)
589+
container_lindex_index, _ = ParserHelper.collect_while_spaces_verified(
590+
container_line, container_lindex_index + 1
591+
)
592+
stack_index += 1
593+
assert is_tracking
594+
list_token = cast(ListStartMarkdownToken, token_stack[end_stack_index])
595+
if not list_token.is_unordered_list_start:
596+
container_lindex_index, numeric_prefix = (
597+
ParserHelper.collect_while_one_of_characters_verified(
598+
container_line, container_lindex_index, "0123456789"
599+
)
600+
)
601+
assert len(numeric_prefix) > 0
602+
is_tracking = ParserHelper.is_character_at_index(
603+
container_line, container_lindex_index, list_token.list_start_sequence
604+
)
605+
return not is_tracking
606+
564607
@staticmethod
565608
def __find_last_block_quote_on_stack(token_stack: List[MarkdownToken]) -> int:
566609
POGGER.debug(" looking for nested block start")
@@ -738,7 +781,11 @@ def __apply_primary_transformation_adjust_container_line(
738781
last_container_token_index
739782
]
740783
else:
741-
prev_list_token = cast(ListStartMarkdownToken, token_stack[-1])
784+
prev_list_token = (
785+
cast(ListStartMarkdownToken, token_stack[-2])
786+
if token_stack[-1].is_new_list_item
787+
else cast(ListStartMarkdownToken, token_stack[-1])
788+
)
742789
assert (
743790
prev_list_token.leading_spaces is not None
744791
), "Leading spaces must be defined by this point."

0 commit comments

Comments
 (0)