|
|
@ -12,7 +12,8 @@ def customSequenceMatcher(
|
|
|
|
include_removed: bool = True,
|
|
|
|
include_removed: bool = True,
|
|
|
|
include_added: bool = True,
|
|
|
|
include_added: bool = True,
|
|
|
|
include_replaced: bool = True,
|
|
|
|
include_replaced: bool = True,
|
|
|
|
include_change_type_prefix: bool = True
|
|
|
|
include_change_type_prefix: bool = True,
|
|
|
|
|
|
|
|
html_colour: bool = False
|
|
|
|
) -> Iterator[List[str]]:
|
|
|
|
) -> Iterator[List[str]]:
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Compare two sequences and yield differences based on specified parameters.
|
|
|
|
Compare two sequences and yield differences based on specified parameters.
|
|
|
@ -25,6 +26,7 @@ def customSequenceMatcher(
|
|
|
|
include_added (bool): Include added parts
|
|
|
|
include_added (bool): Include added parts
|
|
|
|
include_replaced (bool): Include replaced parts
|
|
|
|
include_replaced (bool): Include replaced parts
|
|
|
|
include_change_type_prefix (bool): Add prefixes to indicate change types
|
|
|
|
include_change_type_prefix (bool): Add prefixes to indicate change types
|
|
|
|
|
|
|
|
html_colour (bool): Use HTML background colors for differences
|
|
|
|
|
|
|
|
|
|
|
|
Yields:
|
|
|
|
Yields:
|
|
|
|
List[str]: Differences between sequences
|
|
|
|
List[str]: Differences between sequences
|
|
|
@ -35,16 +37,22 @@ def customSequenceMatcher(
|
|
|
|
if include_equal and tag == 'equal':
|
|
|
|
if include_equal and tag == 'equal':
|
|
|
|
yield before[alo:ahi]
|
|
|
|
yield before[alo:ahi]
|
|
|
|
elif include_removed and tag == 'delete':
|
|
|
|
elif include_removed and tag == 'delete':
|
|
|
|
prefix = "(removed) " if include_change_type_prefix else ''
|
|
|
|
if html_colour:
|
|
|
|
yield [f"{prefix}{line}" for line in same_slicer(before, alo, ahi)]
|
|
|
|
yield [f'<span style="background-color: #ffcecb;">{line}</span>' for line in same_slicer(before, alo, ahi)]
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
yield [f"(removed) {line}" for line in same_slicer(before, alo, ahi)] if include_change_type_prefix else same_slicer(before, alo, ahi)
|
|
|
|
elif include_replaced and tag == 'replace':
|
|
|
|
elif include_replaced and tag == 'replace':
|
|
|
|
prefix_changed = "(changed) " if include_change_type_prefix else ''
|
|
|
|
if html_colour:
|
|
|
|
prefix_into = "(into) " if include_change_type_prefix else ''
|
|
|
|
yield [f'<span style="background-color: #ffcecb;">{line}</span>' for line in same_slicer(before, alo, ahi)] + \
|
|
|
|
yield [f"{prefix_changed}{line}" for line in same_slicer(before, alo, ahi)] + \
|
|
|
|
[f'<span style="background-color: #dafbe1;">{line}</span>' for line in same_slicer(after, blo, bhi)]
|
|
|
|
[f"{prefix_into}{line}" for line in same_slicer(after, blo, bhi)]
|
|
|
|
else:
|
|
|
|
|
|
|
|
yield [f"(changed) {line}" for line in same_slicer(before, alo, ahi)] + \
|
|
|
|
|
|
|
|
[f"(into) {line}" for line in same_slicer(after, blo, bhi)] if include_change_type_prefix else same_slicer(before, alo, ahi) + same_slicer(after, blo, bhi)
|
|
|
|
elif include_added and tag == 'insert':
|
|
|
|
elif include_added and tag == 'insert':
|
|
|
|
prefix = "(added) " if include_change_type_prefix else ''
|
|
|
|
if html_colour:
|
|
|
|
yield [f"{prefix}{line}" for line in same_slicer(after, blo, bhi)]
|
|
|
|
yield [f'<span style="background-color: #dafbe1;">{line}</span>' for line in same_slicer(after, blo, bhi)]
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
yield [f"(added) {line}" for line in same_slicer(after, blo, bhi)] if include_change_type_prefix else same_slicer(after, blo, bhi)
|
|
|
|
|
|
|
|
|
|
|
|
def render_diff(
|
|
|
|
def render_diff(
|
|
|
|
previous_version_file_contents: str,
|
|
|
|
previous_version_file_contents: str,
|
|
|
@ -55,7 +63,8 @@ def render_diff(
|
|
|
|
include_replaced: bool = True,
|
|
|
|
include_replaced: bool = True,
|
|
|
|
line_feed_sep: str = "\n",
|
|
|
|
line_feed_sep: str = "\n",
|
|
|
|
include_change_type_prefix: bool = True,
|
|
|
|
include_change_type_prefix: bool = True,
|
|
|
|
patch_format: bool = False
|
|
|
|
patch_format: bool = False,
|
|
|
|
|
|
|
|
html_colour: bool = False
|
|
|
|
) -> str:
|
|
|
|
) -> str:
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Render the difference between two file contents.
|
|
|
|
Render the difference between two file contents.
|
|
|
@ -70,6 +79,7 @@ def render_diff(
|
|
|
|
line_feed_sep (str): Separator for lines in output
|
|
|
|
line_feed_sep (str): Separator for lines in output
|
|
|
|
include_change_type_prefix (bool): Add prefixes to indicate change types
|
|
|
|
include_change_type_prefix (bool): Add prefixes to indicate change types
|
|
|
|
patch_format (bool): Use patch format for output
|
|
|
|
patch_format (bool): Use patch format for output
|
|
|
|
|
|
|
|
html_colour (bool): Use HTML background colors for differences
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Returns:
|
|
|
|
str: Rendered difference
|
|
|
|
str: Rendered difference
|
|
|
@ -88,7 +98,8 @@ def render_diff(
|
|
|
|
include_removed=include_removed,
|
|
|
|
include_removed=include_removed,
|
|
|
|
include_added=include_added,
|
|
|
|
include_added=include_added,
|
|
|
|
include_replaced=include_replaced,
|
|
|
|
include_replaced=include_replaced,
|
|
|
|
include_change_type_prefix=include_change_type_prefix
|
|
|
|
include_change_type_prefix=include_change_type_prefix,
|
|
|
|
|
|
|
|
html_colour=html_colour
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def flatten(lst: List[Union[str, List[str]]]) -> str:
|
|
|
|
def flatten(lst: List[Union[str, List[str]]]) -> str:
|
|
|
|