Spaces:
Sleeping
Sleeping
Ryan commited on
Commit ·
a197ca5
1
Parent(s): 9614b5c
update text highlighter
Browse files- citation_validator.py +13 -2
citation_validator.py
CHANGED
|
@@ -58,8 +58,19 @@ def create_highlighted_url(base_url: str, quote_text: str) -> str:
|
|
| 58 |
Returns:
|
| 59 |
URL with text fragment
|
| 60 |
"""
|
| 61 |
-
# Extract a meaningful snippet (first
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
# Encode everything for maximum compatibility
|
| 65 |
# quote() with safe='' still preserves unreserved chars (- . _ ~)
|
|
|
|
| 58 |
Returns:
|
| 59 |
URL with text fragment
|
| 60 |
"""
|
| 61 |
+
# Extract a meaningful snippet (first ~80 chars work better for text fragments)
|
| 62 |
+
# Cut at word boundaries to avoid breaking words mid-way
|
| 63 |
+
max_length = 80
|
| 64 |
+
if len(quote_text) > max_length:
|
| 65 |
+
# Find the last space before the cutoff
|
| 66 |
+
text_fragment = quote_text[:max_length]
|
| 67 |
+
last_space = text_fragment.rfind(' ')
|
| 68 |
+
if last_space > 0: # If we found a space, cut there
|
| 69 |
+
text_fragment = text_fragment[:last_space]
|
| 70 |
+
else:
|
| 71 |
+
text_fragment = quote_text
|
| 72 |
+
|
| 73 |
+
text_fragment = text_fragment.strip()
|
| 74 |
|
| 75 |
# Encode everything for maximum compatibility
|
| 76 |
# quote() with safe='' still preserves unreserved chars (- . _ ~)
|