Skip to content

Commit

Permalink
Merge pull request #6 from AbhijeetKrishnan/master
Browse files Browse the repository at this point in the history
Fix bugs in link processing and move name handling
  • Loading branch information
TLNBS2405 authored Feb 12, 2024
2 parents 11ec934 + c71b2dc commit c1c85e7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
File renamed without changes.
8 changes: 8 additions & 0 deletions src/wavu/test/test_wavu_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ def test_get_move(self):
move = wavu_reader.get_move("Azucena-df+1,4",character_movelist)
self.assertEqual(move.id,"Azucena-df+1,4")

def test_process_name(self):
character_movelist = wavu_reader.get_wavu_character_movelist("Jin")
move = wavu_reader.get_move("Jin-1,2,3",character_movelist)
self.assertEqual(move.name,"Left Right > Axe Kick")

def test_complete_parent_input(self):
character_movelist = wavu_reader.get_wavu_character_movelist("Azucena")
move7 = wavu_reader.get_move("Azucena-BT.3",character_movelist)
Expand Down Expand Up @@ -56,3 +61,6 @@ def test_first_parent_input(self):
move = wavu_reader.get_move("Azucena-b+4,3,4",character_movelist)
self.assertEqual(move.startup,"i15~16")

def test_process_links(self):
self.assertEqual(wavu_reader._process_links('[[Snake_Edge|Snake Edge]]'), '[Snake Edge](https://wavu.wiki/t/Snake_Edge \'Snake Edge\')')
self.assertEqual(wavu_reader._process_links('[[Azucena combos#Mini-combos|+27a]]'), '[+27a](https://wavu.wiki/t/Azucena_combos#Mini-combos \'Mini-combo\')'),
25 changes: 18 additions & 7 deletions src/wavu/wavu_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def _convert_json_movelist(move_list_json: list) -> List[Move]:
if move["title"]["ns"] == "0":
alias = []
id = _normalize_data(move["title"]["id"])
name = _normalize_data(_process_links(move["title"]["name"]))
name = html.unescape(_normalize_data(_process_links(move["title"]["name"])))
input = _normalize_data(
_get_all_parent_values_of("input", _normalize_data(move["title"]["parent"]), move_list_json)
+ _normalize_data(move["title"]["input"]))
Expand Down Expand Up @@ -159,13 +159,24 @@ def _remove_html_tags(data):
return result


link_replace_pattern = re.compile(r'\[\[(?P<page>[^#]+)#(?P<section>[^|]+)\|(?P<data>[^|]+)\]\]')

link_replace_pattern = re.compile(r'\[\[(?P<page>[^#]+)(#(?P<section>[^|]+))?\|(?P<data>[^|]+)\]\]')
WAVU_PAGE_STEM = 'https://wavu.wiki/t/'

def _process_links(data: str | None) -> str:
def _replace_link(match):
page, section, data = match.group('page'), match.group('section'), match.group('data')
hover_text = 'Combo' if section == 'Staples' else 'Mini-combo'
return f"[{data}](https://wavu.wiki/t/{page.replace(' ', '_')}#{section} \'{hover_text}\')"
def _replace_link(matchobj):
page, section, data = matchobj.group('page'), matchobj.group('section'), matchobj.group('data')
if section:
match section:
case 'Staples':
hover_text = 'Combo'
case 'Mini-combos':
hover_text = 'Mini-combo'
case _:
hover_text = page.replace('_', ' ').title()
replacement = f"[{data}]({WAVU_PAGE_STEM}{page.replace(' ', '_')}#{section} '{hover_text}')"
else:
hover_text = page.replace('_', ' ').title()
replacement = f"[{data}]({WAVU_PAGE_STEM}{page.replace(' ', '_')} '{hover_text}')"
return replacement

return link_replace_pattern.sub(_replace_link, _empty_value_if_none(data))

0 comments on commit c1c85e7

Please sign in to comment.