mabuseif commited on
Commit
b09c9f7
·
verified ·
1 Parent(s): 5f14b38

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -109,11 +109,13 @@ def check_for_fragment(url):
109
  return '#:~:text=' in url
110
 
111
  def parse_citation_text(citation_text):
112
- # Match "Author (Year)" or "(Author, Year)"
113
- match = re.match(r'(\(?.*?\)?)\s*\((\d{4})\)', citation_text.strip())
114
  if match:
115
- author, year = match.groups()
116
- author = author.strip('()').strip()
 
 
117
  return author, year
118
  return None, None
119
 
@@ -173,7 +175,7 @@ def live_clock():
173
  const date = `${parts[4].value}-${parts[2].value}-${parts[0].value}`;
174
  const time = `${parts[6].value}:${parts[8].value}:${parts[10].value}`;
175
  const datetimeElement = document.getElementById('live_datetime');
176
- if datetimeElement) {
177
  datetimeElement.innerText = `${date} ${time}`;
178
  }
179
  }
 
109
  return '#:~:text=' in url
110
 
111
  def parse_citation_text(citation_text):
112
+ # Match both "Author (Year)" and "(Author, Year)"
113
+ match = re.match(r'^(?:(\w[\w\s.,&et al]+)\s*\((\d{4})\)|\((\w[\w\s.,&et al]+),\s*(\d{4})\))$', citation_text.strip())
114
  if match:
115
+ # If "Author (Year)" matches, take groups 1 and 2; if "(Author, Year)" matches, take groups 3 and 4
116
+ author = match.group(1) or match.group(3)
117
+ year = match.group(2) or match.group(4)
118
+ author = author.strip()
119
  return author, year
120
  return None, None
121
 
 
175
  const date = `${parts[4].value}-${parts[2].value}-${parts[0].value}`;
176
  const time = `${parts[6].value}:${parts[8].value}:${parts[10].value}`;
177
  const datetimeElement = document.getElementById('live_datetime');
178
+ if (datetimeElement) {
179
  datetimeElement.innerText = `${date} ${time}`;
180
  }
181
  }