Skip to content

Commit

Permalink
#13 : Further added variations on 237 and 238 with and without enough…
Browse files Browse the repository at this point in the history
… space to qualify.
  • Loading branch information
jackdewinter committed Jul 5, 2021
1 parent bc4c8d2 commit 9d3f1bb
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 14 deletions.
3 changes: 1 addition & 2 deletions issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@
- same as these, but with an extra level of list or block

if time 270, 271, 237, 238
- with enough space
- with not enough space
- with list item
- start with blank
- list starts after bq starts
- varying spaces between bqs
- no space between bq and following list

## Priority 3 - Like To Solve in next 3 m

Expand Down
66 changes: 56 additions & 10 deletions pymarkdown/container_block_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ def parse_line_for_container_blocks(
container_level_tokens.extend(leaf_tokens)
return container_level_tokens, line_to_parse, None

POGGER.debug("this_bq_count>>$", this_bq_count)
POGGER.debug("stack_bq_count>>$", stack_bq_count)
# POGGER.debug(">>avoid_block_starts>>$", avoid_block_starts)
# POGGER.debug(">>did_process>>$", did_process)

Expand Down Expand Up @@ -161,6 +163,8 @@ def parse_line_for_container_blocks(
">>requeuing lines after looking for ordered list start. returning."
)
return None, None, requeue_line_info
POGGER.debug("this_bq_count>>$", this_bq_count)
POGGER.debug("stack_bq_count>>$", stack_bq_count)

(
did_process,
Expand Down Expand Up @@ -190,6 +194,8 @@ def parse_line_for_container_blocks(
">>requeuing lines after looking for unordered list start. returning."
)
return None, None, requeue_line_info
POGGER.debug("this_bq_count>>$", this_bq_count)
POGGER.debug("stack_bq_count>>$", stack_bq_count)

# POGGER.debug("last_block_quote_index>>$", last_block_quote_index)
# POGGER.debug("indices>>$", end_container_indices)
Expand All @@ -210,6 +216,8 @@ def parse_line_for_container_blocks(
new_position_marker = PositionMarker(
position_marker.line_number, start_index, line_to_parse
)
POGGER.debug("this_bq_count>>$", this_bq_count)
POGGER.debug("stack_bq_count>>$", stack_bq_count)
(
line_to_parse,
leaf_tokens,
Expand All @@ -228,6 +236,8 @@ def parse_line_for_container_blocks(
avoid_block_starts,
)
# POGGER.debug_with_visible_whitespace("text>>$>>", line_to_parse)
POGGER.debug("this_bq_count>>$", this_bq_count)
POGGER.debug("stack_bq_count>>$", stack_bq_count)

# POGGER.debug("olist->container_level_tokens->$", container_level_tokens)
# POGGER.debug("removed_chars_at_start>>>$", removed_chars_at_start)
Expand All @@ -237,10 +247,10 @@ def parse_line_for_container_blocks(
POGGER.debug(">>>>>>>>$<<<<<<<<<<", line_to_parse)
return container_level_tokens, line_to_parse, None

# POGGER.debug_with_visible_whitespace(
# ">>__process_list_in_progress>>$>>",
# line_to_parse,
# )
POGGER.debug_with_visible_whitespace(
">>__process_list_in_progress>>$>>",
line_to_parse,
)
(
did_process,
line_to_parse,
Expand All @@ -254,19 +264,23 @@ def parse_line_for_container_blocks(
container_level_tokens,
extracted_whitespace,
)
# POGGER.debug_with_visible_whitespace(
# ">>__process_list_in_progress>>$>>", line_to_parse
# )
POGGER.debug_with_visible_whitespace(
">>__process_list_in_progress>>$>>", line_to_parse
)
POGGER.debug("container_start_bq_count>>$", container_start_bq_count)
POGGER.debug("this_bq_count>>$", this_bq_count)
POGGER.debug("stack_bq_count>>$", stack_bq_count)
ContainerBlockProcessor.__process_lazy_lines(
parser_state,
leaf_tokens,
this_bq_count,
stack_bq_count,
line_to_parse,
container_level_tokens,
container_start_bq_count,
)
# POGGER.debug_with_visible_whitespace("text>>$>>", line_to_parse)
# POGGER.debug("container_level_tokens>>$>>", container_level_tokens)
POGGER.debug_with_visible_whitespace("text>>$>>", line_to_parse)
POGGER.debug("container_level_tokens>>$>>", container_level_tokens)

# TODO refactor to make indent unnecessary?
calculated_indent = len(parser_state.original_line_to_parse) - len(
Expand Down Expand Up @@ -352,6 +366,9 @@ def __get_block_start_index(
stack_bq_count,
container_start_bq_count,
)
POGGER.debug("container_start_bq_count>>:$", container_start_bq_count)
POGGER.debug("this_bq_count>>:$", this_bq_count)
POGGER.debug("stack_bq_count>>$", stack_bq_count)
POGGER.debug("text>>:$:>>", line_to_parse)
POGGER.debug(">>container_level_tokens>>$", container_level_tokens)
return (
Expand Down Expand Up @@ -633,6 +650,7 @@ def __handle_nested_container_blocks(
end_container_indices.block_index,
)
delta = 0
already_adjusted = False
if (
end_container_indices.block_index != -1
and not nested_container_starts.ulist_index
Expand Down Expand Up @@ -701,6 +719,7 @@ def __handle_nested_container_blocks(
adjusted_indent_level,
indent_level,
)
indent_was_adjusted = indent_level != adjusted_indent_level
if indent_level > adjusted_indent_level:
delta = indent_level - adjusted_indent_level
indent_level = (
Expand Down Expand Up @@ -730,13 +749,36 @@ def __handle_nested_container_blocks(
POGGER.debug("adj_line_to_parse>>$<<", adj_line_to_parse)
adj_line_to_parse = adj_line_to_parse[delta:]
POGGER.debug("adj_line_to_parse>>$<<", adj_line_to_parse)
elif (
not nested_container_starts.block_index
and adj_line_to_parse
and adj_line_to_parse[0] == " "
and indent_was_adjusted
and parser_state.nested_list_start
):

POGGER.debug("adj_line_to_parse>:$:<", adj_line_to_parse)
POGGER.debug(
"parser_state.nested_list_start>:$:<",
parser_state.nested_list_start.matching_markdown_token,
)
POGGER.debug("BOOM")
assert adj_line_to_parse.startswith(
parser_state.nested_list_start.matching_markdown_token.extracted_whitespace
)
adj_line_to_parse = adj_line_to_parse[
len(
parser_state.nested_list_start.matching_markdown_token.extracted_whitespace
) :
]
already_adjusted = True

POGGER.debug(
"check next container_start>mid>>stack_bq_count>>$<<this_bq_count<<$",
stack_bq_count,
this_bq_count,
)
if delta:
if delta or already_adjusted:
POGGER.debug(
"check next container_start>already adjusted<<$<<",
adj_line_to_parse,
Expand Down Expand Up @@ -938,6 +980,7 @@ def __process_lazy_lines(
stack_bq_count,
line_to_parse,
container_level_tokens,
container_start_bq_count,
):

POGGER.debug("LINE-lazy>$", line_to_parse)
Expand All @@ -949,6 +992,9 @@ def __process_lazy_lines(
line_to_parse, 0
)
remaining_line = line_to_parse[after_ws_index:]
POGGER.debug("container_start_bq_count>>:$", container_start_bq_count)
POGGER.debug("__process_lazy_lines>>this_bq_count>$<", this_bq_count)
POGGER.debug("__process_lazy_lines>>stack_bq_count>$<", stack_bq_count)
POGGER.debug("__process_lazy_lines>>mod->ltp>$<", remaining_line)
POGGER.debug("__process_lazy_lines>>mod->ews>$<", ex_whitespace)

Expand Down
8 changes: 6 additions & 2 deletions test/test_markdown_block_quotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ def test_block_quotes_213d():
</blockquote>"""

# Act & Assert
act_and_assert(source_markdown, expected_gfm, expected_tokens)
act_and_assert(source_markdown, expected_gfm, expected_tokens, show_debug=True)


@pytest.mark.gfm
Expand Down Expand Up @@ -2445,7 +2445,11 @@ def test_block_quotes_extra_02ae():

# Act & Assert
act_and_assert(
source_markdown, expected_gfm, expected_tokens, disable_consistency_checks=True
source_markdown,
expected_gfm,
expected_tokens,
disable_consistency_checks=True,
show_debug=True,
)


Expand Down
80 changes: 80 additions & 0 deletions test/test_markdown_list_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,44 @@ def test_list_blocks_237d():
act_and_assert(source_markdown, expected_gfm, expected_tokens)


@pytest.mark.gfm
def test_list_blocks_237e():
"""
Test case 237: 237 with not enough on final
"""

# Arrange
source_markdown = """ > > 1. one
>>
>> two"""
expected_tokens = [
"[block-quote(1,4): :]",
"[block-quote(1,6): : > > \n>>\n>> ]",
"[olist(1,8):.:1:11: ]",
"[para(1,12):]",
"[text(1,12):one:]",
"[end-para:::True]",
"[end-olist:::False]",
"[BLANK(2,3):]",
"[para(3,7): ]",
"[text(3,7):two:]",
"[end-para:::True]",
"[end-block-quote:::True]",
"[end-block-quote:::True]",
]
expected_gfm = """<blockquote>
<blockquote>
<ol>
<li>one</li>
</ol>
<p>two</p>
</blockquote>
</blockquote>"""

# Act & Assert
act_and_assert(source_markdown, expected_gfm, expected_tokens)


@pytest.mark.gfm
def test_list_blocks_238():
"""
Expand Down Expand Up @@ -478,6 +516,48 @@ def test_list_blocks_238():
act_and_assert(source_markdown, expected_gfm, expected_tokens)


@pytest.mark.gfm
def test_list_blocks_238a():
"""
Test case 238: variant
"""

# Arrange
source_markdown = """>>- one
>>
> > two"""
expected_tokens = [
"[block-quote(1,1)::]",
"[block-quote(1,2)::>>\n>>\n > > ]",
"[ulist(1,3):-::4: ]",
"[para(1,5):]",
"[text(1,5):one:]",
"[end-para:::True]",
"[BLANK(2,3):]",
"[para(3,10):]",
"[text(3,10):two:]",
"[end-para:::True]",
"[end-ulist:::True]",
"[end-block-quote:::True]",
"[end-block-quote:::True]",
]
expected_gfm = """<blockquote>
<blockquote>
<ul>
<li>
<p>one</p>
<p>two</p>
</li>
</ul>
</blockquote>
</blockquote>"""

# Act & Assert
act_and_assert(
source_markdown, expected_gfm, expected_tokens, disable_consistency_checks=True
)


@pytest.mark.gfm
def test_list_blocks_239():
"""
Expand Down

0 comments on commit 9d3f1bb

Please sign in to comment.