@@ -33,29 +33,17 @@ def find_bare_citations(markdown_file_path:Path, citation_keys:list)->list:
33
33
34
34
content = markdown_code_block_pattern .sub ('' , content )
35
35
36
-
37
-
38
-
39
- issues = []
40
-
41
-
42
36
for citation_key in citation_keys :
43
37
44
38
# magical regex from ChatGPT: captures the whole line that has a bare citation.
45
39
pattern = re .compile (r'^.*(?<!@)(?:' + re .escape (citation_key ) + r').*$' , re .MULTILINE )
46
40
47
41
# Find all matching lines
48
- matches = pattern .findall (content )
49
-
50
- # Print the matches
51
- # for match in matches:
52
- # print(match)
53
-
54
- if matches :
42
+ if pattern .search (content ) is not None :
43
+ matches = pattern .finditer (content )
55
44
issue_tuple = citation_key , matches
56
- issues .append (issue_tuple )
57
-
58
- return issues
45
+ yield issue_tuple
46
+
59
47
60
48
if __name__ == "__main__" :
61
49
@@ -75,14 +63,13 @@ def find_bare_citations(markdown_file_path:Path, citation_keys:list)->list:
75
63
76
64
citation_keys = extract_citation_keys (args .bib_file_path )
77
65
66
+ # for i in range(50):
67
+ # citation_keys.extend([str(uuid.uuid4) for _ in range(100)])
68
+
78
69
print (f"Bibliography had { len (citation_keys )} citations, checking for bare citations:" )
79
70
80
71
start_time = timeit .default_timer ()
81
72
issues = find_bare_citations (args .markdown_file_path , citation_keys )
82
- elapsed_time = timeit .default_timer () - start_time
83
-
84
- print (f"Bare-citation check complete after ~{ elapsed_time :.2f} seconds" )
85
-
86
73
87
74
if issues :
88
75
print ("Found the following lines with bare citations:" )
@@ -92,8 +79,11 @@ def find_bare_citations(markdown_file_path:Path, citation_keys:list)->list:
92
79
print (f"Citation key: { citation_key } " )
93
80
94
81
for match in matches :
95
- print (f"* { match } " )
82
+ print (f"* { match . group ( 0 ) } " )
96
83
print ()
84
+ elapsed_time = timeit .default_timer () - start_time
85
+ print (f"Bare-citation check complete after ~{ elapsed_time :.2f} seconds" )
86
+ if issues :
97
87
sys .exit (1 ) # exit with an error
98
88
99
89
0 commit comments