Skip to content

Commit a686e9d

Browse files
author
Colin Leong
committed
bare-citation-check: Only find line if issue exists
1 parent 3ed73ea commit a686e9d

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/find_bare_citations.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,17 @@ def find_bare_citations(markdown_file_path: Path, citation_keys: list) -> list:
3232
matches = []
3333
for match in key_pattern.finditer(content):
3434
start_index = match.start()
35-
line_start = content.rfind('\n', 0, start_index) + 1
36-
line_end = content.find('\n', start_index)
37-
if line_end == -1:
38-
line_end = len(content)
39-
line = content[line_start:line_end]
40-
41-
# Ensure the citation key is not immediately preceded by an @ symbol
35+
# Check if the citation key is not immediately preceded by an @ symbol
4236
if '@' not in content[start_index-1:start_index]:
37+
# if the @ is missing, pull out the whole line and return it.
38+
line_start = content.rfind('\n', 0, start_index) + 1
39+
line_end = content.find('\n', start_index)
40+
if line_end == -1:
41+
line_end = len(content)
42+
line = content[line_start:line_end]
4343
matches.append(line)
44+
45+
4446

4547
if matches:
4648
yield citation_key, matches

0 commit comments

Comments
 (0)