Skip to content

Commit

Permalink
Merge pull request #4932 from freelawproject/1178-aria-attributes-for…
Browse files Browse the repository at this point in the history
…-citations

feat(annotate_citations): use aria-attributes
  • Loading branch information
flooie authored Jan 22, 2025
2 parents 4e18f5a + 0140cca commit a2ce5ea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
8 changes: 7 additions & 1 deletion cl/citations/annotate_citations.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from cl.citations.match_citations import NO_MATCH_RESOURCE
from cl.citations.types import MatchedResourceType, SupportedCitationType
from cl.custom_filters.templatetags.text_filters import best_case_name
from cl.lib.string_utils import trunc
from cl.search.models import Opinion, RECAPDocument


Expand Down Expand Up @@ -61,8 +63,12 @@ def generate_annotations(
"</span>",
]
else: # If successfully matched...
case_name = trunc(best_case_name(opinion.cluster), 60, "...")
annotation = [
f'<span class="citation" data-id="{opinion.pk}"><a href="{opinion.cluster.get_absolute_url()}">',
f'<span class="citation" data-id="{opinion.pk}">'
f'<a href="{opinion.cluster.get_absolute_url()}"'
f' aria-description="Citation for case: {case_name}"'
">",
"</a></span>",
]
for c in citations:
Expand Down
17 changes: 10 additions & 7 deletions cl/citations/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ def test_make_html_from_plain_text(self) -> None:
('<script async src="//www.instagram.com/embed.js"></script>',
'<pre class="inline">&lt;script async src=&quot;//www.instagram.com/embed.js&quot;&gt;&lt;/script&gt;</pre>'),
]

# fmt: on
for s, expected_html in test_pairs:
with self.subTest(
Expand Down Expand Up @@ -315,24 +314,26 @@ def test_make_html_from_matched_citation_objects(self) -> None:
# test the rendering of citation objects that we assert are correctly
# matched. (No matching is performed in the previous cases.)
# fmt: off

case_name = "Example vs. Example"
aria_description = f'aria-description="Citation for case: {case_name}"'
test_pairs = [
# Id. citation with page number ("Id., at 123, 124")
('asdf, Id., at 123, 124. Lorem ipsum dolor sit amet',
'<pre class="inline">asdf, </pre><span class="citation" data-id="'
'MATCH_ID"><a href="MATCH_URL">Id., at 123, 124</a></span><pre '
'class="inline">. Lorem ipsum dolor sit amet</pre>'),
f'MATCH_ID"><a href="MATCH_URL" {aria_description}>'
'Id., at 123, 124</a></span><pre class="inline">. '
'Lorem ipsum dolor sit amet</pre>'),

# Id. citation with complex page number ("Id. @ 123:1, ¶¶ 124")
('asdf, Id. @ 123:1, ¶¶ 124. Lorem ipsum dolor sit amet',
'<pre class="inline">asdf, </pre><span class="citation" data-id='
'"MATCH_ID"><a href="MATCH_URL">Id.</a></span><pre class='
f'"MATCH_ID"><a href="MATCH_URL" {aria_description}>Id.</a></span><pre class='
'"inline"> @ 123:1, ¶¶ 124. Lorem ipsum dolor sit amet</pre>'),

# Id. citation without page number ("Id. Something else")
('asdf, Id. Lorem ipsum dolor sit amet',
'<pre class="inline">asdf, </pre><span class="citation" data-id="'
'MATCH_ID"><a href="MATCH_URL">Id.</a></span><pre class="inline">'
f'MATCH_ID"><a href="MATCH_URL" {aria_description}>Id.</a></span><pre class="inline">'
' Lorem ipsum dolor sit amet</pre>'),
]

Expand All @@ -355,7 +356,9 @@ def test_make_html_from_matched_citation_objects(self) -> None:
# to receive. Also make sure that the "matched" opinion is
# mocked appropriately.
opinion.pk = "MATCH_ID"
opinion.cluster = Mock(OpinionCluster(id=24601))
opinion.cluster = Mock(
OpinionCluster(id=24601), case_name=case_name
)
opinion.cluster.get_absolute_url.return_value = "MATCH_URL"
citation_resolutions = {opinion: citations}

Expand Down

0 comments on commit a2ce5ea

Please sign in to comment.