Skip to content

Commit

Permalink
#34 : Multiple line inline elements did not have their positions calc…
Browse files Browse the repository at this point in the history
…ulcated properly within a Block Quote.
  • Loading branch information
jackdewinter committed Sep 27, 2021
1 parent a5669f0 commit 5f14d07
Show file tree
Hide file tree
Showing 15 changed files with 446 additions and 57 deletions.
2 changes: 1 addition & 1 deletion clean.json
Expand Up @@ -13,4 +13,4 @@
"enabled": false
}
}
}
}
17 changes: 2 additions & 15 deletions issues.md
Expand Up @@ -103,21 +103,6 @@ This is text and a blank line.
This is a blank line and some text.
```

### xxx

- similar to other bad lrd tests for md027

```markdown
> this is text
> [a not
> so
> simple](/link
> "a
> title"
> )
> a real test
```

### Inconsistent end for bq

- different ending to block quote if ends with newline or not
Expand Down Expand Up @@ -155,6 +140,8 @@ This is a test

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

- in inline, does `if coalesced_stack and coalesced_stack[-1].is_block_quote_start:` really need
to look for any bq on the stack?
- show url for failed rules as option
- combine traversal for 027 and 007?

Expand Down
2 changes: 1 addition & 1 deletion publish/coverage.json
@@ -1 +1 @@
{"projectName": "pymarkdown", "reportSource": "pytest", "branchLevel": {"totalMeasured": 2808, "totalCovered": 2800}, "lineLevel": {"totalMeasured": 8895, "totalCovered": 8883}}
{"projectName": "pymarkdown", "reportSource": "pytest", "branchLevel": {"totalMeasured": 2824, "totalCovered": 2816}, "lineLevel": {"totalMeasured": 8929, "totalCovered": 8917}}
2 changes: 1 addition & 1 deletion publish/test-results.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions pymarkdown/inline_helper.py
Expand Up @@ -539,6 +539,7 @@ def handle_line_end(
is_setext,
line_number,
column_number,
coalesced_stack,
):
"""
Handle the inline case of having the end of line character encountered.
Expand Down Expand Up @@ -632,6 +633,9 @@ def handle_line_end(
)
POGGER.debug("<<end_string<<$<<", end_string)

if coalesced_stack and coalesced_stack[-1].is_block_quote_start:
coalesced_stack[-1].leading_text_index += 1

POGGER.debug(
"<<append_to_current_string<<$<<",
append_to_current_string,
Expand Down
96 changes: 92 additions & 4 deletions pymarkdown/inline_processor.py
Expand Up @@ -128,6 +128,8 @@ def parse_inline(coalesced_results):
coalesced_stack.append(current_token)
POGGER.debug("STACK-ADD:$", current_token)
POGGER.debug("STACK:$", coalesced_stack)
if current_token.is_block_quote_start:
current_token.leading_text_index = 0

for coalesce_index in range(1, len(coalesced_results)):
if coalesced_results[coalesce_index].is_text and (
Expand Down Expand Up @@ -208,6 +210,7 @@ def parse_inline(coalesced_results):
coalesced_results[coalesce_index].token_text.replace(
ParserHelper.tab_character, " "
),
coalesced_stack,
whitespace_to_recombine=combined_whitespace_text,
is_setext=True,
para_space=coalesced_results[
Expand All @@ -232,6 +235,7 @@ def parse_inline(coalesced_results):
)
processed_tokens = InlineProcessor.__process_inline_text_block(
coalesced_results[coalesce_index].token_text,
coalesced_stack,
coalesced_results[coalesce_index].extracted_whitespace,
line_number=coalesced_results[coalesce_index].line_number,
column_number=coalesced_results[coalesce_index].column_number
Expand All @@ -255,6 +259,7 @@ def parse_inline(coalesced_results):
coalesced_results[coalesce_index].token_text.replace(
ParserHelper.tab_character, " "
),
coalesced_stack,
is_para=True,
para_space=coalesced_results[
coalesce_index
Expand Down Expand Up @@ -412,6 +417,10 @@ def __handle_inline_special(
)
POGGER.debug(">>next_index>>$<<", next_index)
POGGER.debug(">>new_index>>$<<", new_index)
POGGER.debug(
">>source_text:new_index>>$<<",
source_text[new_index:],
)
POGGER.debug(">>inline_blocks>>$<<", inline_blocks)
POGGER.debug(">>new_token>>$<<", new_token)
POGGER.debug(">>source_text>>$<<", source_text[new_index:])
Expand Down Expand Up @@ -448,6 +457,11 @@ def __handle_inline_special(
repeat_count = new_index - next_index
POGGER.debug(">>delta_line>>$<<", delta_line)
POGGER.debug(">>repeat_count>>$<<", repeat_count)
if para_owner:
POGGER.debug(
">>para_owner.rehydrate_index>>$<<",
para_owner.rehydrate_index,
)
(
delta_line,
repeat_count,
Expand All @@ -457,6 +471,11 @@ def __handle_inline_special(
delta_line,
repeat_count,
)
if para_owner:
POGGER.debug(
">>para_owner.rehydrate_index>>$<<",
para_owner.rehydrate_index,
)
POGGER.debug(">>delta_line>>$<<", delta_line)
POGGER.debug(">>repeat_count>>$<<", repeat_count)
else:
Expand Down Expand Up @@ -550,7 +569,13 @@ def __calculate_full_deltas(current_token, para_owner, delta_line, repeat_count)
POGGER.debug(">>ex_label")
delta_line += newline_count
if para_owner:
POGGER.debug(
">>para_owner.rehydrate_index>>$<<", para_owner.rehydrate_index
)
para_owner.rehydrate_index += newline_count
POGGER.debug(
">>para_owner.rehydrate_index>>$<<", para_owner.rehydrate_index
)
POGGER.debug("full>>ex_label>>newline_count>>$", newline_count)

last_line_of_label = ParserHelper.calculate_last_line(
Expand Down Expand Up @@ -589,6 +614,11 @@ def __calculate_inline_deltas(
newline_count = ParserHelper.count_newlines_in_text(
current_token.text_from_blocks
)
oooooo = newline_count
POGGER.debug(
">>current_token.text_from_blocks>>$<<", current_token.text_from_blocks
)
POGGER.debug(">>newline_count>>$<<", newline_count)
if newline_count:
link_part_index, total_newlines = -1, total_newlines + newline_count

Expand Down Expand Up @@ -637,10 +667,17 @@ def __calculate_inline_deltas(
)

POGGER.debug(">>link_part_index>>$<<", link_part_index)
POGGER.debug(">>total_newlines>>$<<", total_newlines)
POGGER.debug(">>delta_line>>$<<", delta_line)

if para_owner:
para_owner.rehydrate_index += total_newlines + delta_line
POGGER.debug(
">>para_owner.rehydrate_index>>$<<", para_owner.rehydrate_index
)
para_owner.rehydrate_index += total_newlines + delta_line - oooooo
POGGER.debug(
">>para_owner.rehydrate_index>>$<<", para_owner.rehydrate_index
)
if link_part_index >= 0:
link_part_lengths[4] = (
len(split_paragraph_lines[para_owner.rehydrate_index])
Expand Down Expand Up @@ -715,8 +752,9 @@ def __calculate_link_and_image_deltas(

# pylint: disable=too-many-statements, too-many-locals, too-many-arguments, too-many-branches, invalid-unary-operand-type
@staticmethod # noqa: C901
def __process_inline_text_block(
def __process_inline_text_block( # noqa: C901
source_text,
coalesced_stack,
starting_whitespace="",
whitespace_to_recombine=None,
is_setext=False,
Expand Down Expand Up @@ -800,11 +838,15 @@ def __process_inline_text_block(
# )
while next_index != -1:

did_line_number_change = False

# POGGER.debug(
# "\n\n>>Token_start>>$,$<<",
# last_line_number,
# last_column_number,
# )
# POGGER.debug("line_number>>$>",line_number)
# POGGER.debug("column_number>>$>", column_number)
# POGGER.debug(">>inline_blocks>>$<<", inline_blocks)
# POGGER.debug(">>current_string>>$<<", current_string)
# POGGER.debug(">>current_string_unresolved>>$<<", current_string_unresolved)
Expand Down Expand Up @@ -882,6 +924,22 @@ def __process_inline_text_block(
)
else:
column_number += inline_response.delta_column_number

did_line_number_change = bool(inline_response.delta_line_number)

if coalesced_stack and coalesced_stack[-1].is_block_quote_start:
if (
inline_response.new_tokens
and inline_response.new_tokens[-1].is_inline_raw_html
):
newline_count = ParserHelper.count_newlines_in_text(
inline_response.new_tokens[-1].raw_tag
)
POGGER.debug("newline_count in raw-html>>$>", newline_count)
coalesced_stack[-1].leading_text_index += newline_count

# POGGER.debug("line_number>>$>",line_number)
# POGGER.debug("column_number>>$>", column_number)
# POGGER.debug("handler(after)>>$,$<<", line_number, column_number)
# POGGER.debug(
# "handler(after)>>new_tokens>>$<<",
Expand Down Expand Up @@ -910,12 +968,14 @@ def __process_inline_text_block(
is_setext,
line_number,
column_number,
coalesced_stack,
)
# POGGER.debug("2<<end_string<<$<<", end_string)
# POGGER.debug(
# "handle_line_end>>new_tokens>>$<<",
# inline_response.new_tokens,
# )

if not inline_response.new_tokens:
# POGGER.debug("ws")
end_string = InlineProcessor.__add_recombined_whitespace(
Expand All @@ -938,8 +998,12 @@ def __process_inline_text_block(
# end_string,
# )
was_new_line = True
# POGGER.debug(">>line_number>>$<<", line_number)
# POGGER.debug(">>column_number>>$<<", column_number)
if para_owner:
# POGGER.debug(">>para_owner.rehydrate_index>>$<<", para_owner.rehydrate_index)
para_owner.rehydrate_index += 1
# POGGER.debug(">>para_owner.rehydrate_index>>$<<", para_owner.rehydrate_index)

# POGGER.debug(
# "new_string-->$<--",
Expand Down Expand Up @@ -1054,17 +1118,41 @@ def __process_inline_text_block(
# line_number,
# column_number,
# )
# POGGER.debug("l/c(was_new_line)>>$<<", was_new_line)
if was_new_line:
# POGGER.debug("l/c(before)>>newline")
line_number, column_number = line_number + 1, 1
column_number = 1
if coalesced_stack and coalesced_stack[-1].is_block_quote_start:
# POGGER.debug("coalesced_list[-1]..leading_text_index=$", coalesced_stack[-1].leading_text_index)
split_leading_spaces = coalesced_stack[-1].leading_spaces.split(
"\n"
)
selected_split_length = len(
split_leading_spaces[coalesced_stack[-1].leading_text_index]
)
# POGGER.debug("l/c(before)>>newline-->$", selected_split_length)
column_number += selected_split_length

line_number += 1
assert fold_space
# POGGER.debug("fold_space(before)>>$<<", fold_space)
fold_space = fold_space[1:]
# POGGER.debug("fold_space(after)>>$<<", fold_space)
column_number += len(fold_space[0])

elif not was_column_number_reset:
column_number += len(remaining_line)
else:
assert did_line_number_change
if coalesced_stack and coalesced_stack[-1].is_block_quote_start:
# POGGER.debug("coalesced_list[-1]..leading_text_index=$", coalesced_stack[-1].leading_text_index)
split_leading_spaces = coalesced_stack[-1].leading_spaces.split(
"\n"
)
selected_split_length = len(
split_leading_spaces[coalesced_stack[-1].leading_text_index]
)
# POGGER.debug("l/c(before)>>newline-->$", selected_split_length)
column_number += selected_split_length
# POGGER.debug(
# "l/c(after)>>$,$<<",
# line_number,
Expand Down
8 changes: 4 additions & 4 deletions pymarkdown/leaf_block_processor.py
Expand Up @@ -1090,8 +1090,8 @@ def correct_for_leaf_block_start_in_list(
POGGER.debug(">>__xx>>tokens_to_add>>$>>", html_tokens)

repeat_loop = True
uid = True
while repeat_loop and uid:
is_remaining_list_token = True
while repeat_loop and is_remaining_list_token:
assert parser_state.token_stack[-1].is_list

POGGER.debug(">>removed_chars_at_start>>$>>", removed_chars_at_start)
Expand All @@ -1109,9 +1109,9 @@ def correct_for_leaf_block_start_in_list(
POGGER.debug(">>__xx>>tokens_from_close>>$>>", tokens_from_close)
html_tokens.extend(tokens_from_close)

uid = parser_state.token_stack[-1].is_list
is_remaining_list_token = parser_state.token_stack[-1].is_list

if uid:
if is_remaining_list_token:
assert parser_state.token_stack[-1].is_list
last_indent = parser_state.token_stack[-1].indent_level
delta_indent = removed_chars_at_start - last_indent
Expand Down
@@ -0,0 +1,8 @@
> this is text
> [a not
> so
> simple](/link
> "a
> title"
> )
> a real test
25 changes: 14 additions & 11 deletions test/test_markdown_block_quotes.py
Expand Up @@ -2449,7 +2449,6 @@ def test_block_quotes_extra_02ae():
expected_gfm,
expected_tokens,
disable_consistency_checks=True,
show_debug=True,
)


Expand Down Expand Up @@ -2807,10 +2806,10 @@ def test_block_quotes_extra_04a():
"[block-quote(1,1)::> \n> \n>\n> ]",
"[para(1,3):\n]",
"[text(1,3):start\n::\n]",
"[emphasis(2,1):1:*]",
"[text(2,2):the:]",
"[end-emphasis(2,5)::]",
"[text(2,6): quote:]",
"[emphasis(2,3):1:*]",
"[text(2,4):the:]",
"[end-emphasis(2,7)::]",
"[text(2,8): quote:]",
"[end-para:::True]",
"[BLANK(3,2):]",
"[para(4,3):]",
Expand All @@ -2825,7 +2824,9 @@ def test_block_quotes_extra_04a():
</blockquote>"""

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


@pytest.mark.gfm
Expand All @@ -2844,10 +2845,10 @@ def test_block_quotes_extra_04b():
"[block-quote(1,1)::> \n> \n> \n>\n> ]",
"[setext(3,3):-:3::(1,3)]",
"[text(1,3):start\n::\n]",
"[emphasis(2,1):1:*]",
"[text(2,2):the:]",
"[end-emphasis(2,5)::]",
"[text(2,6): quote:]",
"[emphasis(2,3):1:*]",
"[text(2,4):the:]",
"[end-emphasis(2,7)::]",
"[text(2,8): quote:]",
"[end-setext::]",
"[BLANK(4,2):]",
"[para(5,3):]",
Expand All @@ -2862,7 +2863,9 @@ def test_block_quotes_extra_04b():
</blockquote>"""

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


@pytest.mark.gfm
Expand Down

0 comments on commit 5f14d07

Please sign in to comment.