Skip to content

Commit

Permalink
#138 : Cleaing up functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdewinter committed Nov 18, 2021
1 parent e7839b5 commit ee6cf5c
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 43 deletions.
2 changes: 1 addition & 1 deletion publish/coverage.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"projectName": "pymarkdown", "reportSource": "pytest", "branchLevel": {"totalMeasured": 2956, "totalCovered": 2956}, "lineLevel": {"totalMeasured": 9900, "totalCovered": 9900}}
{"projectName": "pymarkdown", "reportSource": "pytest", "branchLevel": {"totalMeasured": 2956, "totalCovered": 2956}, "lineLevel": {"totalMeasured": 9908, "totalCovered": 9908}}
4 changes: 2 additions & 2 deletions publish/pylint_suppression.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"pymarkdown/inline_helper.py": {
"too-few-public-methods": 2,
"too-many-instance-attributes": 2,
"too-many-arguments": 3,
"too-many-arguments": 4,
"too-many-locals": 1
},
"pymarkdown/inline_markdown_token.py": {
Expand Down Expand Up @@ -214,7 +214,7 @@
"pymarkdown/version.py": {}
},
"disables-by-name": {
"too-many-arguments": 126,
"too-many-arguments": 127,
"too-many-locals": 38,
"too-few-public-methods": 17,
"broad-except": 6,
Expand Down
116 changes: 76 additions & 40 deletions pymarkdown/inline_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,19 +612,10 @@ def handle_line_end(
removed_end_whitespace_size,
remaining_line,
)
POGGER.debug(">>current_string>>$>>", current_string)

is_proper_hard_break, current_string_size = False, len(current_string)
if (
removed_end_whitespace_size == 0
and current_string_size
and current_string[current_string_size - 1]
== InlineHelper.backslash_character
):
POGGER.debug(">>$<<", current_string)
modified_current_string = current_string[0:-1]
is_proper_hard_break = modified_current_string[-2:] != "\\\b"
POGGER.debug(">>$<<", is_proper_hard_break)
is_proper_hard_break = InlineHelper.__is_proper_hard_break(
current_string, removed_end_whitespace_size
)

(
current_string,
Expand Down Expand Up @@ -663,6 +654,23 @@ def handle_line_end(

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

@staticmethod
def __is_proper_hard_break(current_string, removed_end_whitespace_size):
POGGER.debug(">>current_string>>$>>", current_string)

is_proper_hard_break, current_string_size = False, len(current_string)
if (
removed_end_whitespace_size == 0
and current_string_size
and current_string[current_string_size - 1]
== InlineHelper.backslash_character
):
POGGER.debug(">>$<<", current_string)
modified_current_string = current_string[0:-1]
is_proper_hard_break = modified_current_string[-2:] != "\\\b"
POGGER.debug(">>$<<", is_proper_hard_break)
return is_proper_hard_break

# pylint: disable=too-many-arguments
@staticmethod
def __select_line_ending(
Expand Down Expand Up @@ -776,40 +784,23 @@ def extract_bounded_string(
while next_index < source_text_size and not (
source_text[next_index] == close_character and nesting_level == 0
):
if ParserHelper.is_character_at_index(
source_text, next_index, InlineHelper.backslash_character
):
POGGER.debug("pre-back>>next_index>>$>>", next_index)
old_index = next_index

inline_request = InlineRequest(source_text, next_index)
inline_response = InlineHelper.handle_inline_backslash(inline_request)
next_index = inline_response.new_index
extracted_parts.append(source_text[old_index:next_index])
elif start_character is not None and ParserHelper.is_character_at_index(
source_text, next_index, start_character
):
POGGER.debug("pre-start>>next_index>>$>>", next_index)
extracted_parts.append(start_character)
next_index += 1
nesting_level += 1
else:
assert ParserHelper.is_character_at_index(
source_text, next_index, close_character
)
POGGER.debug("pre-close>>next_index>>$>>", next_index)
extracted_parts.append(close_character)
next_index += 1
nesting_level -= 1
next_index, new_data = ParserHelper.collect_until_one_of_characters(
source_text, next_index, break_characters
(
next_index,
nesting_level,
) = InlineHelper.__handle_next_extract_bounded_string_item(
source_text,
next_index,
extracted_parts,
start_character,
nesting_level,
close_character,
break_characters,
)
POGGER.debug(
"back>>next_index>>$>>data>>$>>",
next_index,
data,
)
extracted_parts.append(new_data)
POGGER.debug(
">>next_index2>>$>>data>>$>>",
next_index,
Expand All @@ -826,6 +817,51 @@ def extract_bounded_string(
)
return next_index, None

# pylint: disable=too-many-arguments
@staticmethod
def __handle_next_extract_bounded_string_item(
source_text,
next_index,
extracted_parts,
start_character,
nesting_level,
close_character,
break_characters,
):

if ParserHelper.is_character_at_index(
source_text, next_index, InlineHelper.backslash_character
):
POGGER.debug("pre-back>>next_index>>$>>", next_index)
old_index = next_index

inline_request = InlineRequest(source_text, next_index)
inline_response = InlineHelper.handle_inline_backslash(inline_request)
next_index = inline_response.new_index
extracted_parts.append(source_text[old_index:next_index])
elif start_character is not None and ParserHelper.is_character_at_index(
source_text, next_index, start_character
):
POGGER.debug("pre-start>>next_index>>$>>", next_index)
extracted_parts.append(start_character)
next_index += 1
nesting_level += 1
else:
assert ParserHelper.is_character_at_index(
source_text, next_index, close_character
)
POGGER.debug("pre-close>>next_index>>$>>", next_index)
extracted_parts.append(close_character)
next_index += 1
nesting_level -= 1
next_index, new_data = ParserHelper.collect_until_one_of_characters(
source_text, next_index, break_characters
)
extracted_parts.append(new_data)
return next_index, nesting_level

# pylint: enable=too-many-arguments

@staticmethod
def __handle_numeric_character_reference_inner(source_text, new_index):
"""
Expand Down

0 comments on commit ee6cf5c

Please sign in to comment.