Skip to content

Commit

Permalink
https://github.com/jackdewinter/pymarkdown/issues/835
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdewinter committed Nov 19, 2023
1 parent 9ba2a2a commit 9cecfb8
Show file tree
Hide file tree
Showing 12 changed files with 658 additions and 272 deletions.
12 changes: 12 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,25 @@

### Fixed

- [Issue 835](https://github.com/jackdewinter/pymarkdown/issues/835)
- a double block quote follwed by a fenced block in a single block quote
was not properly closing
- [Issue 836](https://github.com/jackdewinter/pymarkdown/issues/836)
- these cases were hitting split tab cases within processing for fenced code
blocks
- [Issue 837](https://github.com/jackdewinter/pymarkdown/issues/836)
- these cases were split tab cases where the text to compare to its detabified
forms was incorrect, resulting in a failed match
- [Issue 841](https://github.com/jackdewinter/pymarkdown/issues/841)
- fixed issue with assert
- had commented out branch because no cases were found, finally found one
- spawned other issues to fix less serious issues
- [Issue 842](https://github.com/jackdewinter/pymarkdown/issues/842)
- fixed problem with HTML and lists and split tabs causing assertions
- spawned other issues to fix less serious issues
- [Issue 843](https://github.com/jackdewinter/pymarkdown/issues/843)
- whitespace check not being suspended for one check caused the html block
not to be closed
- [Issue 852](https://github.com/jackdewinter/pymarkdown/issues/852)
- fixed bad tokenization. previous fix was improper, causing strings to
be improperly indexed into to fix spacing issue
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": 4169,
"totalCovered": 4169
"totalMeasured": 4193,
"totalCovered": 4193
},
"lineLevel": {
"totalMeasured": 17555,
"totalCovered": 17555
"totalMeasured": 17626,
"totalCovered": 17626
}
}

10 changes: 5 additions & 5 deletions publish/pylint_suppression.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@
"too-many-arguments": 4
},
"pymarkdown/leaf_blocks/fenced_leaf_block_processor.py": {
"too-many-arguments": 9,
"too-many-locals": 1
"too-many-arguments": 11,
"too-many-locals": 6
},
"pymarkdown/leaf_blocks/indented_leaf_block_processor.py": {
"too-few-public-methods": 1,
Expand Down Expand Up @@ -455,7 +455,7 @@
"pymarkdown/transform_markdown/transform_block_quote.py": {},
"pymarkdown/transform_markdown/transform_containers.py": {
"too-few-public-methods": 1,
"too-many-arguments": 4,
"too-many-arguments": 5,
"too-many-locals": 1,
"too-many-boolean-expressions": 1
},
Expand All @@ -476,8 +476,8 @@
"too-many-instance-attributes": 23,
"too-many-public-methods": 4,
"too-few-public-methods": 40,
"too-many-arguments": 199,
"too-many-locals": 20,
"too-many-arguments": 202,
"too-many-locals": 25,
"chained-comparison": 1,
"too-many-boolean-expressions": 2,
"protected-access": 23,
Expand Down
4 changes: 2 additions & 2 deletions publish/test-results.json
Original file line number Diff line number Diff line change
Expand Up @@ -692,10 +692,10 @@
},
{
"name": "test.gfm.test_markdown_whitespace_fenced",
"totalTests": 99,
"totalTests": 103,
"failedTests": 0,
"errorTests": 0,
"skippedTests": 16,
"skippedTests": 0,
"elapsedTimeInMilliseconds": 0
},
{
Expand Down
207 changes: 116 additions & 91 deletions pymarkdown/general/tab_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,12 +444,119 @@ def find_tabified_string_split(
LOGGER.debug(">>adj_original_index>:%d:<", adj_original_index)
return adj_original, adj_original_index, adj_traverse_original_index

@staticmethod
def __adjust_block_quote_indent_for_tab_block_quote(
parser_state: ParserState, stack_token_index: int
) -> None:
block_quote_token = cast(
BlockQuoteMarkdownToken,
parser_state.token_stack[stack_token_index].matching_markdown_token,
)
# POGGER.debug(
# "parser_state=:$:",
# block_quote_token,
# )
block_quote_leading_spaces = block_quote_token.bleading_spaces
assert block_quote_leading_spaces is not None
# POGGER.debug("block_quote_leading_spaces=:$:", block_quote_leading_spaces)
block_quote_leading_spaces_index = block_quote_leading_spaces.rfind("\n")
last_block_quote_leading_space = block_quote_leading_spaces[
block_quote_leading_spaces_index + 1 :
]
# POGGER.debug(
# "last_block_quote_leading_space=:$:", last_block_quote_leading_space
# )
assert last_block_quote_leading_space.endswith(" ")
last_block_quote_leading_space = last_block_quote_leading_space[:-1]
# POGGER.debug(
# "last_block_quote_leading_space=:$:", last_block_quote_leading_space
# )
# POGGER.debug(
# "parser_state=:$:",
# block_quote_token,
# )
block_quote_token.remove_last_bleading_space()
# POGGER.debug(
# "parser_state=:$:",
# block_quote_token,
# )
block_quote_token.add_bleading_spaces(last_block_quote_leading_space)
# POGGER.debug(
# "parser_state=:$:",
# block_quote_token,
# )

@staticmethod
def __adjust_block_quote_indent_for_tab_list(
parser_state: ParserState,
stack_token_index: int,
extracted_whitespace: Optional[str],
fenced_switch_enabled: bool,
alternate_list_leading_space: Optional[str],
) -> Optional[str]:
assert extracted_whitespace is not None

list_start_token = cast(
ListStartMarkdownToken,
parser_state.token_stack[stack_token_index].matching_markdown_token,
)
LOGGER.debug(
"list_start_token=:%s:",
ParserHelper.make_value_visible(list_start_token),
)
list_leading_spaces = list_start_token.leading_spaces
assert list_leading_spaces is not None
LOGGER.debug(
"list_leading_spaces=:%s:",
ParserHelper.make_value_visible(list_leading_spaces),
)
list_leading_spaces_index = list_leading_spaces.rfind("\n")
last_list_leading_space = list_leading_spaces[list_leading_spaces_index + 1 :]
LOGGER.debug(
"last_list_leading_space=:%s:",
ParserHelper.make_value_visible(last_list_leading_space),
)
tab_index = extracted_whitespace.find("\t")
LOGGER.debug("extracted_whitespace=:%s:", extracted_whitespace)
LOGGER.debug("tab_index=:%d:", tab_index)
last_list_leading_space_length = len(last_list_leading_space)
if fenced_switch_enabled:
assert tab_index < last_list_leading_space_length or (
last_list_leading_space_length == 0
) # and tab_index == 0)
else:
assert tab_index < last_list_leading_space_length
last_list_leading_space = (
extracted_whitespace[:tab_index]
if alternate_list_leading_space is None
else alternate_list_leading_space
)
extracted_whitespace = extracted_whitespace[tab_index:]
LOGGER.debug("last_list_leading_space=:%s:", last_list_leading_space)
LOGGER.debug("extracted_whitespace=:%s:", extracted_whitespace)

LOGGER.debug(
"list_start_token=:%s:",
ParserHelper.make_value_visible(list_start_token),
)
list_start_token.remove_last_leading_space()
LOGGER.debug(
"list_start_token=:%s:",
ParserHelper.make_value_visible(list_start_token),
)
list_start_token.add_leading_spaces(last_list_leading_space)
LOGGER.debug(
"list_start_token=:%s:",
ParserHelper.make_value_visible(list_start_token),
)
return extracted_whitespace

@staticmethod
def adjust_block_quote_indent_for_tab(
parser_state: ParserState,
extracted_whitespace: Optional[str] = None,
alternate_list_leading_space: Optional[str] = None,
xyz:bool = False
fenced_switch_enabled: bool = False,
) -> Optional[str]:
"""
Adjust the last block quote for a tab.
Expand Down Expand Up @@ -479,98 +586,16 @@ def adjust_block_quote_indent_for_tab(
),
)
if parser_state.token_stack[stack_token_index].is_block_quote:
block_quote_token = cast(
BlockQuoteMarkdownToken,
parser_state.token_stack[stack_token_index].matching_markdown_token,
TabHelper.__adjust_block_quote_indent_for_tab_block_quote(
parser_state, stack_token_index
)
# POGGER.debug(
# "parser_state=:$:",
# block_quote_token,
# )
block_quote_leading_spaces = block_quote_token.bleading_spaces
assert block_quote_leading_spaces is not None
# POGGER.debug("block_quote_leading_spaces=:$:", block_quote_leading_spaces)
block_quote_leading_spaces_index = block_quote_leading_spaces.rfind("\n")
last_block_quote_leading_space = block_quote_leading_spaces[
block_quote_leading_spaces_index + 1 :
]
# POGGER.debug(
# "last_block_quote_leading_space=:$:", last_block_quote_leading_space
# )
assert last_block_quote_leading_space.endswith(" ")
last_block_quote_leading_space = last_block_quote_leading_space[:-1]
# POGGER.debug(
# "last_block_quote_leading_space=:$:", last_block_quote_leading_space
# )
# POGGER.debug(
# "parser_state=:$:",
# block_quote_token,
# )
block_quote_token.remove_last_bleading_space()
# POGGER.debug(
# "parser_state=:$:",
# block_quote_token,
# )
block_quote_token.add_bleading_spaces(last_block_quote_leading_space)
# POGGER.debug(
# "parser_state=:$:",
# block_quote_token,
# )
else:
assert extracted_whitespace is not None

list_start_token = cast(
ListStartMarkdownToken,
parser_state.token_stack[stack_token_index].matching_markdown_token,
)
LOGGER.debug(
"list_start_token=:%s:",
ParserHelper.make_value_visible(list_start_token),
)
list_leading_spaces = list_start_token.leading_spaces
assert list_leading_spaces is not None
LOGGER.debug(
"list_leading_spaces=:%s:",
ParserHelper.make_value_visible(list_leading_spaces),
)
list_leading_spaces_index = list_leading_spaces.rfind("\n")
last_list_leading_space = list_leading_spaces[
list_leading_spaces_index + 1 :
]
LOGGER.debug(
"last_list_leading_space=:%s:",
ParserHelper.make_value_visible(last_list_leading_space),
)
tab_index = extracted_whitespace.find("\t")
LOGGER.debug("extracted_whitespace=:%s:", extracted_whitespace)
LOGGER.debug("tab_index=:%d:", tab_index)
abc = len(last_list_leading_space)
if xyz:
assert tab_index < abc or (abc == 0) # and tab_index == 0)
else:
assert tab_index < abc
last_list_leading_space = (
extracted_whitespace[:tab_index]
if alternate_list_leading_space is None
else alternate_list_leading_space
)
extracted_whitespace = extracted_whitespace[tab_index:]
LOGGER.debug("last_list_leading_space=:%s:", last_list_leading_space)
LOGGER.debug("extracted_whitespace=:%s:", extracted_whitespace)

LOGGER.debug(
"list_start_token=:%s:",
ParserHelper.make_value_visible(list_start_token),
)
list_start_token.remove_last_leading_space()
LOGGER.debug(
"list_start_token=:%s:",
ParserHelper.make_value_visible(list_start_token),
)
list_start_token.add_leading_spaces(last_list_leading_space)
LOGGER.debug(
"list_start_token=:%s:",
ParserHelper.make_value_visible(list_start_token),
extracted_whitespace = TabHelper.__adjust_block_quote_indent_for_tab_list(
parser_state,
stack_token_index,
extracted_whitespace,
fenced_switch_enabled,
alternate_list_leading_space,
)
return extracted_whitespace

Expand Down
Loading

0 comments on commit 9cecfb8

Please sign in to comment.