From c5c025a805ab5034200e8cf5ade98ba6d6729977 Mon Sep 17 00:00:00 2001 From: Samuel Conjard <samuel.conjard@univ-grenoble-alpes.fr> Date: Thu, 13 Mar 2025 15:46:59 +0100 Subject: [PATCH] Html conversion, recognize two authors edge case --- src/ptf/tests/test_html_conversion.py | 20 ++++++++++++++++++++ src/ptf/utils.py | 5 ++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/ptf/tests/test_html_conversion.py b/src/ptf/tests/test_html_conversion.py index 35c81f1e..25ca490a 100644 --- a/src/ptf/tests/test_html_conversion.py +++ b/src/ptf/tests/test_html_conversion.py @@ -602,3 +602,23 @@ class InterlinkCreationTestCase(TestCase): ) result = create_interlink_for_citation(input_html, input_bibliography_list) self.assertEqual(result, expected) + + def test_12_two_authors_with_no_quote_but_parenthesis_date_should_create_interlink(self): + """Test interlink creation for multiple citations in the same text.""" + input_html = "Mauris lacinia tortor molestie purus luctus, Author & Bauthor (2024); Lorem ipsum." + input_bibliography_list = [ + { + "author": "Author & Bauthor, 2024", + "year": 2024, + "reference": "Author & Bauthor, Study reference.", + "cited_in_article": False, + }, + ] + expected = ( + 'Mauris lacinia tortor molestie purus luctus, <span class="tooltipPCJ">' + '<a id="1" href="#r1" onclick="highlightReference(\'r1\', 3000, 500)" >Author & Bauthor (2024</a>' + '<span style="position: absolute; visibility: hidden" class="tooltip tooltiptexthidden">' + "Author & Bauthor, Study reference.</span></span>); Lorem ipsum." + ) + result = create_interlink_for_citation(input_html, input_bibliography_list) + self.assertEqual(result, expected) diff --git a/src/ptf/utils.py b/src/ptf/utils.py index abdbdf27..a53b41f3 100644 --- a/src/ptf/utils.py +++ b/src/ptf/utils.py @@ -515,10 +515,9 @@ def create_interlink_for_citation(html_text: str, bibliography: list[dict[str, s base_key = author + rank if rank else author # Append the rank letter if it exists return { - base_key, - base_key.replace("&", "&"), # Replace & with & - base_key.replace("&", "and"), # Replace & with "and" base_key.replace(",", ""), # Remove commas + base_key.replace("&", "&").replace(",", ""), # Replace & with & + base_key.replace("&", "and").replace(",", ""), # Replace & with "and" } for i, entry in enumerate(bibliography, start=1): -- GitLab