Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -92,18 +92,23 @@ def load_css():
|
|
| 92 |
""", unsafe_allow_html=True)
|
| 93 |
|
| 94 |
# --- Helper Functions ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
def generate_citation_hash(author, year, url, fragment_text, cited_text, username, task_name, current_date, current_time):
|
| 96 |
data = f"{author}, {year} | {url} | {fragment_text} | {cited_text} | {username} | {task_name} | {current_date} | {current_time}"
|
| 97 |
return hashlib.sha256(data.encode('utf-8')).hexdigest()
|
| 98 |
|
| 99 |
def format_citation_html(url, fragment_text, author, year, scc_hash):
|
| 100 |
-
encoded_fragment =
|
| 101 |
full_url = f"{url}#:~:text={encoded_fragment}"
|
| 102 |
return f'<a href="{full_url}" data-hash="{scc_hash}">{author} ({year})</a>'
|
| 103 |
|
| 104 |
def format_metadata_html(url, author, year, scc_hash, username, task_name, current_date, current_time):
|
| 105 |
metadata = f"{username}β{task_name}β{current_date}β{current_time}"
|
| 106 |
-
encoded_metadata =
|
| 107 |
full_url = f"{url}#:~:text={encoded_metadata}"
|
| 108 |
return f'<a href="{full_url}" data-hash="{scc_hash}">{author} ({year}). {scc_hash}</a>'
|
| 109 |
|
|
@@ -167,12 +172,12 @@ def live_clock():
|
|
| 167 |
hour12: false
|
| 168 |
};
|
| 169 |
const formatter = new Intl.DateTimeFormat('en-AU', options);
|
| 170 |
-
const now =
|
| 171 |
const parts = formatter.formatToParts(now);
|
| 172 |
const date = `${parts[4].value}-${parts[2].value}-${parts[0].value}`;
|
| 173 |
const time = `${parts[6].value}:${parts[8].value}:${parts[10].value}`;
|
| 174 |
const datetimeElement = document.getElementById('live_datetime');
|
| 175 |
-
if datetimeElement) {
|
| 176 |
datetimeElement.innerText = `${date} ${time}`;
|
| 177 |
}
|
| 178 |
}
|
|
@@ -206,7 +211,7 @@ with st.expander("About SCC and Example Citation"):
|
|
| 206 |
<li><strong>Benefits:</strong> Promotes digital fluency, ensures source traceability, prevents fabrication, and simplifies referencing.</li>
|
| 207 |
</ul>
|
| 208 |
<h4>Technical Legitimacy</h4>
|
| 209 |
-
The SCC style uses the W3C Text Fragments specification by
|
| 210 |
<h4>Example Citation</h4>
|
| 211 |
<p><strong>Inputs:</strong></p>
|
| 212 |
<ul>
|
|
@@ -342,7 +347,7 @@ with tabs[0]:
|
|
| 342 |
else:
|
| 343 |
scc_hash = generate_citation_hash(author_name, publication_year, source_url, annotated_text, annotated_text, username, task_name, current_date, current_time)
|
| 344 |
citation_link_start = format_citation_html(source_url, annotated_text, author_name, publication_year, scc_hash)
|
| 345 |
-
citation_link_end = f'<a href="{source_url}#:~:text={
|
| 346 |
metadata_link = format_metadata_html(source_url, author_name, publication_year, scc_hash, username, task_name, current_date, current_time)
|
| 347 |
|
| 348 |
col_html1, col_html2 = st.columns(2)
|
|
|
|
| 92 |
""", unsafe_allow_html=True)
|
| 93 |
|
| 94 |
# --- Helper Functions ---
|
| 95 |
+
def encode_text_fragment(text):
|
| 96 |
+
# Encode text for W3C Text Fragments, preserving hyphens and em dashes
|
| 97 |
+
# Use urllib.parse.quote with safe characters to match provided encoding table
|
| 98 |
+
return urllib.parse.quote(text, safe='-β')
|
| 99 |
+
|
| 100 |
def generate_citation_hash(author, year, url, fragment_text, cited_text, username, task_name, current_date, current_time):
|
| 101 |
data = f"{author}, {year} | {url} | {fragment_text} | {cited_text} | {username} | {task_name} | {current_date} | {current_time}"
|
| 102 |
return hashlib.sha256(data.encode('utf-8')).hexdigest()
|
| 103 |
|
| 104 |
def format_citation_html(url, fragment_text, author, year, scc_hash):
|
| 105 |
+
encoded_fragment = encode_text_fragment(fragment_text)
|
| 106 |
full_url = f"{url}#:~:text={encoded_fragment}"
|
| 107 |
return f'<a href="{full_url}" data-hash="{scc_hash}">{author} ({year})</a>'
|
| 108 |
|
| 109 |
def format_metadata_html(url, author, year, scc_hash, username, task_name, current_date, current_time):
|
| 110 |
metadata = f"{username}β{task_name}β{current_date}β{current_time}"
|
| 111 |
+
encoded_metadata = encode_text_fragment(metadata)
|
| 112 |
full_url = f"{url}#:~:text={encoded_metadata}"
|
| 113 |
return f'<a href="{full_url}" data-hash="{scc_hash}">{author} ({year}). {scc_hash}</a>'
|
| 114 |
|
|
|
|
| 172 |
hour12: false
|
| 173 |
};
|
| 174 |
const formatter = new Intl.DateTimeFormat('en-AU', options);
|
| 175 |
+
const now = New Date();
|
| 176 |
const parts = formatter.formatToParts(now);
|
| 177 |
const date = `${parts[4].value}-${parts[2].value}-${parts[0].value}`;
|
| 178 |
const time = `${parts[6].value}:${parts[8].value}:${parts[10].value}`;
|
| 179 |
const datetimeElement = document.getElementById('live_datetime');
|
| 180 |
+
if (datetimeElement) {
|
| 181 |
datetimeElement.innerText = `${date} ${time}`;
|
| 182 |
}
|
| 183 |
}
|
|
|
|
| 211 |
<li><strong>Benefits:</strong> Promotes digital fluency, ensures source traceability, prevents fabrication, and simplifies referencing.</li>
|
| 212 |
</ul>
|
| 213 |
<h4>Technical Legitimacy</h4>
|
| 214 |
+
<p>The SCC style uses the W3C Text Fragments specification by Burris and Bokan (2023) to enable precise linking to specific sections of digital content. This ensures that citations are contextually accurate, verifiable, and aligned with modern digital standards. <a href="https://wicg.github.io/scroll-to-text-fragment/" target="_blank">W3C Text Fragments specification</a></p>
|
| 215 |
<h4>Example Citation</h4>
|
| 216 |
<p><strong>Inputs:</strong></p>
|
| 217 |
<ul>
|
|
|
|
| 347 |
else:
|
| 348 |
scc_hash = generate_citation_hash(author_name, publication_year, source_url, annotated_text, annotated_text, username, task_name, current_date, current_time)
|
| 349 |
citation_link_start = format_citation_html(source_url, annotated_text, author_name, publication_year, scc_hash)
|
| 350 |
+
citation_link_end = f'<a href="{source_url}#:~:text={encode_text_fragment(annotated_text)}" data-hash="{scc_hash}">({author_name}, {publication_year})</a>'
|
| 351 |
metadata_link = format_metadata_html(source_url, author_name, publication_year, scc_hash, username, task_name, current_date, current_time)
|
| 352 |
|
| 353 |
col_html1, col_html2 = st.columns(2)
|